From 9eadb9f8995215bd0eb4f3349e99a29d2f35061d Mon Sep 17 00:00:00 2001 From: molsonkiko <46202915+molsonkiko@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:13:14 -0700 Subject: [PATCH] Add translation in settings form Also fix translation of sort_keys setting, and add translation of tab_indent_pretty_print setting --- CHANGELOG.md | 1 + .../PluginInfrastructure/SettingsBase.cs | 30 +++++++++++++++---- JsonToolsNppPlugin/Properties/AssemblyInfo.cs | 4 +-- JsonToolsNppPlugin/Utils/Translator.cs | 2 ++ README.md | 4 +-- translation/english.json5 | 5 ++-- translation/italian.json5 | 5 ++-- 7 files changed, 36 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cfb6b0..a208174 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). 1. [Progress reporting](/docs/README.md#reporting-progress-when-parsing-large-amounts-of-json) with the JSON from files and APIs form (henceforth the `grepper form`). 2. In the `grepper form`, pressing `Enter` inside the `Previously viewed directories...` box causes the current text of the box to be searched, assuming that it is a valid directory. +3. [Translation](/README.md#translating-jsontools-to-another-language) of settings in the [Settings form](/docs/README.md#customizing-settings). ### Fixed diff --git a/JsonToolsNppPlugin/PluginInfrastructure/SettingsBase.cs b/JsonToolsNppPlugin/PluginInfrastructure/SettingsBase.cs index 68f8efa..5897751 100644 --- a/JsonToolsNppPlugin/PluginInfrastructure/SettingsBase.cs +++ b/JsonToolsNppPlugin/PluginInfrastructure/SettingsBase.cs @@ -296,12 +296,30 @@ public void ShowDialog(bool debug = false) SaveToIniFile(); dialog.Close(); }; - //var grid = (PropertyGrid)dialog.Controls["Grid"]; - //grid.SelectedGridItemChanged += (object _, SelectedGridItemChangedEventArgs e) => - //{ - // GridItem selectedItem = e.NewSelection; - // selectedItem. - //}; + var grid = dialog.Controls["Grid"]; + if (Translator.HasTranslations + && grid.Controls.Count >= 1 && grid.Controls[0] is Control commentPane + && commentPane.Controls.Count >= 2 && commentPane.Controls[1] is Label descriptionLabel) + { + string translatedDescription = ""; + var propGrid = (PropertyGrid)grid; + propGrid.SelectedGridItemChanged += (object _, SelectedGridItemChangedEventArgs e) => + { + GridItem selectedItem = e.NewSelection; + PropertyDescriptor selectedPropertyDesc = selectedItem?.PropertyDescriptor; + if (selectedPropertyDesc is null) + return; + PropertyInfo selectedProp = GetType().GetProperty(selectedPropertyDesc.Name); + translatedDescription = Translator.TranslateSettingsDescription(selectedProp); + if (translatedDescription.Length > 0) + descriptionLabel.Text = translatedDescription; + }; + commentPane.SizeChanged += (object _, EventArgs e) => + { + if (translatedDescription.Length > 0) + descriptionLabel.Text = translatedDescription; + }; + } dialog.ShowDialog(); } diff --git a/JsonToolsNppPlugin/Properties/AssemblyInfo.cs b/JsonToolsNppPlugin/Properties/AssemblyInfo.cs index c5f7a99..d545210 100644 --- a/JsonToolsNppPlugin/Properties/AssemblyInfo.cs +++ b/JsonToolsNppPlugin/Properties/AssemblyInfo.cs @@ -28,5 +28,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("8.0.0.1")] -[assembly: AssemblyFileVersion("8.0.0.1")] +[assembly: AssemblyVersion("8.0.0.2")] +[assembly: AssemblyFileVersion("8.0.0.2")] diff --git a/JsonToolsNppPlugin/Utils/Translator.cs b/JsonToolsNppPlugin/Utils/Translator.cs index 121a925..059a4bf 100644 --- a/JsonToolsNppPlugin/Utils/Translator.cs +++ b/JsonToolsNppPlugin/Utils/Translator.cs @@ -122,6 +122,8 @@ public static string GetTranslatedMenuItem(string menuItem) /// public static string TranslateSettingsDescription(PropertyInfo propertyInfo) { + if (propertyInfo is null) + return ""; if (translations is JObject jobj && jobj.children is Dictionary dict && dict.TryGetValue("settingsDescriptions", out JNode settingsDescNode) && settingsDescNode is JObject settingsDescObj diff --git a/README.md b/README.md index 091d795..e51720d 100644 --- a/README.md +++ b/README.md @@ -149,9 +149,7 @@ The following aspects of JsonTools __can__ be translated: - Forms (including all controls and items in drop-down menus) - Items in the JsonTools sub-menu of the Notepad++ Plugins menu - The descriptions of settings in the [`JsonTools.ini` config file](/docs/README.md#customizing-settings) - -The following aspect(s) of JsonTools __may eventually__ be translated: -- The descriptions of settings in the [settings form](/docs/README.md#customizing-settings) (this is harder than translating the config file for weird technical reasons). +- The descriptions of settings in the [settings form](/docs/README.md#customizing-settings) (*only for versions since [v8.1](/CHANGELOG.md#810---unreleased-yyyy-mm-dd)*) The following aspects of JsonTools __will not__ be translated: - This documentation diff --git a/translation/english.json5 b/translation/english.json5 index 5b267fe..2400a34 100644 --- a/translation/english.json5 +++ b/translation/english.json5 @@ -206,7 +206,7 @@ }, // The JsonTools.ini config file (in your plugin config folder) // will have these translated descriptions as comments above each setting. - // TODO: When a user opens the settings form and clicks on a setting, the translation should also appear. + // The settings form will also show these translated descriptions when the named setting is selected. "settingsDescriptions": { "logger_level": "Suppress logging of errors at or below this level.\r\nSTRICT: Log all deviations from the original JSON spec.\r\nOK: The original JSON spec plus the following:\r\n * strings can contain characters with ASCII values less than 0x20 (includes '\\t')\r\nNAN_INF: Do not log errors when NaN, Infinity, and -Infinity are parsed.\r\nJSONC: The following errors are not logged:\r\n * JavaScript single-line '//' and multi-line '/*...*/' comments\r\n * NaN and +/-Infinity\r\nJSON5: Everything in the JSONC and NAN_INF levels is not logged, as well as the following:\r\n * singlequoted strings\r\n * commas after the last element of an array or object\r\n * unquoted object keys\r\n * see https://json5.org/ for more.", "offer_to_show_lint": "When the document is parsed, show a prompt to see syntax errors in the document.", @@ -217,9 +217,10 @@ "tree_node_images": "Should each node in the tree have an image associated with its type?", "ask_before_pretty_printing_json_lines": "Ask before pretty-printing JSON Lines documents, ignore requests to pretty-print, or pretty-print without asking?", "indent_pretty_print": "The number of spaces between levels of JSON when pretty-printing", + "tab_indent_pretty_print": "Use one horizontal tab ('\\t') instead of spaces between levels of JSON when pretty-printing", "minimal_whitespace_compression": "If true, using the 'Compress JSON' plugin command will remove ALL unnecessary whitespace from the JSON. Otherwise, it will leave after the colon in objects and after the comma in both objects and arrays", "remember_comments": "When JSON is pretty-printed or compressed, any comments found when it was last parsed are included.\r\nWhen pretty-printing, each comment will have the same relative location to each JSON element as when it was parsed.\r\nWhen compressing, all comments will come at the beginning of the document.", - "sort_keys": "Use one horizontal tab ('\\t') instead of spaces between levels of JSON when pretty-printing", + "sort_keys": "Sort the keys of objects alphabetically when formatting or compressing", "toolbar_icons": "Specify one of these chars for each toolbar icon you want to show, in the order you want:\r\n('t' = tree view, 'c' = compress, 'p' = pretty-print, 'o' = path to current position)\r\nThis setting will take effect the next time you start Notepad++.\r\nIf you want there to be NO toolbar icons, enter a character that does not represent an icon; do NOT leave this field empty.", "auto_try_guess_csv_delim_newline": "If this setting is true,\r\nwhen the regex search form is opened, or when the \"Parse as CSV?\" checkbox in that form is toggled on,\r\nJsonTools will attempt to guess whether the current document is a CSV or TSV file, and how many columns and what newline it has.\r\nThe regex search form will take slightly longer to open if this is true.", "csv_newline": "Which type of newline to use for generated CSV files.", diff --git a/translation/italian.json5 b/translation/italian.json5 index 0c92991..b8b7019 100644 --- a/translation/italian.json5 +++ b/translation/italian.json5 @@ -206,7 +206,7 @@ }, // The JsonTools.ini config file (in your plugin config folder) // will have these translated descriptions as comments above each setting. - // TODO: When a user opens the settings form and clicks on a setting, the translation should also appear. + // The settings form will also show these translated descriptions when the named setting is selected. "settingsDescriptions": { "logger_level": "Disattiva la registrazione degli errori del livello corrente e di quelli inferiori.\r\nSTRICT: registra tutte le deviazioni dalla struttura JSON originale.\r\nOK: la struttura JSON originale e quanto segue::\r\n * le stringhe possono contenere caratteri con valori ASCII inferiori a 0x20 ( compreso '\\t')\r\nNAN_INF: non registrare gli errori quando vengono analizzati NaN, Infinity, e vengono analizzati -Infinity.\r\nJSONC: i seguenti errori non vengono registrati:\r\n * Commenti JavaScript su riga singola '//' e commenti multi-riga '/*...*/' \r\n * NaN e +/-Infinity\r\nJSON5: Tutto nei JSONC e livello NAN_INF non loggato, e quanto segue:\r\n * stringhe tra apici singoli\r\n * virgole dopo l'ultimo elemento di un array od oggetto\r\n * chiavi oggetto senza virgolette\r\n * vedi https://json5.org/ per maggiori informazioni.", "offer_to_show_lint": "Quando il documento viene analizzato, visualizza con un messaggio gli errori di sintassi nel documento.", @@ -217,9 +217,10 @@ "tree_node_images": "Ogni nodo nell'albero dovrebbe avere un'immagine associata al suo tipo?", "ask_before_pretty_printing_json_lines": "Chiedi prima di formattare le righe dei documenti JSON, ignora le richieste di formattazione, o formattare senza chiedere?", "indent_pretty_print": "Il numero di spazi tra i livelli JSON quando formattato", + "tab_indent_pretty_print": "Utilizza il tabulatore ('\\t') invece degli spazi tra i livelli di JSON durante la formattazione", "minimal_whitespace_compression": "Se vero, l'utilizzo del comando del plugin 'Comprimi JSON' rimuoverà TUTTI gli spazi bianchi non necessari dal JSON. Altrimenti, lascerà dopo i due punti negli oggetti e dopo la virgola sia negli oggetti che negli array", "remember_comments": "Quando JSON viene formattato o compresso, vengono inclusi tutti i commenti trovati durante l'ultima analisi.\r\nQuando viene formattato, ogni commento avrà la stessa posizione relativa a ciascun elemento JSON di quando è stato analizzato.\r\nDurante la compressione, tutti i commenti verranno visualizzati all'inizio del documento.", - "sort_keys": "Utilizza il tabulatore ('\\t') invece degli spazi tra i livelli di JSON durante la formattazione", + "sort_keys": "Ordina le chiavi degli oggetti in ordine alfabetico durante la formattazione o la compressione", "toolbar_icons": "Per ogni icona della barra degli strumenti, indica una delle seguenti icone nell'ordine desiderato:\r\n('t' = visualizzazione ad albero, 'c' = compressione, 'p' = formatta, 'o' = Percorso della posizione corrente)\r\n Questa impostazione avrà effetto al riavvio di Notepad++.\r\n Per non visualizzare le icone nella barra degli strumenti, inserisci un carattere diverso dai precedenti; NON lasciare questo campo vuoto.", "auto_try_guess_csv_delim_newline": "Se questa impostazione è abilitata,\r\nquando la finestra di ricerca con espressione regolare, o quando \"Analizza come CSV?\" di questa finestra è attivata,\r\nJsonTools tenterà di indovinare se il documento corrente è un file CSV o TSV, e quante colonne e quale nuova riga contiene.\r\nIn questo caso l'apertura della finestra di ricerca espressione regolare richiederà leggermente più tempo.", "csv_newline": "Indicare il fine riga da usare per generare file CSV.",