From a40137ea030138f0d004cf287911282536587ff4 Mon Sep 17 00:00:00 2001 From: molsonkiko <46202915+molsonkiko@users.noreply.github.com> Date: Mon, 4 Nov 2024 21:17:42 -0800 Subject: [PATCH] Translate to other lang iff NPP is in that lang Ignore the Windows culture of the user to address #82. --- CHANGELOG.md | 1 + JsonToolsNppPlugin/Properties/AssemblyInfo.cs | 4 ++-- JsonToolsNppPlugin/Utils/Translator.cs | 7 +++++++ README.md | 14 +++++--------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d56a056..7672a1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). 1. If a number string is too large or small for a 64-bit floating point number (for example, `-2e700`, `3.5e+450`), the JSON parser will now represent them as `-Infinity` (if they have a leading `-` sign) or `Infinity`, rather than representing them as `NaN`. The linter also has a new message for when this happens. 2. If a [JSON lines document](/docs/README.md#json-lines-documents) is not compliant with the strict JSON specification, the [status bar](/docs/README.md#error-form-and-status-bar) will now reflect that it is JSON lines. +3. Stop considering the user's Windows culture when determining the UI language for JsonTools (fix [issue 82](https://github.com/molsonkiko/JsonToolsNppPlugin/issues/82)). Now JsonTools will be translated into language X if and only if Notepad++ is in language X. ### Fixed diff --git a/JsonToolsNppPlugin/Properties/AssemblyInfo.cs b/JsonToolsNppPlugin/Properties/AssemblyInfo.cs index 2aa1148..fff676b 100644 --- a/JsonToolsNppPlugin/Properties/AssemblyInfo.cs +++ b/JsonToolsNppPlugin/Properties/AssemblyInfo.cs @@ -28,5 +28,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("8.1.0.14")] -[assembly: AssemblyFileVersion("8.1.0.14")] +[assembly: AssemblyVersion("8.1.0.15")] +[assembly: AssemblyFileVersion("8.1.0.15")] diff --git a/JsonToolsNppPlugin/Utils/Translator.cs b/JsonToolsNppPlugin/Utils/Translator.cs index 477bbda..9e6c77c 100644 --- a/JsonToolsNppPlugin/Utils/Translator.cs +++ b/JsonToolsNppPlugin/Utils/Translator.cs @@ -23,6 +23,11 @@ public static class Translator public static string languageName { get; private set; } = DEFAULT_LANG; public const string DEFAULT_LANG = "english"; + /// + /// whether to use the Windows culture (see below) to determine translation language in some cases

+ /// This is currently false because of issue 82 (https://github.com/molsonkiko/JsonToolsNppPlugin/issues/82) + ///
+ public const bool CHECK_WINDOWS_CULTURE = false; public static readonly string translationDir = Path.Combine(Npp.pluginDllDirectory, "translation"); public static void LoadTranslations(bool atStartup = true, string preferredLang = null) @@ -52,6 +57,7 @@ public static void LoadTranslations(bool atStartup = true, string preferredLang //MessageBox.Show($"While attempting to determine native language preference from Notepad++ config XML, got an error:\r\n{ex}"); } } +#if CHECK_WINDOWS_CULTURE // as a fallback, try to determine the user's language by asking Windows for their current culture if (languageName == DEFAULT_LANG || !TryGetTranslationFileName(languageName, out _)) { @@ -61,6 +67,7 @@ public static void LoadTranslations(bool atStartup = true, string preferredLang if (languageName == "Unknown") languageName = currentCulture.Parent.EnglishName.Split(' ')[0].ToLower(); } +#endif } else { diff --git a/README.md b/README.md index 02c6910..3e99496 100644 --- a/README.md +++ b/README.md @@ -142,20 +142,16 @@ I expect you could find plenty of other good websites if you did some research. If you are interested in helping users of JsonTools who don't speak English, JsonTools can be translated to other languages beginning in [v8.0](/CHANGELOG.md#800---2024-06-29). JsonTools infers your preferred language and attempts to translate in the following way: -1. JsonTools checks your [Notepad++ `nativeLang.xml` config file](https://npp-user-manual.org/docs/binary-translation/#creating-or-editing-a-translation) (at [XPath path](https://www.w3schools.com/xml/xml_xpath.asp) `/NotepadPlus/Native-Langue/@name`) to determine what language you prefer to use, and sets `lowerEnglishName` to the appropriate value and __skips to step 3__. For example, if this file says `galician`, we will attempt to translate JsonTools to `galician`. __If the Notepad++ native language is `english` *or* if JsonTools does not have a translation file for the Notepad++ native language, JsonTools then does the following:__ - 1. JsonTools looks up your [`current culture`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-culture?view=powershell-7.4) (which can be checked using the `get-culture` command in Powershell). - 2. Next, we find the `EnglishName` property of the `current culture` (which can be found by the `$foo = get-culture; $foo.EnglishName` command in Powershell), take the first word, and convert it to lowercase. Call this `lowerEnglishName`. - - Example: the `EnglishName` of the `en-us` culture is `English (United States)`, so `lowerEnglishName` is `english` - - Example: the `EnglishName` of the `it-it` culture is `Italian (Italy)`, so `lowerEnglishName` is `italian` -3. JsonTools then does one of the following: +1. JsonTools checks your [Notepad++ `nativeLang.xml` config file](https://npp-user-manual.org/docs/binary-translation/#creating-or-editing-a-translation) (at [XPath path](https://www.w3schools.com/xml/xml_xpath.asp) `/NotepadPlus/Native-Langue/@name`) to determine what language you prefer to use, and sets `lowerEnglishName` to the appropriate value. For example, if this file says `galician`, we will attempt to translate JsonTools to `galician`. +2. JsonTools then does one of the following: - If `lowerEnglishName` is `english`, it does nothing (because JsonTools is naturally in English) - Otherwise, it looks in the `translation` subdirectory of the `JsonTools` plugin folder (where `JsonTools.dll` lives) for a file named `{lowerEnglishName}.json5` - __NOTE:__ because the translation files are in a subdirectory of the plugin folder, *translation does not work for versions of Notepad++ older than [version 8](https://notepad-plus-plus.org/downloads/v8/),* since those older versions do not have separate folders for each plugin. -4. If JsonTools found `translation\{lowerEnglishName}.json5`, it attempts to parse the file. If parsing fails, a message box will appear warning the user of this. +3. If JsonTools found `translation\{lowerEnglishName}.json5`, it attempts to parse the file. If parsing fails, a message box will appear warning the user of this. - If no translation file was found, or if parsing failed, the default English will be used. -5. If parsing was successful, JsonTools will use the translation file as described below. +4. If parsing was successful, JsonTools will use the translation file as described below. -JsonTools only attempts to find translation files once, when Notepad++ is starting up. If you change the UI language of Notepad++ or your operating system's UI culture, you will have to close Notepad++ and reopen it before this change will apply to JsonTools. +JsonTools only attempts to find translation files once, when Notepad++ is starting up. If you change the UI language of Notepad++, you will have to close Notepad++ and reopen it before this change will apply to JsonTools. To be clear, *JsonTools may not be in the same language of the Notepad++ UI.* The steps described above represent my best effort to automatically translate JsonTools into a language that the user will find useful, without requiring the user to select their language from a list of available languages in the settings form.