From c818501360ebec32e3a0cadf1e031015ec751867 Mon Sep 17 00:00:00 2001 From: tombogle Date: Thu, 11 Apr 2024 15:01:12 -0400 Subject: [PATCH 1/2] Added IncludeSourceRevisionInInformationalVersion to SampleApp.csproj so that Version doesn't get added garbage Added some test code to the sample app to try to re-create and diagnose problem the Bloom team encountered. --- src/SampleApp/Program.cs | 11 +++++++++-- src/SampleApp/SampleApp.csproj | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/SampleApp/Program.cs b/src/SampleApp/Program.cs index 7255a0a..2928e85 100644 --- a/src/SampleApp/Program.cs +++ b/src/SampleApp/Program.cs @@ -21,6 +21,13 @@ static void Main(string[] args) Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + MessageBox.Show(string.Format(LocalizationManager.GetString("accessed.before.setting.up.lm", + "Localization is not yet set up, so this will always be in English. " + + "It should not cause anything bad to happen even if the current culture is some other" + + "variant of a localized language (e.g., es-MX). By the way, the current " + + "locale is {0}"), System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag), + "FYI"); + SetUpLocalization(args.Any(a => a == "-m"), args.Any(a => a == "-tmx")); LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false); @@ -32,12 +39,12 @@ static void Main(string[] args) _localizationManager = null; } - public static void SetUpLocalization(bool useAdditionalMethodInfo, bool useTmx) + private static void SetUpLocalization(bool useAdditionalMethodInfo, bool useTmx) { if (useTmx) throw new NotSupportedException("TMX-based localization is no longer supported."); - //your installer should have a folder where you place the localization files you're shipping with the program + // Your installer should have a folder where you place the localization files you're shipping with the program var directoryOfInstalledLocFiles = "../../LocalizationFilesFromInstaller"; Directory.CreateDirectory(directoryOfInstalledLocFiles); diff --git a/src/SampleApp/SampleApp.csproj b/src/SampleApp/SampleApp.csproj index d184764..da09d72 100644 --- a/src/SampleApp/SampleApp.csproj +++ b/src/SampleApp/SampleApp.csproj @@ -4,6 +4,7 @@ SampleApp SampleApp false + false From e326deec8a786799bfdbe19e2847a94b02401215 Mon Sep 17 00:00:00 2001 From: tombogle Date: Mon, 4 Nov 2024 14:12:16 -0500 Subject: [PATCH 2/2] Added command-line switch to SampleApp to allow testing LM in both strict (default) and permissive initialization mode --- .gitignore | 2 +- src/SampleApp/Program.cs | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 51468f6..d4148f9 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,5 @@ bin/ packages/ /.vs/ build/nuget.exe -/src/ExtractXliff/Properties/launchSettings.json +/src/**/Properties/launchSettings.json /src/*/gitversion.json diff --git a/src/SampleApp/Program.cs b/src/SampleApp/Program.cs index 2928e85..05a9c0d 100644 --- a/src/SampleApp/Program.cs +++ b/src/SampleApp/Program.cs @@ -2,10 +2,12 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Linq.Expressions; using System.Reflection; using System.Windows.Forms; using L10NSharp; using SampleApp.Properties; +using static System.String; namespace SampleApp { @@ -21,12 +23,30 @@ static void Main(string[] args) Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - MessageBox.Show(string.Format(LocalizationManager.GetString("accessed.before.setting.up.lm", - "Localization is not yet set up, so this will always be in English. " + - "It should not cause anything bad to happen even if the current culture is some other" + - "variant of a localized language (e.g., es-MX). By the way, the current " + - "locale is {0}"), System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag), - "FYI"); + if (args.Any(a => a == "-i:permissive")) + LocalizationManager.StrictInitializationMode = false; + + try + { + // If StrictInitializationMode (the default), this should now throw an + // InvalidOperationException, which we will catch and (for the purposes + // of this sample app) ignore. + MessageBox.Show(Format( + LocalizationManager.GetString("accessed.before.setting.up.lm", + "Localization is not yet set up, so this will always be in English. " + + "It should not cause anything bad to happen even if the current culture " + + "is some other variant of a localized language (e.g., es-MX). By the " + + "way, the current locale is {0}"), + System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag), + "FYI"); + } + catch (InvalidOperationException ex) + { + if (LocalizationManager.StrictInitializationMode) + Trace.WriteLine($"Got expected {ex.GetType().FullName} exception: {ex.Message}"); + else + throw; + } SetUpLocalization(args.Any(a => a == "-m"), args.Any(a => a == "-tmx")); @@ -50,9 +70,9 @@ private static void SetUpLocalization(bool useAdditionalMethodInfo, bool useTmx) try { - //if this is your first time running the app, the library will query the OS for the - //the default language. If it doesn't have that, it puts up a dialog listing what - //it does have to offer. + // If this is your first time running the app, the library will query the OS for the + // default language. If it doesn't have that, it puts up a dialog listing what + // it does have to offer. var theLanguageYouRememberedFromLastTime = Settings.Default.UserInterfaceLanguage;