diff --git a/CHANGELOG.md b/CHANGELOG.md index ba7deb7..50673cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,83 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed + +- BREAKING CHANGE: Move code that depends on Windows.Forms or System.Drawing into an L10NSharp.Windows.Forms namespace. Rename L10NSharp.UI as L10NSharp.Windows.Forms.UIComponents. Move L10NExtender out of UI subfolder into L10NSharp.Windows.Forms. Move Winforms related tests to L10NSharp.Windows.Forms.Tests. Change the folder for L10NSharp tests to match its namespace L10NSharp.Tests. + + Classes that contain some properties or methods that depend on Windows.Forms are split into Winforms-dependent and Winforms-independent classes. The Winforms-dependent classes subclass the Winforms-independent ones and can be found in the L10NSharp.Windows.Forms namespace. (e.g. LocalizationManagerWinforms in the L10NSharp.Windows.Forms namespace is a subclass of LocalizationManager in the L10NSharp namespace.) + + To handle Windows forms related objects, call the Winforms versions of these classes and methods (e.g. LocalizationManagerWinforms.Create() instead of LocalizationManager.Create()). Each affected interface or class and its affected properties and methods are listed below. + + - Split ILocalizationManagerInternal into ILocalizationManagerInternal and ILocalizationManagerInternalWinforms. + + CHANGED: ILocalizationManagerInternalWinforms\ declares a new StringCache object of type ILocalizedStringCacheWinforms\, while ILocalizationManagerInternal\ has a StringCache object of type ILocalizedStringCache\. + + MOVED: The properties ToolTipCtrls, LocalizableComponents, and ApplicationIcon; and the methods ApplyLocalization, ApplyLocalizationsToILocalizableComponent, ReapplyLocalizationsToAllComponents, and RegisterComponentForLocalizing are moved to ILocalizationManagerInternalWinforms. + + - Split ILocalizedStringCache into ILocalizedStringCache and ILocalizedStringCacheWinforms. + + MOVED: The property LeafNodeList, and the methods GetShortcutKeys and LoadGroupNodes are moved to ILocalizedStringCacheWinforms. + + - Split LocalizationManager into LocalizationManager and LocalizationManagerWinforms. + + CHANGED: Remove static designation from the LocalizationManager class in order for LocalizationManagerWinforms to subclass it and share its properties. + + CHANGED: The Icon argument is removed from the Create methods in LocalizationManager. Create methods for LocalizationManagerWinforms are available with and without the Icon argument. (The two obsolete create methods in LocalizationManager, which included a TranslationMemory argument, are removed.) + + CHANGED: SetUILanguage in LocalizationManager no longer reapplies localizations based on a reapplyLocalizationsToAllObjectsInAllManagers argument, since reapplying localizations is a Winforms method. SetUILanguage in LocalizationManagerWinforms retains this argument and reapplies localizations depending on its value. + + MOVED: The methods ReapplyLocalizationsToAllObjectsInAllManagers, ReapplyLocalizationsToAllObjects, and GetLocalisedToolTipForControl are moved to LocalizationManagerWinforms. + + - Split LocalizationManagerInternal into LocalizationManagerInternal and LocalizationManagerInternalWinforms. + + CHANGED: Remove static designation from LocalizationManagerInternal class in order for LocalizationManagerInternalWinforms to subclass it and share its s_loadedManagers property. + + CHANGED: Use different handling for ChooseFallbackLanguage in LocalizationManagerInternal that omits use of a Windows forms dialog for choosing the fallback. Retain original Winforms-dependent handling for ChooseFallbackLanguage in LocalizationManagerInternalWinforms. + + CHANGED: Use different handling for GetString in LocalizationManagerInternal that omits handling of Winforms objects and methods. Retain original Winforms-dependent handling of GetString in LocalizationManagerInternalWinforms. + + CHANGED: Remove Icon argument from the CreateXliff method in LocalizationManagerInternal. CreateXliff methods in LocalizationManagerInternalWinforms are available with and without the Icon argument. + + CHANGED: In LocalizationManagerInternalWinforms, GetLocalizationManagerForComponent and GetLocalizationManagerForString, return type ILocalizationManagerInternalWinforms\ instead of ILocalizationManagerInternal\. + + MOVED: The methods ReapplyLocalizationsToAllObjectsInAllManagers, ReapplyLocalizationsToAllObjects, GetLocalizedToolTipForControl, and GetRealTopLevelControl are moved to LocalizationManagerInternalWinforms. + + - Split LocalizingInfo into LocalizingInfo and LocalizingInfoWinforms. + + CHANGED: Make private properties protected. LocalizingInfo returns null for Id while LocalizingInfoWinforms retains method to make an Id from a winforms component. + + MOVED: The get methods for ShortcutKeys and Id properties are moved to LocalizingInfoWinforms, since they involve winforms components; LocalizingInfo will return null for ShortcutKeys and Id. The methods UpdateTextFromObject, CreateIdIfMissing, MakeId, MakeIdForCtrl, MakeIdForColumnHeader, MakeIdForDataGridViewColumn, GetIdPrefix, OwningFormName and GetCategory are moved to LocalizingInfoWinforms + + - Split Utils into Utils and UtilsWinforms. + + MOVED: The methods SendMessage, SendMessageWindows and SetWindowRedraw are moved to UtilsWinforms. + + - Split XliffLocalizationManager into XliffLocalizationManager and XliffLocalizationManagerWinforms. + + MOVED: The following are moved to XliffLocalizationManagerWinforms: + + - The properties ApplicationIcon, ToolTipCtrls, LocalizableComponents and StringCache. + - The methods RegisterComponentForLocalizing, GetShortcutKeyFromStringCache, ApplyLocalizationToIlocalizableComponent, ReapplyLocalizationsToAllComponents, RefreshToolTips, ApplyLocalization, ApplyLocalizationsToILocalizableComponent, ApplyLocalizationsToControl, ApplyLocalizedToolTipToControl, HandleToolTipRefChanged, HandleToolTipRefDestroyed, ApplyLocalizationsToToolStripItem, ApplyLocalizationToListViewColumnHeader, and ApplyLocalizationToDataGridViewColumn. + + - Split XliffLocalizedStringCache into XliffLocalizedStringCacheWinforms and XliffLocalizedStringCache. + + MOVED: The LeafNodeList property and the methods LoadGroupNodes and GetShortcutKeys are moved to XliffLocalizedStringCacheWinforms. + +### Removed + +- BREAKING CHANGE: Remove code related to doing one's own localization at runtime. Also remove obsolete create methods from LocalizationManager. + + In particular: + + - Remove the LocalizeItemDlg designer, cs, resx, and viewmodel. + - Remove ShowLocalizationDialogBox from LocalizationManager and LocalizationManagerInternal. + - Remove the following runtime-localization related methods from XliffLocalizationManager: + PrepareComponentForRuntimeLocalization, HandleToolStripItemMouseDown, DoHandleMouseDown, HandeToolStripItemDisposed, HandleControlMouseDouwn, HandleControlDisposed, HandleTabPageDisposed, HandleDataGridViewDisposed, HandleListViewColumnHeaderClicked, HandleListViewDisposed, HandleListViewColumnDisposed, HandleDataGridViewCellMouseDown, HandleColumnDisposed, and ShowLocalizationDialogBox. + - Remove obsolete Create methods from LocalizationManager. These are the two Create methods that included a TranslationMemory argument. + + Also, remove RefreshToolTips from ILocalizationManager. All references were already to specific implementations of the method, and RefreshToolTips is not needed in the Winforms-free side of L10NSharp. + ## [8.0.0] - 2025-03-12 ### Changed diff --git a/L10NSharp.sln b/L10NSharp.sln index 244b42c..4309409 100644 --- a/L10NSharp.sln +++ b/L10NSharp.sln @@ -4,8 +4,6 @@ VisualStudioVersion = 17.0.32112.339 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "L10NSharp", "src\L10NSharp\L10NSharp.csproj", "{8EE0895A-7B9D-4B49-8F73-9F1270F1E583}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "L10NSharpTests", "src\L10NSharpTests\L10NSharpTests.csproj", "{BCE5B569-057C-4D7E-832E-E44A2DA705AC}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleApp", "src\SampleApp\SampleApp.csproj", "{58923B30-FD84-4BCC-85E0-607DCA7E7C95}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExtractXliff", "src\ExtractXliff\ExtractXliff.csproj", "{E0666C78-B8DC-4232-952C-753940D54921}" @@ -24,6 +22,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFolder", "SolutionF README.md = README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "L10NSharp.Windows.Forms", "src\L10NSharp.Windows.Forms\L10NSharp.Windows.Forms.csproj", "{B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "L10NSharp.Windows.Forms.Tests", "src\L10NSharp.Windows.Forms.Tests\L10NSharp.Windows.Forms.Tests.csproj", "{DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "L10NSharp.Tests", "src\L10NSharp.Tests\L10NSharp.Tests.csproj", "{B0218FB3-62E0-487B-B154-5788D8EF8345}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -44,16 +48,6 @@ Global {8EE0895A-7B9D-4B49-8F73-9F1270F1E583}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {8EE0895A-7B9D-4B49-8F73-9F1270F1E583}.Release|Mixed Platforms.Build.0 = Release|Any CPU {8EE0895A-7B9D-4B49-8F73-9F1270F1E583}.Release|x86.ActiveCfg = Release|Any CPU - {BCE5B569-057C-4D7E-832E-E44A2DA705AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BCE5B569-057C-4D7E-832E-E44A2DA705AC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BCE5B569-057C-4D7E-832E-E44A2DA705AC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {BCE5B569-057C-4D7E-832E-E44A2DA705AC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {BCE5B569-057C-4D7E-832E-E44A2DA705AC}.Debug|x86.ActiveCfg = Debug|Any CPU - {BCE5B569-057C-4D7E-832E-E44A2DA705AC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BCE5B569-057C-4D7E-832E-E44A2DA705AC}.Release|Any CPU.Build.0 = Release|Any CPU - {BCE5B569-057C-4D7E-832E-E44A2DA705AC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {BCE5B569-057C-4D7E-832E-E44A2DA705AC}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {BCE5B569-057C-4D7E-832E-E44A2DA705AC}.Release|x86.ActiveCfg = Release|Any CPU {58923B30-FD84-4BCC-85E0-607DCA7E7C95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {58923B30-FD84-4BCC-85E0-607DCA7E7C95}.Debug|Any CPU.Build.0 = Debug|Any CPU {58923B30-FD84-4BCC-85E0-607DCA7E7C95}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -89,6 +83,42 @@ Global {E4BB984D-DFB8-42EF-860D-5A038FF85B1C}.Release|Mixed Platforms.Build.0 = Release|Any CPU {E4BB984D-DFB8-42EF-860D-5A038FF85B1C}.Release|x86.ActiveCfg = Release|Any CPU {E4BB984D-DFB8-42EF-860D-5A038FF85B1C}.Release|x86.Build.0 = Release|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Debug|x86.ActiveCfg = Debug|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Debug|x86.Build.0 = Debug|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Release|Any CPU.Build.0 = Release|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Release|x86.ActiveCfg = Release|Any CPU + {B118A158-F6A9-4346-ADC7-A9FEBCE5BE68}.Release|x86.Build.0 = Release|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Debug|x86.ActiveCfg = Debug|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Debug|x86.Build.0 = Debug|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Release|Any CPU.Build.0 = Release|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Release|x86.ActiveCfg = Release|Any CPU + {DCF3741C-9496-4495-BF57-0DBA1DBBB7F5}.Release|x86.Build.0 = Release|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Debug|x86.ActiveCfg = Debug|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Debug|x86.Build.0 = Debug|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Release|Any CPU.Build.0 = Release|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Release|x86.ActiveCfg = Release|Any CPU + {B0218FB3-62E0-487B-B154-5788D8EF8345}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/README.md b/README.md index 9ba722c..9631382 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ ## Overview -L10NSharp is a .NET localization library for Windows Forms applications. It collects strings which -need localization when your application first runs and saves them in a translation memory file. It -can also dynamically collect strings at runtime. +L10NSharp is a .NET localization library. It collects strings which need localization when your +application first runs and saves them in a translation memory file. + +L10NSharp.Windows.Forms builds on L10NSharp and should be used for localization of Windows Forms applications. L10NSharp works with XLIFF files as translation memory. @@ -12,10 +13,24 @@ L10NSharp works with XLIFF files as translation memory. [![NuGet version (L10NSharp)](https://img.shields.io/nuget/v/L10NSharp.svg?style=flat-square)](https://www.nuget.org/packages/L10NSharp/) -L10NSharp is provided as a [nuget package](https://www.nuget.org/packages/L10NSharp). +L10NSharp and L10NSharp.Windows.Forms are provided as [nuget packages](https://www.nuget.org/packages/L10NSharp). -To use L10NSharp in your application, simply call the `Create` method on `LocalizationManager`, -passing the location of the translation memory files and some other information: +To use L10NSharp in your application, call the `Create` method on `LocalizationManager`, +passing the location of the translation memory XLIFF files and some other information: + +```csharp +using (var lm = LocalizationManager.Create(lang, "SampleApp", + "SampleApp", productVersion, directoryOfInstalledXliffFiles, "MyCompany/L10NSharpSample", + "sample@example.com", "SampleApp") +{ + // existing code to run the application +} +``` + +To use L10NSharp.Windows.Forms in your Windows forms application, you can call the `Create` method +on `LocalizationManagerWinforms` instead, passing the location of the translation memory XLIFF +files and the other information as above. Note that the `Create` for Windows forms applications can +optionally include an additional icon argument: ```csharp using (var lm = LocalizationManager.Create(lang, "SampleApp", @@ -39,8 +54,10 @@ or `es/Whatever.xlf`). ### Selecting a Language If an exact match for the requested language is not available, L10NSharp will try to find the best available language. For example, if the client -requests `es` but only `Whatever.es-ES.xlf` is available, `Whatever.es-ES.xlf` will be loaded automatically, and vice versa. However, if the client -requests `es` and both `Whatever.es-ES.xlf` and `Whatever.es-MX.xlf` are available, or if no `Whatever.es[-details].xlf` is available, a dialog will +requests `es` but only `Whatever.es-ES.xlf` is available, `Whatever.es-ES.xlf` will be loaded automatically, and vice versa. + +In L10NSharp.Windows.Forms, if the client +requests `es` and both `Whatever.es-ES.xlf` and `Whatever.es-MX.xlf` are available, or if no `Whatever.es[-details].xlf` is available, a Windows forms dialog will inform the user that the selected language is not available and prompt the user to select from the available languages. ## Thread safety @@ -51,14 +68,9 @@ attempted to make the various varieties of `GetString` thread-safe,. ## L10NSharpExtender -To localize a Windows Forms form or control, simply add the `L10NSharpExtender`. It will +To localize a Windows Forms form or control, simply add the `L10NSharpExtender` from L10NSharp.Windows.Forms. It will automatically collect all the localizable strings on your form or control and its children. -## Localizing Within the Application - -L10NSharp provides a dialog for translating terms while running the application. The dialog can be -launched by Alt-Shift-clicking a Windows Forms element. - ## Upgrading to a newer version The [migration](https://github.com/sillsdev/l10nsharp/wiki/Migration) guide describes the diff --git a/src/L10NSharpTests/CodeReaderTests.cs b/src/L10NSharp.Tests/CodeReaderTests.cs similarity index 100% rename from src/L10NSharpTests/CodeReaderTests.cs rename to src/L10NSharp.Tests/CodeReaderTests.cs diff --git a/src/L10NSharpTests/L10NCultureInfoTests.cs b/src/L10NSharp.Tests/L10NCultureInfoTests.cs similarity index 100% rename from src/L10NSharpTests/L10NCultureInfoTests.cs rename to src/L10NSharp.Tests/L10NCultureInfoTests.cs diff --git a/src/L10NSharpTests/L10NSharpTests.csproj b/src/L10NSharp.Tests/L10NSharp.Tests.csproj similarity index 100% rename from src/L10NSharpTests/L10NSharpTests.csproj rename to src/L10NSharp.Tests/L10NSharp.Tests.csproj diff --git a/src/L10NSharpTests/LocalizationManagerTestsBase.cs b/src/L10NSharp.Tests/LocalizationManagerTestsBase.cs similarity index 94% rename from src/L10NSharpTests/LocalizationManagerTestsBase.cs rename to src/L10NSharp.Tests/LocalizationManagerTestsBase.cs index 4dab434..9b40ab9 100644 --- a/src/L10NSharpTests/LocalizationManagerTestsBase.cs +++ b/src/L10NSharp.Tests/LocalizationManagerTestsBase.cs @@ -44,7 +44,7 @@ public void TearDownLocalizationManagers() LocalizationManager.UseLanguageCodeFolders = false; LocalizationManagerInternal.LoadedManagers.Clear(); LocalizationManagerInternal.MapToExistingLanguage.Clear(); - LocalizationManager.SetUILanguage(LocalizationManager.kDefaultLang, false); + LocalizationManager.SetUILanguage(LocalizationManager.kDefaultLang); } /// @@ -321,7 +321,7 @@ public string GetDynamicStringOrEnglish(string langId, string uiLangId) using(var folder = new TempFolder()) { SetupManager(folder, "ar"); - LocalizationManager.SetUILanguage(uiLangId, true); + LocalizationManager.SetUILanguage(uiLangId); return LocalizationManager.GetDynamicStringOrEnglish(AppId, "blahId", "blahInEnglishInCode", "comment", langId); } } @@ -472,7 +472,7 @@ public void SetupManager(TempFolder folder, string uiLanguageId = LocalizationMa AddFrenchTranslation(GetInstalledDirectory(folder)); AddSpanishTranslation(GetInstalledDirectory(folder)); - LocalizationManager.SetUILanguage(uiLanguageId, true); + LocalizationManager.SetUILanguage(uiLanguageId); var manager = CreateLocalizationManager(AppId, AppName, AppVersion, GetInstalledDirectory(folder), GetGeneratedDirectory(folder), GetUserModifiedDirectory(folder)); @@ -664,7 +664,7 @@ public void OrphanLogicUsedForArabic_ButNotIfFoundInEnglishTranslation() GetInstalledDirectory(folder), GetUserModifiedDirectory(folder), GetUserModifiedDirectory(folder)); LocalizationManagerInternal.LoadedManagers[AppId] = manager; - LocalizationManager.SetUILanguage("ar", false); + LocalizationManager.SetUILanguage("ar"); Assert.That(LocalizationManager.GetDynamicStringOrEnglish(AppId, "SuperClassMethod.TestId", null, null, "en"), Is.EqualTo("Title")); Assert.That(LocalizationManager.GetDynamicStringOrEnglish(AppId, "AnotherContext.AnotherDialog.TestId", null, null, "en"), Is.EqualTo("Title")); @@ -686,7 +686,7 @@ public void OrphanLogicNotUsed_WithWrongEnglishSource() GetInstalledDirectory(folder), GetUserModifiedDirectory(folder), GetUserModifiedDirectory(folder)); LocalizationManagerInternal.LoadedManagers[AppId] = manager; - LocalizationManager.SetUILanguage("ar", false); + LocalizationManager.SetUILanguage("ar"); Assert.That(LocalizationManager.GetDynamicStringOrEnglish(AppId, "SuperClassMethod.TestId", null, null, "en"), Is.EqualTo("Title")); Assert.That(LocalizationManager.GetDynamicStringOrEnglish(AppId, "AnotherContext.AnotherDialog.TestId", null, null, "en"), Is.EqualTo("Title")); @@ -779,7 +779,7 @@ public void TranslationWithNewlineReplacement_YieldsStandardizedNewline() doc.AddTransUnit(tuF); doc.Save(Path.Combine(folder.Path, LocalizationManager.GetTranslationFileNameForLanguage(AppId, "fr"))); - LocalizationManager.SetUILanguage("fr", true); + LocalizationManager.SetUILanguage("fr"); var manager = CreateLocalizationManager(AppId, AppName, AppVersion, GetInstalledDirectory(folder), GetGeneratedDirectory(folder), GetUserModifiedDirectory(folder)); LocalizationManagerInternal.LoadedManagers[AppId] = manager; @@ -804,7 +804,7 @@ public void TestInexactLanguageMatching() // unchanged UI language. Calling the method to set the fallback languages will // possibly change the UI language to something less (or more) specific, and // possibly have a longer fallback list. - LocalizationManager.SetUILanguage("es", true); + LocalizationManager.SetUILanguage("es"); Assert.AreEqual("es", LocalizationManager.UILanguageId); Assert.AreEqual(1, LocalizationManager.FallbackLanguageIds.Count()); Assert.AreEqual("en", LocalizationManager.FallbackLanguageIds.First()); @@ -814,7 +814,7 @@ public void TestInexactLanguageMatching() Assert.AreEqual(1, LocalizationManager.FallbackLanguageIds.Count()); Assert.AreEqual("en", LocalizationManager.FallbackLanguageIds.First()); - LocalizationManager.SetUILanguage("fr-FR", true); + LocalizationManager.SetUILanguage("fr-FR"); Assert.AreEqual("fr-FR", LocalizationManager.UILanguageId); Assert.AreEqual(1, LocalizationManager.FallbackLanguageIds.Count()); Assert.AreEqual("en", LocalizationManager.FallbackLanguageIds.First()); @@ -823,7 +823,7 @@ public void TestInexactLanguageMatching() Assert.AreEqual(1, LocalizationManager.FallbackLanguageIds.Count()); Assert.AreEqual("en", LocalizationManager.FallbackLanguageIds.First()); - LocalizationManager.SetUILanguage("en-GB", true); + LocalizationManager.SetUILanguage("en-GB"); Assert.AreEqual("en-GB", LocalizationManager.UILanguageId); Assert.AreEqual(1, LocalizationManager.FallbackLanguageIds.Count()); Assert.AreEqual("en", LocalizationManager.FallbackLanguageIds.First()); @@ -838,7 +838,7 @@ public void TestInexactLanguageMatching() Assert.AreEqual(1, LocalizationManager.FallbackLanguageIds.Count()); Assert.AreEqual("en", LocalizationManager.FallbackLanguageIds.First()); - LocalizationManager.SetUILanguage("en-GB", true); + LocalizationManager.SetUILanguage("en-GB"); Assert.AreEqual("en-GB", LocalizationManager.UILanguageId); Assert.AreEqual(1, LocalizationManager.FallbackLanguageIds.Count()); Assert.AreEqual("en", LocalizationManager.FallbackLanguageIds.First()); @@ -868,7 +868,7 @@ public void GetString_UsesFallbackLanguages() AddFrenchTranslation(GetInstalledDirectory(folder)); AddSpanishTranslation(GetInstalledDirectory(folder)); - LocalizationManager.SetUILanguage("ha", true); + LocalizationManager.SetUILanguage("ha"); var manager = CreateLocalizationManager(AppId, AppName, AppVersion, GetInstalledDirectory(folder), GetGeneratedDirectory(folder), GetUserModifiedDirectory(folder)); LocalizationManagerInternal.LoadedManagers[AppId] = manager; @@ -917,7 +917,7 @@ internal void AddOverSpecifiedSpanishTranslation(string folderPath) [Test] public void TestMappingLanguageCodesToAvailable() { - LocalizationManager.SetUILanguage("en", true); + LocalizationManager.SetUILanguage("en"); LocalizationManagerInternal.LoadedManagers.Clear(); using (var folder = new TempFolder()) { @@ -980,17 +980,16 @@ public void TestMappingLanguageCodesToAvailable() [Test] public void TestMappingLanguageCodesToAvailable_FindsSpecificGivenGeneric() { - LocalizationManager.SetUILanguage("en", true); + LocalizationManager.SetUILanguage("en"); LocalizationManagerInternal.LoadedManagers.Clear(); using (var folder = new TempFolder()) { var installedFolder = Path.Combine(folder.Path, "installed"); AddEnglishTranslation(installedFolder, null); AddChineseOfChinaTranslation(installedFolder); - LocalizationManagerInternal.ChooseFallbackLanguage = (langTag, icon) => - throw new NotImplementedException($"{langTag} shouldn't have stumped us"); + LocalizationManagerInternal.ChooseFallbackLanguage(); var manager = LocalizationManager.Create("zh", AppId, AppName, AppVersion, installedFolder, - $"Temp/{Path.GetFileName(folder.Path)}/user", null, null, new string[] { }); + $"Temp/{Path.GetFileName(folder.Path)}/user", null, new string[] { }); LocalizationManagerInternal.LoadedManagers[AppId] = (ILocalizationManagerInternal)manager; var langs = LocalizationManager.GetAvailableLocalizedLanguages(); @@ -1007,42 +1006,5 @@ public void TestMappingLanguageCodesToAvailable_FindsSpecificGivenGeneric() Assert.That(languageIdUsed, Is.EqualTo("zh-CN")); } } - - [Test] - public void TestMappingLanguageCodesToAvailable_AmbiguousOptions_PromptsUser([Values("zh-CN", "zh-TW")] string choice) - { - LocalizationManager.SetUILanguage("en", true); - LocalizationManagerInternal.LoadedManagers.Clear(); - using (var folder = new TempFolder()) - { - var installedFolder = Path.Combine(folder.Path, "installed"); - // ReSharper disable once AssignNullToNotNullAttribute - var userRelativeFolder = Path.Combine("Temp", Path.GetFileName(Path.GetDirectoryName(folder.Path)), - Path.GetFileName(folder.Path), "user"); - AddEnglishTranslation(installedFolder, null); - AddChineseOfChinaTranslation(installedFolder); - AddChineseOfTaiwanTranslation(installedFolder); - var userPromptCount = 0; - LocalizationManagerInternal.ChooseFallbackLanguage = (langTag, icon) => - { - userPromptCount++; - Assert.That(langTag, Is.EqualTo("zh")); - return choice; - }; - var manager = LocalizationManager.Create("zh", AppId, AppName, AppVersion, installedFolder, - userRelativeFolder, null, null, new string[] { }); - Assert.That(userPromptCount, Is.EqualTo(1)); - LocalizationManagerInternal.LoadedManagers[AppId] = (ILocalizationManagerInternal)manager; - - var langs = LocalizationManager.GetAvailableLocalizedLanguages(); - Assert.That(langs, Is.EquivalentTo(new[] { "en", "zh-CN", "zh-TW" })); - Assert.That(LocalizationManager.UILanguageId, Is.EqualTo(choice)); - - Assert.That(LocalizationManager.GetIsStringAvailableForLangId("theId", "zh"), Is.False, "zh is ambiguous"); - Assert.That(LocalizationManager.GetIsStringAvailableForLangId("theId", "zh-CN"), Is.True, "zh-CN should find zh-CN"); - Assert.That(LocalizationManager.GetIsStringAvailableForLangId("theId", "zh-TW"), Is.True, "zh-TW should find zh-TW"); - Assert.That(LocalizationManager.GetIsStringAvailableForLangId("theId", "en"), Is.True, "en should find en"); - } - } } } diff --git a/src/L10NSharpTests/LocalizationManagerTests_NoManagersLoaded.cs b/src/L10NSharp.Tests/LocalizationManagerTests_NoManagersLoaded.cs similarity index 100% rename from src/L10NSharpTests/LocalizationManagerTests_NoManagersLoaded.cs rename to src/L10NSharp.Tests/LocalizationManagerTests_NoManagersLoaded.cs diff --git a/src/L10NSharpTests/LocalizationManagerXliffTests.cs b/src/L10NSharp.Tests/LocalizationManagerXliffTests.cs similarity index 97% rename from src/L10NSharpTests/LocalizationManagerXliffTests.cs rename to src/L10NSharp.Tests/LocalizationManagerXliffTests.cs index 30718f4..47ff2f7 100644 --- a/src/L10NSharpTests/LocalizationManagerXliffTests.cs +++ b/src/L10NSharp.Tests/LocalizationManagerXliffTests.cs @@ -40,7 +40,7 @@ public void Create_PreferredUiLanguageIsGenericVariant_CreatesLocalizationManage LocalizationManager.ClearLoadedManagers(); var dir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); var lm = LocalizationManager.Create(genericLocaleId, "Test", "Test", "1.0", - Path.Combine(dir, "../../../src/L10NSharpTests/TestXliff2"), "", null, "", + Path.Combine(dir, "../../../src/L10NSharp.Tests/TestXliff2"), "", "", new string[] {}); Assert.AreEqual($"Protección de configuraciones ({genericLocaleId})...", lm.GetLocalizedString("SettingsProtection.LauncherButtonLabel", "don't use this")); diff --git a/src/L10NSharpTests/ProxyLocalizationManager.cs b/src/L10NSharp.Tests/ProxyLocalizationManager.cs similarity index 100% rename from src/L10NSharpTests/ProxyLocalizationManager.cs rename to src/L10NSharp.Tests/ProxyLocalizationManager.cs diff --git a/src/L10NSharpTests/TempFile.cs b/src/L10NSharp.Tests/TempFile.cs similarity index 100% rename from src/L10NSharpTests/TempFile.cs rename to src/L10NSharp.Tests/TempFile.cs diff --git a/src/L10NSharpTests/TestXliff/Test.en.xlf b/src/L10NSharp.Tests/TestXliff/Test.en.xlf similarity index 100% rename from src/L10NSharpTests/TestXliff/Test.en.xlf rename to src/L10NSharp.Tests/TestXliff/Test.en.xlf diff --git a/src/L10NSharpTests/TestXliff/Test.es.xlf b/src/L10NSharp.Tests/TestXliff/Test.es.xlf similarity index 100% rename from src/L10NSharpTests/TestXliff/Test.es.xlf rename to src/L10NSharp.Tests/TestXliff/Test.es.xlf diff --git a/src/L10NSharpTests/TestXliff/Test.fr.xlf b/src/L10NSharp.Tests/TestXliff/Test.fr.xlf similarity index 100% rename from src/L10NSharpTests/TestXliff/Test.fr.xlf rename to src/L10NSharp.Tests/TestXliff/Test.fr.xlf diff --git a/src/L10NSharpTests/TestXliff/Test2.en.xlf b/src/L10NSharp.Tests/TestXliff/Test2.en.xlf similarity index 100% rename from src/L10NSharpTests/TestXliff/Test2.en.xlf rename to src/L10NSharp.Tests/TestXliff/Test2.en.xlf diff --git a/src/L10NSharpTests/TestXliff/xliff-core-1.2-strict.xsd b/src/L10NSharp.Tests/TestXliff/xliff-core-1.2-strict.xsd similarity index 100% rename from src/L10NSharpTests/TestXliff/xliff-core-1.2-strict.xsd rename to src/L10NSharp.Tests/TestXliff/xliff-core-1.2-strict.xsd diff --git a/src/L10NSharpTests/TestXliff/xliff-core-1.2-transitional.xsd b/src/L10NSharp.Tests/TestXliff/xliff-core-1.2-transitional.xsd similarity index 100% rename from src/L10NSharpTests/TestXliff/xliff-core-1.2-transitional.xsd rename to src/L10NSharp.Tests/TestXliff/xliff-core-1.2-transitional.xsd diff --git a/src/L10NSharpTests/TestXliff2/Test.en.xlf b/src/L10NSharp.Tests/TestXliff2/Test.en.xlf similarity index 100% rename from src/L10NSharpTests/TestXliff2/Test.en.xlf rename to src/L10NSharp.Tests/TestXliff2/Test.en.xlf diff --git a/src/L10NSharpTests/TestXliff2/Test.es.xlf b/src/L10NSharp.Tests/TestXliff2/Test.es.xlf similarity index 100% rename from src/L10NSharpTests/TestXliff2/Test.es.xlf rename to src/L10NSharp.Tests/TestXliff2/Test.es.xlf diff --git a/src/L10NSharpTests/TestXliff2/Test.pt.xlf b/src/L10NSharp.Tests/TestXliff2/Test.pt.xlf similarity index 100% rename from src/L10NSharpTests/TestXliff2/Test.pt.xlf rename to src/L10NSharp.Tests/TestXliff2/Test.pt.xlf diff --git a/src/L10NSharpTests/XLiffLocalizationManagerTests.cs b/src/L10NSharp.Tests/XLiffLocalizationManagerTests.cs similarity index 100% rename from src/L10NSharpTests/XLiffLocalizationManagerTests.cs rename to src/L10NSharp.Tests/XLiffLocalizationManagerTests.cs diff --git a/src/L10NSharpTests/XLiffLocalizedStringCacheTests.cs b/src/L10NSharp.Tests/XLiffLocalizedStringCacheTests.cs similarity index 100% rename from src/L10NSharpTests/XLiffLocalizedStringCacheTests.cs rename to src/L10NSharp.Tests/XLiffLocalizedStringCacheTests.cs diff --git a/src/L10NSharpTests/XLiffSchemaValidationTests.cs b/src/L10NSharp.Tests/XLiffSchemaValidationTests.cs similarity index 98% rename from src/L10NSharpTests/XLiffSchemaValidationTests.cs rename to src/L10NSharp.Tests/XLiffSchemaValidationTests.cs index a586e66..706dd12 100644 --- a/src/L10NSharpTests/XLiffSchemaValidationTests.cs +++ b/src/L10NSharp.Tests/XLiffSchemaValidationTests.cs @@ -19,7 +19,7 @@ private static string SchemaLocation get { var dir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); - var installedXliffDir = "../../../src/L10NSharpTests/TestXliff"; + var installedXliffDir = "../../../src/L10NSharp.Tests/TestXliff"; var schemaLocation = Path.Combine(dir, installedXliffDir, "xliff-core-1.2-transitional.xsd"); diff --git a/src/L10NSharpTests/XLiffUtilsTests.cs b/src/L10NSharp.Tests/XLiffUtilsTests.cs similarity index 99% rename from src/L10NSharpTests/XLiffUtilsTests.cs rename to src/L10NSharp.Tests/XLiffUtilsTests.cs index ba2c83a..6bd68ba 100644 --- a/src/L10NSharpTests/XLiffUtilsTests.cs +++ b/src/L10NSharp.Tests/XLiffUtilsTests.cs @@ -20,7 +20,7 @@ public XLiffUtilsTests() folder = Path.GetDirectoryName(folder); folder = Path.GetDirectoryName(folder); folder = Path.GetDirectoryName(folder); - _testFolder = Path.Combine(folder, "src", "L10NSharpTests", "TestXliff"); + _testFolder = Path.Combine(folder, "src", "L10NSharp.Tests", "TestXliff"); } [Test] diff --git a/src/L10NSharpTests/ILocalizableComponentTests.cs b/src/L10NSharp.Windows.Forms.Tests/ILocalizableComponentTests.cs similarity index 91% rename from src/L10NSharpTests/ILocalizableComponentTests.cs rename to src/L10NSharp.Windows.Forms.Tests/ILocalizableComponentTests.cs index 4ec6df3..fbc02dc 100644 --- a/src/L10NSharpTests/ILocalizableComponentTests.cs +++ b/src/L10NSharp.Windows.Forms.Tests/ILocalizableComponentTests.cs @@ -1,11 +1,10 @@ using System; using System.IO; using System.Reflection; -using L10NSharp.UI; using L10NSharp.XLiffUtils; using NUnit.Framework; -namespace L10NSharp.Tests +namespace L10NSharp.Windows.Forms.Tests { /// ---------------------------------------------------------------------------------------- /// @@ -28,18 +27,18 @@ public class ILocalizableComponentXLiffTests protected void TestSetup(string installedTranslationDir) { var dir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); - m_manager = LocalizationManager.Create("en", "Test", "Test", "1.0", + m_manager = LocalizationManagerWinforms.Create("en", "LocalizableComponentTest", "LocalizableComponentTest", "1.0", Path.Combine(dir, installedTranslationDir), "", null, "", new string[] { }) - as ILocalizationManagerInternal; + as ILocalizationManagerInternalWinforms; m_translationPath = m_manager.GetPathForLanguage("en", true); - m_extender = new L10NSharpExtender { LocalizationManagerId = "Test" }; + m_extender = new L10NSharpExtender { LocalizationManagerId = "LocalizableComponentTest" }; } [SetUp] public void TestSetup() { - TestSetup("../../../src/L10NSharpTests/TestXliff"); + TestSetup("../../../src/L10NSharp.Windows.Forms.Tests/TestXliff"); } /// ------------------------------------------------------------------------------------ @@ -80,7 +79,7 @@ public void TestLocalizingALocalizableComponent() Assert.AreEqual("Fish-eating bird", locComponent.GetLocalizedStringFromMock(locComponent.BirdButton, "TestItem.Bird.Eagle")); // SUT2 - LocalizationManager.SetUILanguage("fr", true); + LocalizationManagerWinforms.SetUILanguage("fr", true); // Verify French Assert.AreEqual("C'est un corbeau", locComponent.GetLocalizedStringFromMock(locComponent.BirdButton, "TestItem.Bird.Crow")); diff --git a/src/L10NSharp.Windows.Forms.Tests/L10NSharp.Windows.Forms.Tests.csproj b/src/L10NSharp.Windows.Forms.Tests/L10NSharp.Windows.Forms.Tests.csproj new file mode 100644 index 0000000..681efd7 --- /dev/null +++ b/src/L10NSharp.Windows.Forms.Tests/L10NSharp.Windows.Forms.Tests.csproj @@ -0,0 +1,21 @@ + + + Unit tests for L10NSharpWinforms + L10NSharp.Windows.Forms.Tests + L10NSharp.Windows.Forms.Tests + false + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/L10NSharpTests/LanguageChoosingDialogViewModelTests.cs b/src/L10NSharp.Windows.Forms.Tests/LanguageChoosingDialogViewModelTests.cs similarity index 99% rename from src/L10NSharpTests/LanguageChoosingDialogViewModelTests.cs rename to src/L10NSharp.Windows.Forms.Tests/LanguageChoosingDialogViewModelTests.cs index a125627..bb7c2a2 100644 --- a/src/L10NSharpTests/LanguageChoosingDialogViewModelTests.cs +++ b/src/L10NSharp.Windows.Forms.Tests/LanguageChoosingDialogViewModelTests.cs @@ -2,11 +2,12 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using L10NSharp; using L10NSharp.Translators; -using L10NSharp.UI; +using L10NSharp.Windows.Forms.UIComponents; using NUnit.Framework; -namespace L10NSharp.Tests +namespace L10NSharp.Windows.Forms.Tests { [TestFixture] class LanguageChoosingDialogViewModelTests diff --git a/src/L10NSharpTests/LocalizationExtenderTests.cs b/src/L10NSharp.Windows.Forms.Tests/LocalizationExtenderTests.cs similarity index 90% rename from src/L10NSharpTests/LocalizationExtenderTests.cs rename to src/L10NSharp.Windows.Forms.Tests/LocalizationExtenderTests.cs index 4635a11..6f79859 100644 --- a/src/L10NSharpTests/LocalizationExtenderTests.cs +++ b/src/L10NSharp.Windows.Forms.Tests/LocalizationExtenderTests.cs @@ -1,15 +1,17 @@ using System.Collections.Generic; using System.Windows.Forms; -using L10NSharp.UI; +using L10NSharp; +using L10NSharp.Windows.Forms.UIComponents; using NUnit.Framework; +using L10NSharp.Windows.Forms; -namespace L10NSharp.Tests +namespace L10NSharp.Windows.Forms.Tests { [TestFixture] public class LocalizationExtenderTests { private L10NSharpExtender m_extender; - private Dictionary m_extCtrls; + private Dictionary m_extCtrls; /// ------------------------------------------------------------------------------------ /// @@ -21,7 +23,7 @@ public void TestSetup() { m_extender = new L10NSharpExtender(); m_extCtrls = ReflectionHelper.GetField(m_extender, "m_extendedCtrls") as - Dictionary; + Dictionary; } /// ------------------------------------------------------------------------------------ @@ -72,28 +74,28 @@ public void GetLocalizedObjectInfoTest() var lbl1 = new Label(); lbl1.Text = "bananas"; - // Make sure calling GetLocalizedObjectInfo creates a LocalizingInfo object when + // Make sure calling GetLocalizedObjectInfo creates a LocalizingInfoWinforms object when // one doesn't exist for the label. - var loi = ReflectionHelper.GetResult(m_extender, "GetLocalizedComponentInfo", new object[] {lbl1, true}) as LocalizingInfo; + var loi = ReflectionHelper.GetResult(m_extender, "GetLocalizedComponentInfo", new object[] {lbl1, true}) as LocalizingInfoWinforms; Assert.AreEqual(1, m_extCtrls.Count); Assert.AreEqual("bananas", loi.Text); - // Make sure calling GetLocalizedObjectInfo does not create a LocalizingInfo object when + // Make sure calling GetLocalizedObjectInfo does not create a LocalizingInfoWinforms object when // one already exists for the label. - loi = ReflectionHelper.GetResult(m_extender, "GetLocalizedComponentInfo", new object[] { lbl1, true }) as LocalizingInfo; + loi = ReflectionHelper.GetResult(m_extender, "GetLocalizedComponentInfo", new object[] { lbl1, true }) as LocalizingInfoWinforms; Assert.AreEqual(1, m_extCtrls.Count); Assert.AreEqual("bananas", loi.Text); - // Create a new LocalizingInfo object for a different label, then poke it into the + // Create a new LocalizingInfoWinforms object for a different label, then poke it into the // extender's internal collection and make sure calling GetLocalizedObjectInfo returns - // that LocalizingInfo for the object. + // that LocalizingInfoWinforms for the object. var lbl2 = new Label(); lbl2.Text = "apples"; - loi = new LocalizingInfo(lbl2, true); + loi = new LocalizingInfoWinforms(lbl2, true); m_extCtrls[lbl2] = loi; Assert.AreEqual(2, m_extCtrls.Count); - loi = ReflectionHelper.GetResult(m_extender, "GetLocalizedComponentInfo", new object[] { lbl2, true }) as LocalizingInfo; + loi = ReflectionHelper.GetResult(m_extender, "GetLocalizedComponentInfo", new object[] { lbl2, true }) as LocalizingInfoWinforms; Assert.AreEqual(2, m_extCtrls.Count); Assert.AreEqual("apples", loi.Text); } diff --git a/src/L10NSharpTests/LocalizingInfoTests.cs b/src/L10NSharp.Windows.Forms.Tests/LocalizingInfoTests.cs similarity index 86% rename from src/L10NSharpTests/LocalizingInfoTests.cs rename to src/L10NSharp.Windows.Forms.Tests/LocalizingInfoTests.cs index fbf6050..7fe2f6f 100644 --- a/src/L10NSharpTests/LocalizingInfoTests.cs +++ b/src/L10NSharp.Windows.Forms.Tests/LocalizingInfoTests.cs @@ -1,7 +1,9 @@ using System.Windows.Forms; using NUnit.Framework; +using L10NSharp; +using L10NSharp.Windows.Forms; -namespace L10NSharp.Tests +namespace L10NSharp.Windows.Forms.Tests { [TestFixture] [Category("RequiresDisplay")] @@ -16,7 +18,7 @@ public class LocalizingInfoTests public void MakeIdTest_ForForm() { Form frm = new Form { Name = "hamster" }; - var loi = new LocalizingInfo(frm, true); + var loi = new LocalizingInfoWinforms(frm, true); Assert.AreEqual("hamster.WindowTitle", loi.Id); } @@ -33,7 +35,7 @@ public void MakeIdTest_ForControl() var btn = new Button { Name = "fox" }; frm.Controls.Add(btn); - var loi = new LocalizingInfo(btn, true); + var loi = new LocalizingInfoWinforms(btn, true); Assert.AreEqual("racoon.fox", loi.Id); var lbl = new Label { Name = "opossum" }; @@ -42,7 +44,7 @@ public void MakeIdTest_ForControl() pnl1.Controls.Add(pnl2); pnl2.Controls.Add(lbl); frm.Controls.Add(pnl1); - loi = new LocalizingInfo(lbl, true); + loi = new LocalizingInfoWinforms(lbl, true); Assert.AreEqual("racoon.opossum", loi.Id); } @@ -60,12 +62,12 @@ public void MakeIdTest_ForColumnHeader() var hdr = new ColumnHeader { Name = "monkey" }; lv.Columns.Add(hdr); - var loi = new LocalizingInfo(hdr, true); + var loi = new LocalizingInfoWinforms(hdr, true); Assert.AreEqual("fish.Colmonkey", loi.Id); var frm = new Form { Name = "wolf" }; frm.Controls.Add(lv); - loi = new LocalizingInfo(hdr, true); + loi = new LocalizingInfoWinforms(hdr, true); Assert.AreEqual("wolf.fishColmonkey", loi.Id); } @@ -83,13 +85,13 @@ public void MakeIdTest_ForDataGridViewColumn() var col = new DataGridViewTextBoxColumn { Name = "cheetah" }; grid.Columns.Add(col); - var loi = new LocalizingInfo(col, true); + var loi = new LocalizingInfoWinforms(col, true); Assert.AreEqual("hippo.Colcheetah", loi.Id); var frm = new Form { Name = "jackal" }; frm.Controls.Add(grid); - loi = new LocalizingInfo(col, true); + loi = new LocalizingInfoWinforms(col, true); Assert.AreEqual("jackal.hippoColcheetah", loi.Id); } } diff --git a/src/L10NSharpTests/MockLocalizableComponent.cs b/src/L10NSharp.Windows.Forms.Tests/MockLocalizableComponent.cs similarity index 85% rename from src/L10NSharpTests/MockLocalizableComponent.cs rename to src/L10NSharp.Windows.Forms.Tests/MockLocalizableComponent.cs index 55683da..c458127 100644 --- a/src/L10NSharpTests/MockLocalizableComponent.cs +++ b/src/L10NSharp.Windows.Forms.Tests/MockLocalizableComponent.cs @@ -2,9 +2,11 @@ using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; -using L10NSharp.UI; +using L10NSharp; +using L10NSharp.Windows.Forms; +using L10NSharp.Windows.Forms.UIComponents; -namespace L10NSharp.Tests +namespace L10NSharp.Windows.Forms.Tests { class MockLocalizableComponent: ILocalizableComponent, IComponent { @@ -48,15 +50,15 @@ public string GetLocalizedStringFromMock(Control control, string subId) /// Allows the MockLocalizableComponent to give L10NSharp the information it needs to put strings /// into the localization UI to be localized. /// - /// A list of LocalizingInfo objects - public IEnumerable GetAllLocalizingInfoObjects(L10NSharpExtender extender) + /// A list of LocalizingInfoWinforms objects + public IEnumerable GetAllLocalizingInfoObjects(L10NSharpExtender extender) { - var result = new List(); + var result = new List(); foreach (var kvp in StringContainer) { var control = kvp.Key.Item1; var id = extender.GetLocalizingId(control) + kvp.Key.Item2; - result.Add(new LocalizingInfo(control, id) { Text = kvp.Value, Category = LocalizationCategory.LocalizableComponent}); + result.Add(new LocalizingInfoWinforms(control, id) { Text = kvp.Value, Category = LocalizationCategory.LocalizableComponent}); } return result; } @@ -65,7 +67,7 @@ public IEnumerable GetAllLocalizingInfoObjects(L10NSharpExtender /// L10NSharp will call this for each localized string so that the component can set /// the correct value in the control. /// - /// The control that was returned via the LocalizingInfo in + /// The control that was returned via the LocalizingInfoWinforms in /// GetAllLocalizingInfoObjects(). Will be null if that value was null. /// a key into the ILocalizableComponent allowing it to know what /// string to localize diff --git a/src/L10NSharp.Windows.Forms.Tests/Properties/Resources.Designer.cs b/src/L10NSharp.Windows.Forms.Tests/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6d7c8e6 --- /dev/null +++ b/src/L10NSharp.Windows.Forms.Tests/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace L10NSharp.Windows.Forms.Tests.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("L10NSharp.WindowsFormsTests.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/src/L10NSharp.Windows.Forms.Tests/Properties/Resources.resx b/src/L10NSharp.Windows.Forms.Tests/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/src/L10NSharp.Windows.Forms.Tests/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/L10NSharpTests/ReflectionHelper.cs b/src/L10NSharp.Windows.Forms.Tests/ReflectionHelper.cs similarity index 99% rename from src/L10NSharpTests/ReflectionHelper.cs rename to src/L10NSharp.Windows.Forms.Tests/ReflectionHelper.cs index f398a7a..ec5ddf5 100644 --- a/src/L10NSharpTests/ReflectionHelper.cs +++ b/src/L10NSharp.Windows.Forms.Tests/ReflectionHelper.cs @@ -3,7 +3,7 @@ using System.IO; using System.Reflection; -namespace L10NSharp.Tests +namespace L10NSharp.Windows.Forms.Tests { public static class ReflectionHelper { diff --git a/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest.en.xlf b/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest.en.xlf new file mode 100644 index 0000000..049d6c4 --- /dev/null +++ b/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest.en.xlf @@ -0,0 +1,23 @@ + + + +
+ This is a test. This is only a test. + I'm not sure I agree with the previous note. +
+ + + It's a crow + + + It's not a crow + + + It's a chicken + + + Fish-eating bird + + +
+
diff --git a/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest.es.xlf b/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest.es.xlf new file mode 100644 index 0000000..7e1d09c --- /dev/null +++ b/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest.es.xlf @@ -0,0 +1,31 @@ + + + + + + The button will show up when you hold down the Ctrl and Shift keys together. + El botón se mostrará cuando se mantengan presionadas juntas las teclas Ctrl y Mayús. + + El botón se mostrará cuando juntamente se presiona las teclas Ctrl y Mayús. + + ID: SettingsProtection.CtrlShiftHint + + + Settings Protection... + Protección de configuraciones... + ID: SettingsProtection.LauncherButtonLabel + OLD TEXT (before 4.0): Settings... + + + Hide the button that opens settings. + Ocultar el botón que abre la configuración. + ID: SettingsProtection.NormallyHiddenCheckbox + + + Factory Password + Factory Password + ID: SettingsProtection.PasswordDialog.FactoryPassword + + + + diff --git a/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest.fr.xlf b/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest.fr.xlf new file mode 100644 index 0000000..3aab556 --- /dev/null +++ b/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest.fr.xlf @@ -0,0 +1,26 @@ + + + +
+ This file supposedly contains French translations. +
+ + + It's a crow + C'est un corbeau + + + It's not a crow + Ce n'est pas un corbeau + + + It's a chicken + C'est un poulet + + + Fish-eating bird + Un oiseau qui mange des poissons + + +
+
diff --git a/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest2.en.xlf b/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest2.en.xlf new file mode 100644 index 0000000..82652eb --- /dev/null +++ b/src/L10NSharp.Windows.Forms.Tests/TestXliff/LocalizableComponentTest2.en.xlf @@ -0,0 +1,40 @@ + + + + + + This is plain text. + + + This is bold. + + + This is italic. + + + This is superscript. + + + This is a link. + + + This has an embedded image: . + + + This is a paragraph. + + + This is a div. + + + This is a block quote. + + + This is in\npresentation\ndisplay. + + + This is more complex!! + + + + diff --git a/src/L10NSharpTests/UtilsTests.cs b/src/L10NSharp.Windows.Forms.Tests/UtilsTests.cs similarity index 62% rename from src/L10NSharpTests/UtilsTests.cs rename to src/L10NSharp.Windows.Forms.Tests/UtilsTests.cs index 481d933..a4273b2 100644 --- a/src/L10NSharpTests/UtilsTests.cs +++ b/src/L10NSharp.Windows.Forms.Tests/UtilsTests.cs @@ -1,8 +1,9 @@ using System; using System.Windows.Forms; using NUnit.Framework; +using L10NSharp; -namespace L10NSharp.Tests +namespace L10NSharp.Windows.Forms.Tests { [TestFixture] public class UtilsTests @@ -10,37 +11,37 @@ public class UtilsTests [Test] public void TypeDoesNotHaveUnexpectedProperty() { - Assert.IsFalse(UI.Utils.HasProperty(typeof(String), "nonsense")); + Assert.IsFalse(Utils.HasProperty(typeof(String), "nonsense")); } [Test] public void InstanceDoesNotHaveUnexpectedProperty() { - Assert.IsFalse(UI.Utils.HasProperty("", "nonsense")); + Assert.IsFalse(Utils.HasProperty("", "nonsense")); } [Test] public void InstanceHasExpectedProperty() { - Assert.IsTrue(UI.Utils.HasProperty("", "Length")); + Assert.IsTrue(Utils.HasProperty("", "Length")); } [Test] public void TypeHasExpectedProperty() { - Assert.IsTrue(UI.Utils.HasProperty(typeof(int), "MaxValue")); + Assert.IsTrue(Utils.HasProperty(typeof(int), "MaxValue")); } [Test] public void GetPropertyOnExistingMethod_Works() { - Assert.AreEqual(3, UI.Utils.GetProperty("abc", "Length")); + Assert.AreEqual(3, Utils.GetProperty("abc", "Length")); } [Test] public void GetPropertyOnMissingMethod_ReturnsNull() { - Assert.IsNull(UI.Utils.GetProperty("abc", "nonsence")); + Assert.IsNull(Utils.GetProperty("abc", "nonsence")); } /// @@ -50,7 +51,7 @@ public void GetPropertyOnMissingMethod_ReturnsNull() public void GetShortcutKeysOnToolStripButton_ReturnsNull() { var button = new ToolStripButton(); - Assert.IsNull(UI.Utils.GetProperty(button, "ShortcutKeys")); + Assert.IsNull(Utils.GetProperty(button, "ShortcutKeys")); } } } diff --git a/src/L10NSharp.Windows.Forms.Tests/XliffLocalizationManagerTests.cs b/src/L10NSharp.Windows.Forms.Tests/XliffLocalizationManagerTests.cs new file mode 100644 index 0000000..10b220c --- /dev/null +++ b/src/L10NSharp.Windows.Forms.Tests/XliffLocalizationManagerTests.cs @@ -0,0 +1,197 @@ +// Copyright © 2022-2025 SIL Global +// This software is licensed under the MIT License (http://opensource.org/licenses/MIT) +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using L10NSharp.XLiffUtils; +using L10NSharp.Windows.Forms.XLiffUtils; +using NUnit.Framework; + +namespace L10NSharp.Windows.Forms.Tests +{ + public class XliffLocalizationManagerTests + { + protected const string AppId = "test"; + protected const string AppName = "unit test"; + protected const string AppVersion = "1.0.0"; + protected const string HigherVersion = "2.0.0"; + protected const string LowerVersion = "0.0.1"; + protected const string LiteralNewline = "\\n"; + + internal ILocalizationManagerInternalWinforms CreateLocalizationManager( + string appId, string appName, string appVersion, string directoryOfInstalledLocFiles, + string directoryForGeneratedDefaultFile, string directoryOfUserModifiedXliffFiles, + IEnumerable additionalGetStringMethodInfo = null, + params string[] namespaceBeginnings) + { + var manager = new XliffLocalizationManagerWinforms(appId, null, appName, appVersion, directoryOfInstalledLocFiles, + directoryForGeneratedDefaultFile, directoryOfUserModifiedXliffFiles, additionalGetStringMethodInfo, + namespaceBeginnings); + Assert.That(manager.OriginalExecutableFile, Is.EqualTo(appId + ".dll")); + LocalizationManagerInternalWinforms.LoadedManagers.Add("myAppId", manager); + return manager; + } + + internal ILocalizationManagerInternalWinforms CreateLocalizationManager( + string appId, string appName, string appVersion) + { + return new XliffLocalizationManagerWinforms(appId, appName, appVersion); + } + + protected XLiffDocument CreateNewDocument(string productVersion, string sourceLang, + string targetLang = null, string otherAppVersion = null) + { + var doc = new XLiffDocument { File = { SourceLang = sourceLang } }; + if (!string.IsNullOrEmpty(productVersion)) + doc.File.ProductVersion = productVersion; + if (!string.IsNullOrEmpty(targetLang)) + doc.File.TargetLang = targetLang; + if (!string.IsNullOrEmpty(otherAppVersion)) + doc.File.SetPropValue(LocalizationManager.kAppVersionPropTag, otherAppVersion); + doc.File.HardLineBreakReplacement = LiteralNewline; + doc.File.Original = "test.dll"; + return doc; + } + + protected ITransUnit CreateTransUnit(string id, bool dynamic, + ITransUnitVariant sourceVariant, ITransUnitVariant targetVariant = null, + string noteText = null, TranslationStatus? translationStatus = null, bool? noLongerUsed = null) + { + var tu = new XLiffTransUnit + { + Id = id, + Source = (XLiffTransUnitVariant)sourceVariant, + Target = (XLiffTransUnitVariant)targetVariant + + }; + + if (dynamic) + tu.Dynamic = true; + + if (!string.IsNullOrEmpty(noteText)) + tu.Notes = new List { new XLiffNote { Text = noteText } }; + + if (translationStatus.HasValue) + tu.TranslationStatus = translationStatus.Value; + return tu; + } + + protected ITransUnitVariant CreateTransUnitVariant(string lang, string value) + { + return new XLiffTransUnitVariant { Lang = lang, Value = value }; + } + + [TearDown] + public void TearDownLocalizationManagers() + { + LocalizationManager.UseLanguageCodeFolders = false; + LocalizationManagerInternalWinforms.LoadedManagers.Clear(); + LocalizationManagerInternalWinforms.MapToExistingLanguage.Clear(); + LocalizationManagerWinforms.SetUILanguage(LocalizationManager.kDefaultLang, false); + } + + private void AddEnglishTranslation(string folderPath, string appVersion) + { + var englishDoc = CreateNewDocument(appVersion, "en"); + + // first unit + var tu = CreateTransUnit("theId", false, + CreateTransUnitVariant("en", "from English Translation"), + null, "Test"); + englishDoc.AddTransUnit(tu); + // second unit + var tu2 = CreateTransUnit("notUsedId", false, + CreateTransUnitVariant("en", "no longer used English text"), + noLongerUsed: true); + englishDoc.AddTransUnit(tu2); + // third unit + var tu3 = CreateTransUnit("blahId", false, + CreateTransUnitVariant("en", "blah")); + englishDoc.AddTransUnit(tu3); + englishDoc.Save(Path.Combine(folderPath, LocalizationManager.GetTranslationFileNameForLanguage(AppId, "en"))); + } + + private void AddChineseOfChinaTranslation(string folderPath) + { + var chineseDoc = CreateNewDocument(null, "en", "zh-CN"); + // first unit + var tu = CreateTransUnit("theId", false, + CreateTransUnitVariant("en", "from English Translation"), + CreateTransUnitVariant("zh-CN", "from Chinese (China) Translation"), + "Test", TranslationStatus.Approved); + chineseDoc.AddTransUnit(tu); + // second unit + var tu2 = CreateTransUnit("notUsedId", false, + CreateTransUnitVariant("en", "no longer used English text"), + CreateTransUnitVariant("zh-CN", "no longer used Chinese (China) text"), + null, TranslationStatus.Approved); + chineseDoc.AddTransUnit(tu2); + // third unit + var tu3 = CreateTransUnit("blahId", false, + CreateTransUnitVariant("en", "blah"), + CreateTransUnitVariant("zh-CN", "中文(中国) blah")); + chineseDoc.AddTransUnit(tu3); + chineseDoc.Save(Path.Combine(folderPath, LocalizationManager.GetTranslationFileNameForLanguage(AppId, "zh-CN"))); + } + + private void AddChineseOfTaiwanTranslation(string folderPath) + { + var chineseDoc = CreateNewDocument(null, "en", "zh-TW"); + // first unit + var tu = CreateTransUnit("theId", false, + CreateTransUnitVariant("en", "from English Translation"), + CreateTransUnitVariant("zh-TW", "from Chinese (Taiwan) Translation"), + "Test", TranslationStatus.Approved); + chineseDoc.AddTransUnit(tu); + // second unit + var tu2 = CreateTransUnit("notUsedId", false, + CreateTransUnitVariant("en", "no longer used English text"), + CreateTransUnitVariant("zh-TW", "no longer used Chinese (Taiwan) text"), + null, TranslationStatus.Approved); + chineseDoc.AddTransUnit(tu2); + // third unit + var tu3 = CreateTransUnit("blahId", false, + CreateTransUnitVariant("en", "blah"), + CreateTransUnitVariant("zh-TW", "中文(Taiwan) blah")); + chineseDoc.AddTransUnit(tu3); + chineseDoc.Save(Path.Combine(folderPath, LocalizationManager.GetTranslationFileNameForLanguage(AppId, "zh-TW"))); + } + + [Test] + public void TestMappingLanguageCodesToAvailable_AmbiguousOptions_PromptsUser([Values("zh-CN", "zh-TW")] string choice) + { + LocalizationManagerWinforms.SetUILanguage("en", true); + LocalizationManagerInternalWinforms.LoadedManagers.Clear(); + using (var folder = new L10NSharp.Tests.TempFolder()) + { + var installedFolder = Path.Combine(folder.Path, "installed"); + // ReSharper disable once AssignNullToNotNullAttribute + var userRelativeFolder = Path.Combine("Temp", Path.GetFileName(Path.GetDirectoryName(folder.Path)), + Path.GetFileName(folder.Path), "user"); + AddEnglishTranslation(installedFolder, null); + AddChineseOfChinaTranslation(installedFolder); + AddChineseOfTaiwanTranslation(installedFolder); + var userPromptCount = 0; + LocalizationManagerInternalWinforms.ChooseFallbackLanguageWinforms = (langTag, icon) => + { + userPromptCount++; + Assert.That(langTag, Is.EqualTo("zh")); + return choice; + }; + var manager = LocalizationManagerWinforms.Create("zh", AppId, AppName, AppVersion, installedFolder, + userRelativeFolder, null, null, new string[] { }); + Assert.That(userPromptCount, Is.EqualTo(1)); + LocalizationManagerInternal.LoadedManagers[AppId] = (ILocalizationManagerInternal)manager; + + var langs = LocalizationManager.GetAvailableLocalizedLanguages(); + Assert.That(langs, Is.EquivalentTo(new[] { "en", "zh-CN", "zh-TW" })); + Assert.That(LocalizationManager.UILanguageId, Is.EqualTo(choice)); + + Assert.That(LocalizationManager.GetIsStringAvailableForLangId("theId", "zh"), Is.False, "zh is ambiguous"); + Assert.That(LocalizationManager.GetIsStringAvailableForLangId("theId", "zh-CN"), Is.True, "zh-CN should find zh-CN"); + Assert.That(LocalizationManager.GetIsStringAvailableForLangId("theId", "zh-TW"), Is.True, "zh-TW should find zh-TW"); + Assert.That(LocalizationManager.GetIsStringAvailableForLangId("theId", "en"), Is.True, "en should find en"); + } + } + } +} diff --git a/src/L10NSharp/ILocalizableComponent.cs b/src/L10NSharp.Windows.Forms/ILocalizableComponent.cs similarity index 82% rename from src/L10NSharp/ILocalizableComponent.cs rename to src/L10NSharp.Windows.Forms/ILocalizableComponent.cs index 74234b7..3c83908 100644 --- a/src/L10NSharp/ILocalizableComponent.cs +++ b/src/L10NSharp.Windows.Forms/ILocalizableComponent.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; -using L10NSharp.UI; -namespace L10NSharp +namespace L10NSharp.Windows.Forms { /// /// This interface allows a control to be localized by L10NSharp. It can be used to enable @@ -13,14 +12,14 @@ public interface ILocalizableComponent /// Allows the container to give L10NSharp the information it needs to put strings /// into the localization UI to be localized. /// - /// A list of LocalizingInfo objects - IEnumerable GetAllLocalizingInfoObjects(L10NSharpExtender extender); + /// A list of LocalizingInfoWinforms objects + IEnumerable GetAllLocalizingInfoObjects(L10NSharpExtender extender); /// /// L10NSharp will call this for each localized string so that the component can set /// the correct value in the control. /// - /// The control that was returned via the LocalizingInfo in + /// The control that was returned via the LocalizingInfoWinforms in /// GetAllLocalizingInfoObjects(). Will be null if that value was null. /// a key into the ILocalizableComponent allowing it to know what /// string to localize diff --git a/src/L10NSharp.Windows.Forms/ILocalizationManagerInternalWinforms.cs b/src/L10NSharp.Windows.Forms/ILocalizationManagerInternalWinforms.cs new file mode 100644 index 0000000..b9a0d4e --- /dev/null +++ b/src/L10NSharp.Windows.Forms/ILocalizationManagerInternalWinforms.cs @@ -0,0 +1,33 @@ +// Copyright © 2019-2025 SIL Global +// This software is licensed under the MIT License (http://opensource.org/licenses/MIT) + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; + +namespace L10NSharp.Windows.Forms +{ + internal interface ILocalizationManagerInternalWinforms: ILocalizationManagerInternal + { + Dictionary ToolTipCtrls { get; } + Dictionary> LocalizableComponents { get; } + Icon ApplicationIcon { get; set; } + + void ApplyLocalization(IComponent component); + void ApplyLocalizationsToILocalizableComponent(LocalizingInfoWinforms locInfo); + void ReapplyLocalizationsToAllComponents(); + + void RegisterComponentForLocalizing(IComponent component, string id, string defaultText, + string defaultTooltip, string defaultShortcutKeys, string comment); + void RegisterComponentForLocalizing(LocalizingInfoWinforms info, + Action successAction); + + } + + internal interface ILocalizationManagerInternalWinforms : ILocalizationManagerInternalWinforms, ILocalizationManagerInternal + { + new ILocalizedStringCacheWinforms StringCache { get; } + } +} diff --git a/src/L10NSharp.Windows.Forms/ILocalizedStringCacheWinforms.cs b/src/L10NSharp.Windows.Forms/ILocalizedStringCacheWinforms.cs new file mode 100644 index 0000000..df54b51 --- /dev/null +++ b/src/L10NSharp.Windows.Forms/ILocalizedStringCacheWinforms.cs @@ -0,0 +1,16 @@ +// // Copyright © 2019-2025 SIL Global +// // This software is licensed under the MIT License (http://opensource.org/licenses/MIT) + +using System.Collections.Generic; +using System.Windows.Forms; +using L10NSharp.Windows.Forms.UIComponents; + +namespace L10NSharp.Windows.Forms +{ + internal interface ILocalizedStringCacheWinforms:L10NSharp.ILocalizedStringCache + { + List> LeafNodeList { get; } + Keys GetShortcutKeys(string langId, string id); + void LoadGroupNodes(TreeNodeCollection topCollection); + } +} diff --git a/src/L10NSharp/UI/L10NExtender.cs b/src/L10NSharp.Windows.Forms/L10NExtender.cs similarity index 94% rename from src/L10NSharp/UI/L10NExtender.cs rename to src/L10NSharp.Windows.Forms/L10NExtender.cs index bbdbd17..8ad9b1a 100644 --- a/src/L10NSharp/UI/L10NExtender.cs +++ b/src/L10NSharp.Windows.Forms/L10NExtender.cs @@ -22,7 +22,7 @@ using System.Linq; using System.Windows.Forms; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms { /// ---------------------------------------------------------------------------------------- [ProvideProperty("LocalizingId", typeof(IComponent))] @@ -37,8 +37,8 @@ public class L10NSharpExtender : Component, IExtenderProvider, ISupportInitializ // Required for Windows.Forms Class Composition Designer support private Container components = null; #pragma warning restore CS0414 - private Dictionary m_extendedCtrls; - private ILocalizationManagerInternal _manager; + private Dictionary m_extendedCtrls; + private ILocalizationManagerInternalWinforms _manager; private string _locManagerId; //private string _idPrefixForThisForm=""; private bool _okayToLocalizeControls = false; @@ -60,7 +60,7 @@ public L10NSharpExtender() // Required for Windows.Forms Class Composition Designer support components = new Container(); - m_extendedCtrls = new Dictionary(); + m_extendedCtrls = new Dictionary(); } #endregion @@ -78,7 +78,7 @@ public string LocalizationManagerId get { return _locManagerId; } set { - if (LocalizationManager.LoadedManagers == null) + if (LocalizationManagerWinforms.LoadedManagers == null) { return; } @@ -86,9 +86,9 @@ public string LocalizationManagerId Debug.Assert(ReallyDesignMode || value != null, "You need to enter the manager/package id for this L10NExtender"); _locManagerId = value; - if (value != null && !DesignMode && LocalizationManager.LoadedManagers.ContainsKey(_locManagerId)) + if (value != null && !DesignMode && LocalizationManagerWinforms.LoadedManagers.ContainsKey(_locManagerId)) { - _manager = LocalizationManager.LoadedManagers[_locManagerId]; + _manager = LocalizationManagerWinforms.LoadedManagers[_locManagerId]; LocalizeControls(); } } @@ -364,7 +364,7 @@ private void FinalizationForDataGridViewColumns() /// ------------------------------------------------------------------------------------ private void HandleGridColumnAdded(object sender, DataGridViewColumnEventArgs e) { - var locInfo = new LocalizingInfo(e.Column, true); + var locInfo = new LocalizingInfoWinforms(e.Column, true); _manager.RegisterComponentForLocalizing(locInfo, (lm, info) => lm.ApplyLocalization(info.Component)); } @@ -420,13 +420,13 @@ private void AddMultipleStrings(ILocalizableComponent locComponent) if (m_extendedCtrls == null) // no can do! (can happen during view setup) return; var lios = locComponent.GetAllLocalizingInfoObjects(this); - var idToLocInfo = new Dictionary(); - foreach (var localizingInfo in lios) + var idToLocInfo = new Dictionary(); + foreach (var localizingInfoWinforms in lios) { - if (string.IsNullOrEmpty(localizingInfo.Id)) + if (string.IsNullOrEmpty(localizingInfoWinforms.Id)) continue; - _manager.AddString(localizingInfo.Id, localizingInfo.Text, null, null, null); - idToLocInfo.Add(localizingInfo.Id, localizingInfo); + _manager.AddString(localizingInfoWinforms.Id, localizingInfoWinforms.Text, null, null, null); + idToLocInfo.Add(localizingInfoWinforms.Id, localizingInfoWinforms); } _manager.LocalizableComponents.Add(locComponent, idToLocInfo); } @@ -504,13 +504,13 @@ public void SetLocalizableToolTip(IComponent component, string tip) /// Gets the localized object info. for the specified component. /// /// ------------------------------------------------------------------------------------ - private LocalizingInfo GetLocalizedComponentInfo(IComponent component, bool initTextFromCompIfNewlyCreated) + private LocalizingInfoWinforms GetLocalizedComponentInfo(IComponent component, bool initTextFromCompIfNewlyCreated) { - LocalizingInfo loi; + LocalizingInfoWinforms loi; if (m_extendedCtrls.TryGetValue(component, out loi)) // && !string.IsNullOrEmpty(loi.Id) && loi.Priority != LocalizationPriority.NotLocalizable) return loi; - loi = new LocalizingInfo(component, initTextFromCompIfNewlyCreated); + loi = new LocalizingInfoWinforms(component, initTextFromCompIfNewlyCreated); m_extendedCtrls[component] = loi; return loi; } diff --git a/src/L10NSharp/UI/LanguageChoosingDialog.resx b/src/L10NSharp.Windows.Forms/L10NExtender.resx similarity index 100% rename from src/L10NSharp/UI/LanguageChoosingDialog.resx rename to src/L10NSharp.Windows.Forms/L10NExtender.resx diff --git a/src/L10NSharp.Windows.Forms/L10NSharp.Windows.Forms.csproj b/src/L10NSharp.Windows.Forms/L10NSharp.Windows.Forms.csproj new file mode 100644 index 0000000..42be91a --- /dev/null +++ b/src/L10NSharp.Windows.Forms/L10NSharp.Windows.Forms.csproj @@ -0,0 +1,96 @@ + + + L10NSharp.Windows.Forms + L10NSharp.Windows.Forms is a .NET localization library for Windows Forms applications. It collects strings which need localization when your application first runs and saves them in a XLIFF file. It can also dynamically collect strings at runtime. + L10NSharp.Windows.Forms + L10NSharp.Windows.Forms + True + + + + + + + + + + + + + + + + + + + + + Component + + + True + Settings.settings + True + + + UserControl + + + Component + + + Form + + + Form + + + Form + + + Component + + + Form + + + Form + + + Form + + + Form + + + Form + + + UserControl + + + UserControl + + + UserControl + + + Form + + + Component + + + Component + + + Component + + + + + Settings.Designer.cs + SettingsSingleFileGenerator + + + diff --git a/src/L10NSharp.Windows.Forms/LocalizationManagerInternalWinforms.cs b/src/L10NSharp.Windows.Forms/LocalizationManagerInternalWinforms.cs new file mode 100644 index 0000000..64a784f --- /dev/null +++ b/src/L10NSharp.Windows.Forms/LocalizationManagerInternalWinforms.cs @@ -0,0 +1,276 @@ +// Copyright © 2022-2025 SIL Global +// This software is licensed under the MIT License (http://opensource.org/licenses/MIT) + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows.Forms; +using L10NSharp.Windows.Forms.XLiffUtils; +using L10NSharp.Windows.Forms.UIComponents; +// ReSharper disable StaticMemberInGenericType - these static fields are parameter-independent + +namespace L10NSharp.Windows.Forms +{ + internal class LocalizationManagerInternalWinforms : LocalizationManagerInternal + { + + /// + /// Function to choose a fallback language during construction. Overridable by unit tests. + /// + internal static Func ChooseFallbackLanguageWinforms = (desiredUiLangId, icon) => + { + using (var dlg = new LanguageChoosingDialog(L10NCultureInfo.GetCultureInfo(desiredUiLangId), icon)) + { + dlg.ShowDialog(); + return dlg.SelectedLanguage; + } + }; + + #region Static methods for creating a LocalizationManagerInternal + private static ILocalizationManager Create(string desiredUiLangId, string appId, + string appName, string relativeSettingPathForLocalizationFolder, + Icon applicationIcon, Func> createMethod) + { + if (string.IsNullOrEmpty(relativeSettingPathForLocalizationFolder)) + relativeSettingPathForLocalizationFolder = appName; + else if (Path.IsPathRooted(relativeSettingPathForLocalizationFolder)) + throw new ArgumentException(@"Relative (non-rooted) path expected", nameof(relativeSettingPathForLocalizationFolder)); + + var directoryOfWritableTranslationFiles = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), + relativeSettingPathForLocalizationFolder, "localizations"); + + if (!LoadedManagers.TryGetValue(appId, out var lm)) + { + lm = createMethod(directoryOfWritableTranslationFiles); + + LoadedManagers[appId] = lm; + PreviouslyLoadedManagers.Remove(appId); + } + + if (lm is ILocalizationManagerInternalWinforms) + ((ILocalizationManagerInternalWinforms)lm).ApplicationIcon = applicationIcon; + + if (string.IsNullOrEmpty(desiredUiLangId)) + { + desiredUiLangId = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; + } + + if (!LocalizationManagerInternalWinforms.IsDesiredUiCultureAvailable(desiredUiLangId)) + { + desiredUiLangId = ChooseFallbackLanguageWinforms(desiredUiLangId, applicationIcon); + } + + LocalizationManagerWinforms.SetUILanguage(desiredUiLangId, false); + + L10NSharp.LocalizationManager.EnableClickingOnControlToBringUpLocalizationDialog = true; + + return lm; + } + /// ------------------------------------------------------------------------------------ + /// + /// Creates a new instance of a localization manager for the specified application id. + /// If a localization manager has already been created for the specified id, then + /// that is returned. + /// + /// The language code of the desired UI language. If + /// there are no translations for that ID, a message is displayed and the UI language + /// falls back to the default. + /// The application Id (e.g. 'Pa' for Phonology Assistant). + /// This should be a unique name that identifies the manager for an assembly or + /// application. May include an optional file extension, which will be stripped off but + /// used to correctly set the "original" attribute when persisting an XLIFF file. The + /// base portion must still be unique (i.e., it is not valid to create a LM for + /// "Blah.exe" and another for "Blah.dll"). + /// The application's name. This will appear to the user + /// in the localization dialog box as a parent item in the tree. + /// + /// The full folder path of the original Xliff files + /// installed with the application. + /// The path, relative to + /// %appdata%, where your application stores user settings (e.g., "SIL\SayMore"). + /// A folder named "localizations" will be created there. + /// + /// MethodInfo objects representing + /// additional methods that should be regarded as calls to get localizations. If the method + /// is named "Localize", the extractor will attempt to parse its signature as an extension + /// method with the parameters (this string s, string separateId="", string comment=""). + /// Otherwise, it will be treated like a L10nSharp GetString method if its signature + /// matches one of the following: (string stringId, string englishText), + /// (string stringId, string englishText, string comment), or + /// (string stringId, string englishText, string comment, string englishToolTipText, + /// string englishShortcutKey, IComponent component). + /// A list of namespace beginnings indicating + /// what types to scan for localized string calls. For example, to only scan + /// types found in Pa.exe and assuming all types in that assembly begin with + /// 'Pa', then this value would only contain the string 'Pa'. + /// ------------------------------------------------------------------------------------ + public static ILocalizationManager CreateXliff(string desiredUiLangId, string appId, + string appName, string appVersion, string directoryOfInstalledXliffFiles, + string relativeSettingPathForLocalizationFolder, + Icon applicationIcon, + IEnumerable additionalLocalizationMethods, + params string[] namespaceBeginnings) + { + if (string.IsNullOrWhiteSpace(appId)) + throw new ArgumentNullException(nameof(appId)); + var origExeExtension = Path.GetExtension(appId); + if (origExeExtension == string.Empty) + origExeExtension = ".dll"; + appId = Path.GetFileNameWithoutExtension(appId); + + return Create(desiredUiLangId, appId, appName, + relativeSettingPathForLocalizationFolder, applicationIcon, + directoryOfWritableXliffFiles => + (ILocalizationManagerInternalWinforms)new XliffLocalizationManagerWinforms(appId, origExeExtension, appName, + appVersion, directoryOfInstalledXliffFiles, + directoryOfWritableXliffFiles, directoryOfWritableXliffFiles, + additionalLocalizationMethods, + namespaceBeginnings)); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Creates a new instance of a localization manager for the specified application id. + /// If a localization manager has already been created for the specified id, then + /// that is returned. + /// + /// The language code of the desired UI language. If + /// there are no translations for that ID, a message is displayed and the UI language + /// falls back to the default. + /// The application Id (e.g. 'Pa' for Phonology Assistant). + /// This should be a unique name that identifies the manager for an assembly or + /// application. May include an optional file extension, which will be stripped off but + /// used to correctly set the "original" attribute when persisting an XLIFF file. The + /// base portion must still be unique (i.e., it is not valid to create a LM for + /// "Blah.exe" and another for "Blah.dll"). + /// The application's name. This will appear to the user + /// in the localization dialog box as a parent item in the tree. + /// + /// The full folder path of the original Xliff files + /// installed with the application. + /// The path, relative to + /// %appdata%, where your application stores user settings (e.g., "SIL\SayMore"). + /// A folder named "localizations" will be created there. + /// + /// MethodInfo objects representing + /// additional methods that should be regarded as calls to get localizations. If the method + /// is named "Localize", the extractor will attempt to parse its signature as an extension + /// method with the parameters (this string s, string separateId="", string comment=""). + /// Otherwise, it will be treated like a L10nSharp GetString method if its signature + /// matches one of the following: (string stringId, string englishText), + /// (string stringId, string englishText, string comment), or + /// (string stringId, string englishText, string comment, string englishToolTipText, + /// string englishShortcutKey, IComponent component). + /// A list of namespace beginnings indicating + /// what types to scan for localized string calls. For example, to only scan + /// types found in Pa.exe and assuming all types in that assembly begin with + /// 'Pa', then this value would only contain the string 'Pa'. + /// ------------------------------------------------------------------------------------ + public static ILocalizationManager CreateXliff(string desiredUiLangId, string appId, + string appName, string appVersion, string directoryOfInstalledXliffFiles, + string relativeSettingPathForLocalizationFolder, + IEnumerable additionalLocalizationMethods, + params string[] namespaceBeginnings) + { + if (string.IsNullOrWhiteSpace(appId)) + throw new ArgumentNullException(nameof(appId)); + var origExeExtension = Path.GetExtension(appId); + if (origExeExtension == string.Empty) + origExeExtension = ".dll"; + appId = Path.GetFileNameWithoutExtension(appId); + + return Create(desiredUiLangId, appId, appName, + relativeSettingPathForLocalizationFolder, + directoryOfWritableXliffFiles => + (ILocalizationManagerInternalWinforms)new XliffLocalizationManagerWinforms(appId, origExeExtension, appName, + appVersion, directoryOfInstalledXliffFiles, + directoryOfWritableXliffFiles, directoryOfWritableXliffFiles, + additionalLocalizationMethods, + namespaceBeginnings)); + } + + /// ------------------------------------------------------------------------------------ + internal static ILocalizationManagerInternalWinforms GetLocalizationManagerForComponentWinforms( + IComponent component) + { + return (ILocalizationManagerInternalWinforms)LoadedManagers.Values.FirstOrDefault(lm => lm.ComponentCache.ContainsKey(component)); + } + + /// ------------------------------------------------------------------------------------ + internal static ILocalizationManagerInternalWinforms GetLocalizationManagerForStringWinforms(string id) + { + return (ILocalizationManagerInternalWinforms)LoadedManagers.Values.FirstOrDefault( + lm => lm.StringCache.GetString(LocalizationManager.UILanguageId, id) != null); + } + + #endregion + + /// ------------------------------------------------------------------------------------ + /// + /// Reapplies the localizations to all objects in the localization manager's cache of + /// localized objects. + /// + /// ------------------------------------------------------------------------------------ + public static void ReapplyLocalizationsToAllObjectsInAllManagers() + { + if (LoadedManagers == null) + return; + + foreach (var lm in LoadedManagers.Values) + // ReapplyLocalizationsToAllComponents() is a no-op outside of Winforms. + // We only have something to do if lm is Winforms. + if(lm is ILocalizationManagerInternalWinforms) + ((ILocalizationManagerInternalWinforms)lm).ReapplyLocalizationsToAllComponents(); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Reapplies the localizations to all objects in the localization manager's cache of + /// localized objects. + /// + /// ------------------------------------------------------------------------------------ + public static void ReapplyLocalizationsToAllObjects(string localizationManagerId) + { + if (LoadedManagers == null) + return; + + if (LoadedManagers.TryGetValue(localizationManagerId, out var lm)) + // ReapplyLocalizationsToAllComponents() is a no-op outside of Winforms. + // We only have something to do if lm is Winforms. + if (lm is ILocalizationManagerInternalWinforms) + ((ILocalizationManagerInternalWinforms)lm).ReapplyLocalizationsToAllComponents(); + } + + /// ------------------------------------------------------------------------------------ + public static string GetLocalizedToolTipForControl(Control ctrl) + { + var lm = LocalizationManagerInternalWinforms.GetLocalizationManagerForComponentWinforms(ctrl); + var topCtrl = GetRealTopLevelControl(ctrl); + if (topCtrl == null || lm == null) + return null; + + return lm.ToolTipCtrls.TryGetValue(topCtrl, out var ttctrl) ? ttctrl.GetToolTip(ctrl) + : null; + } + + /// ------------------------------------------------------------------------------------ + /// + /// Gets the real top level control (using the control's TopLevelControl property + /// seems to return null until the control is on a form). + /// + /// ------------------------------------------------------------------------------------ + internal static Control GetRealTopLevelControl(Control ctrl) + { + var parentControl = ctrl; + while (parentControl.Parent != null) + parentControl = parentControl.Parent; + + return parentControl; + } + } +} diff --git a/src/L10NSharp.Windows.Forms/LocalizationManagerWinforms.cs b/src/L10NSharp.Windows.Forms/LocalizationManagerWinforms.cs new file mode 100644 index 0000000..397f9e3 --- /dev/null +++ b/src/L10NSharp.Windows.Forms/LocalizationManagerWinforms.cs @@ -0,0 +1,200 @@ +// Copyright © 2022-2025 SIL Global +// This software is licensed under the MIT License (http://opensource.org/licenses/MIT) + +using System.Collections.Generic; +using System.Windows.Forms; +using L10NSharp.XLiffUtils; +using L10NSharp; +using System.Reflection; +using System.Drawing; + +namespace L10NSharp.Windows.Forms +{ + public class LocalizationManagerWinforms : LocalizationManager + { + /// ------------------------------------------------------------------------------------ + /// + /// Creates a new instance of a localization manager for the specified application id. + /// If a localization manager has already been created for the specified id, then + /// that is returned. + /// + /// The language code of the desired UI language. If + /// there are no translations for that ID, a message is displayed and the UI language + /// falls back to the default. + /// The application Id (e.g. 'Pa' for Phonology Assistant). + /// This should be a unique name that identifies the manager for an assembly or + /// application. May include an optional file extension, which will be stripped off but + /// used to correctly set the "original" attribute when persisting an XLIFF file. The + /// base portion must still be unique (i.e., it is not valid to create a LM for + /// "Blah.exe" and another for "Blah.dll"). + /// The application's name. This will appear to the user + /// in the localization dialog box as a parent item in the tree. + /// + /// The full folder path of the original l10n + /// files installed with the application. + /// The path, relative to + /// %localappdata%, where your application stores user settings (e.g., "SIL\SayMore"). + /// A folder named "localizations" will be created there. + /// + /// This will be used in UI that helps the translator + /// know what to do with their work + /// A list of namespace beginnings indicating + /// what types to scan for localized string calls. For example, to only scan + /// types found in Pa.exe and assuming all types in that assembly begin with + /// 'Pa', then this value would only contain the string 'Pa'. + /// MethodInfo objects representing + /// additional methods that should be regarded as calls to get localizations. If the method + /// is named "Localize", the extractor will attempt to parse its signature as an extension + /// method with the parameters (this string s, string separateId="", string comment=""). + /// Otherwise, it will be treated like a L10nSharp GetString method if its signature + /// matches one of the following: (string stringId, string englishText), + /// (string stringId, string englishText, string comment), or + /// (string stringId, string englishText, string comment, string englishToolTipText, + /// string englishShortcutKey, IComponent component). + /// ------------------------------------------------------------------------------------ + public static ILocalizationManager Create(string desiredUiLangId, + string appId, string appName, string appVersion, string directoryOfInstalledFiles, + string relativeSettingPathForLocalizationFolder, + Icon applicationIcon, string emailForSubmissions, + string[] namespaceBeginnings, + IEnumerable additionalLocalizationMethods = null) + { + LocalizationManager.TranslationMemoryKind = TranslationMemory.XLiff; + LocalizationManager.EmailForSubmissions = emailForSubmissions; + return LocalizationManagerInternalWinforms.CreateXliff(desiredUiLangId, + appId, appName, appVersion, directoryOfInstalledFiles, + relativeSettingPathForLocalizationFolder, applicationIcon, + additionalLocalizationMethods, + namespaceBeginnings); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Creates a new instance of a localization manager for the specified application id. + /// If a localization manager has already been created for the specified id, then + /// that is returned. + /// + /// The language code of the desired UI language. If + /// there are no translations for that ID, a message is displayed and the UI language + /// falls back to the default. + /// The application Id (e.g. 'Pa' for Phonology Assistant). + /// This should be a unique name that identifies the manager for an assembly or + /// application. May include an optional file extension, which will be stripped off but + /// used to correctly set the "original" attribute when persisting an XLIFF file. The + /// base portion must still be unique (i.e., it is not valid to create a LM for + /// "Blah.exe" and another for "Blah.dll"). + /// The application's name. This will appear to the user + /// in the localization dialog box as a parent item in the tree. + /// + /// The full folder path of the original l10n + /// files installed with the application. + /// The path, relative to + /// %localappdata%, where your application stores user settings (e.g., "SIL\SayMore"). + /// A folder named "localizations" will be created there. + /// This will be used in UI that helps the translator + /// know what to do with their work + /// A list of namespace beginnings indicating + /// what types to scan for localized string calls. For example, to only scan + /// types found in Pa.exe and assuming all types in that assembly begin with + /// 'Pa', then this value would only contain the string 'Pa'. + /// MethodInfo objects representing + /// additional methods that should be regarded as calls to get localizations. If the method + /// is named "Localize", the extractor will attempt to parse its signature as an extension + /// method with the parameters (this string s, string separateId="", string comment=""). + /// Otherwise, it will be treated like a L10nSharp GetString method if its signature + /// matches one of the following: (string stringId, string englishText), + /// (string stringId, string englishText, string comment), or + /// (string stringId, string englishText, string comment, string englishToolTipText, + /// string englishShortcutKey, IComponent component). + public new static ILocalizationManager Create(string desiredUiLangId, + string appId, string appName, string appVersion, string directoryOfInstalledFiles, + string relativeSettingPathForLocalizationFolder, + string emailForSubmissions, + string[] namespaceBeginnings, + IEnumerable additionalLocalizationMethods = null) + { + LocalizationManager.TranslationMemoryKind = TranslationMemory.XLiff; + LocalizationManager.EmailForSubmissions = emailForSubmissions; + return LocalizationManagerInternalWinforms.CreateXliff(desiredUiLangId, + appId, appName, appVersion, directoryOfInstalledFiles, + relativeSettingPathForLocalizationFolder, null, + additionalLocalizationMethods, + namespaceBeginnings); + } + public static void SetUILanguage(string langId, + bool reapplyLocalizationsToAllObjectsInAllManagers) + { + SetUILanguage(langId); + + if (reapplyLocalizationsToAllObjectsInAllManagers) + ReapplyLocalizationsToAllObjectsInAllManagers(); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Reapplies the localizations to all objects in the localization manager's cache of + /// localized objects. + /// + /// ------------------------------------------------------------------------------------ + public static void ReapplyLocalizationsToAllObjectsInAllManagers() + { + switch (TranslationMemoryKind) + { + default: + case TranslationMemory.XLiff: + LocalizationManagerInternalWinforms.ReapplyLocalizationsToAllObjectsInAllManagers(); + break; + } + } + + /// ------------------------------------------------------------------------------------ + /// + /// Reapplies the localizations to all objects in the localization manager's cache of + /// localized objects. + /// + /// ------------------------------------------------------------------------------------ + public static void ReapplyLocalizationsToAllObjects(string localizationManagerId) + { + switch (TranslationMemoryKind) + { + default: + case TranslationMemory.XLiff: + LocalizationManagerInternalWinforms.ReapplyLocalizationsToAllObjects(localizationManagerId); + break; + } + } + + public static string GetLocalizedToolTipForControl(Control ctrl) + { + switch (LocalizationManager.TranslationMemoryKind) + { + default: + case TranslationMemory.XLiff: + return LocalizationManagerInternalWinforms.GetLocalizedToolTipForControl(ctrl); + } + } + + /// ------------------------------------------------------------------------------------ + internal new static Dictionary LoadedManagers + { + get + { + switch (LocalizationManager.TranslationMemoryKind) + { + default: + case TranslationMemory.XLiff: + { + var loadedManagers = new Dictionary(); + foreach (var keyValuePair in LocalizationManagerInternalWinforms.LoadedManagers) + { + if(keyValuePair.Value is ILocalizationManagerInternalWinforms) + loadedManagers.Add(keyValuePair.Key, (ILocalizationManagerInternalWinforms)keyValuePair.Value); + } + + return loadedManagers; + } + } + } + } + } +} diff --git a/src/L10NSharp.Windows.Forms/LocalizingInfoWinforms.cs b/src/L10NSharp.Windows.Forms/LocalizingInfoWinforms.cs new file mode 100644 index 0000000..3c866c6 --- /dev/null +++ b/src/L10NSharp.Windows.Forms/LocalizingInfoWinforms.cs @@ -0,0 +1,324 @@ +using System.ComponentModel; +using System.Windows.Forms; +using L10NSharp.Windows.Forms.UIComponents; + +namespace L10NSharp.Windows.Forms +{ + /// ---------------------------------------------------------------------------------------- + /// + /// This class extends LocalizingInfo and is used to determine and track localization information + /// (i.e. extended properties of the LocalizationExtender) that depends on the specific type of + /// Windows forms object being extended. It is used to get a component's ID, localization category, + /// or shortcut keys. + /// + /// ---------------------------------------------------------------------------------------- + public class LocalizingInfoWinforms : LocalizingInfo + { + #region Constructors + /// ------------------------------------------------------------------------------------ + /// + /// Initializes a new instance of the class. + /// + /// ------------------------------------------------------------------------------------ + public LocalizingInfoWinforms(IComponent component, bool initTextFromObj) : base(component, initTextFromObj) + { + Category = GetCategory(_component); + if (initTextFromObj) + UpdateTextFromObject(); + } + + public void UpdateTextFromObject() + { + Text = LocalizationManager.StripOffLocalizationInfoFromText(_component is DataGridViewColumn + ? ((DataGridViewColumn) _component).HeaderText + : Utils.GetProperty(_component, "Text") as string); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Initializes a new instance of the class. + /// + /// ------------------------------------------------------------------------------------ + public LocalizingInfoWinforms(IComponent component, string id) : base(component, id) + { + } + + /// ------------------------------------------------------------------------------------ + /// + /// Initializes a new instance of the class. + /// + /// ------------------------------------------------------------------------------------ + public LocalizingInfoWinforms(string id) : base(id) + { + } + + #endregion + + #region Methods for initializing the localization id. + + internal void CreateIdIfMissing(string prefixForId) + { + if (prefixForId == null) + prefixForId = ""; + if (string.IsNullOrEmpty(_id)) + _id = MakeId(_component, idPrefixFromFormExtender: prefixForId); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Sets the id. + /// + /// ------------------------------------------------------------------------------------ + internal static string MakeId(IComponent component, string idPrefixFromFormExtender = "") + { + if (idPrefixFromFormExtender == null) + idPrefixFromFormExtender = ""; + + idPrefixFromFormExtender = idPrefixFromFormExtender.Trim('.', ' '); + if (idPrefixFromFormExtender.Length > 0) + idPrefixFromFormExtender = idPrefixFromFormExtender + "."; + + if (component is Form) + { + Form frm = (Form)component; + return (frm.Site != null && frm.Site.DesignMode ? frm.Site.Name : frm.Name) + ".WindowTitle"; + } + + if (component is Control) + return idPrefixFromFormExtender+MakeIdForCtrl(component as Control); + + if (component is ColumnHeader) + return idPrefixFromFormExtender + MakeIdForColumnHeader((ColumnHeader)component); + + if (component is DataGridViewColumn) + return idPrefixFromFormExtender + MakeIdForDataGridViewColumn((DataGridViewColumn)component); + + if (component is ToolStripItem) + { + string formName = OwningFormName(component as ToolStripItem); + return idPrefixFromFormExtender + (formName ?? "Miscellaneous") + "." + ((ToolStripItem)component).Name; + } + + return null; + } + + /// ------------------------------------------------------------------------------------ + /// + /// Sets the id for CTRL. + /// + /// ------------------------------------------------------------------------------------ + private static string MakeIdForCtrl(Control ctrl) + { + if (ctrl == null) + return null; + + if (ctrl.Text.StartsWith(LocalizationManager.kL10NPrefix)) + return GetIdFromText(ctrl.Text); + + string prefix = GetIdPrefix(ctrl); + if (string.IsNullOrEmpty(prefix)) + return ctrl.Name; + + //return (string.IsNullOrEmpty(prefix) ? string.Empty : prefix + "." + ctrl.Name); + return prefix.Trim(new char[] { '.' }) + "." + ctrl.Name.Trim(new char[] { '.' }); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Makes an id for a column header. + /// + /// ------------------------------------------------------------------------------------ + private static string MakeIdForColumnHeader(ColumnHeader hdr) + { + return (hdr == null ? null : GetIdFromText(hdr.Name)); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Makes an id for a DataGridView column. + /// Note that in order to have a DataGridViewColumn header be localizable, one must create the HeaderText + /// in the following format: _L10N_:{ID}!{EnglishName} + /// + /// ------------------------------------------------------------------------------------ + private static string MakeIdForDataGridViewColumn(DataGridViewColumn col) + { + return (col == null || !col.HeaderText.StartsWith(LocalizationManager.kL10NPrefix) ? + null : GetIdFromText(col.HeaderText)); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Tries to get the name of the form that hosts the specified control. That name is + /// used as the prefix for a localization id. + /// + /// ------------------------------------------------------------------------------------ + private static string GetIdPrefix(Control control) + { + if (control == null) + return "Miscellaneous"; + if (control.Parent == null) + return ""; + + while (control.Parent != null && + !control.Parent.GetType().FullName.StartsWith("System.Windows.Forms.Design")) + { + control = control.Parent; + } + + + return (control.Site != null && control.Site.DesignMode ? control.Site.Name : control.Name); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Gets the name of the form to which the specified ToolStripItem belongs. + /// + /// ------------------------------------------------------------------------------------ + private static string OwningFormName(ToolStripItem tsItem) + { + if (tsItem != null) + { + var item = tsItem; + while (item.OwnerItem != null) + item = item.OwnerItem; + + if (item.Owner != null) + { + var frm = item.Owner.FindForm(); + if (frm != null) + return (frm.Site != null && frm.Site.DesignMode ? frm.Site.Name : frm.Name); + } + } + + return string.Empty; + } + + #endregion + + #region Method for initializing the category + /// ------------------------------------------------------------------------------------ + /// + /// Returns the localization category for the specified IComponent object. + /// + /// ------------------------------------------------------------------------------------ + private static LocalizationCategory GetCategory(IComponent component) + { + if (component is ILocalizableComponent) + return LocalizationCategory.LocalizableComponent; + if (component is ToolStripMenuItem) + return LocalizationCategory.MenuItem; + if (component is ToolStripItem) + return LocalizationCategory.ToolbarOrStatusBarItem; + if (component is Button) + return LocalizationCategory.Button; + if (component is TextBox) + return LocalizationCategory.TextBox; + if (component is LinkLabel) + return LocalizationCategory.LinkLabel; + if (component is Label) + return LocalizationCategory.Label; + if (component is ComboBox) + return LocalizationCategory.ComboBox; + if (component is RadioButton) + return LocalizationCategory.RadioButton; + if (component is CheckBox) + return LocalizationCategory.CheckBox; + if (component is Form) + return LocalizationCategory.WindowOrDialog; + if (component is TabPage) + return LocalizationCategory.TabPage; + if (component is ColumnHeader) + return LocalizationCategory.ListViewColumnHeading; + if (component is DataGridViewColumn) + return LocalizationCategory.ListViewColumnHeading; + + return LocalizationCategory.Other; + } + + #endregion + + #region Properties + /// ------------------------------------------------------------------------------------ + public new bool IsEmpty + { + get + { + return + ((_text ?? string.Empty).Trim() == string.Empty && + (ToolTipText ?? string.Empty).Trim() == string.Empty && + (_shortcutKeys ?? string.Empty).Trim() == string.Empty && + (_comment ?? string.Empty).Trim() == string.Empty); + } + } + + /// ------------------------------------------------------------------------------------ + /// + /// Gets or sets the id. + /// + /// ------------------------------------------------------------------------------------ + public new string Id + { + get + { + if (string.IsNullOrEmpty(_id)) + _id = MakeId(_component); + + return _id; + } + set + { + _id = value; + if (string.IsNullOrEmpty(_id)) + { + Priority = LocalizationPriority.NotLocalizable; + } + else + { + _id = _id.Trim().Replace("..", ".");//it happens... + } + } + } + + /// ------------------------------------------------------------------------------------ + /// + /// Gets the component. + /// + /// ------------------------------------------------------------------------------------ + internal new IComponent Component + { + get { return _component; } + set + { + _component = value; + if (_component != null && string.IsNullOrEmpty(_id)) + Id = MakeId(_component); + } + } + + /// ------------------------------------------------------------------------------------ + /// + /// Gets or sets the shortcutKeys. + /// + /// ------------------------------------------------------------------------------------ + public new string ShortcutKeys + { + get + { + if (_shortcutKeys == null && _component != null) + { + object keysobj = Utils.GetProperty(_component, "ShortcutKeys"); + if (keysobj != null && keysobj.GetType() == typeof(Keys)) + { + Keys keys = (Keys)keysobj; + _shortcutKeys = (keys == Keys.None ? + string.Empty : ShortcutKeysEditor.KeysToString(keys)); + } + } + + return _shortcutKeys; + } + set { _shortcutKeys = (value == Keys.None.ToString() ? string.Empty : value); } + } + #endregion + } +} diff --git a/src/L10NSharp.Windows.Forms/Properties/AssemblyInfo.cs b/src/L10NSharp.Windows.Forms/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..707e25e --- /dev/null +++ b/src/L10NSharp.Windows.Forms/Properties/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Runtime.CompilerServices; + +// to get the public key, run: +// 1. extract the public key from the keyfile with +// sn –p +// 2. show the public key with +// sn -tp +// (use the full public key, not the public key token!) + +[assembly: InternalsVisibleTo("L10NSharp.Windows.Forms.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010019cae48c6e5703818db31fcca17b87012eef38df95e3961c59b035190eace2c4ee5cfa1a258b84867c7549f60eec00ec1e0004c2ed224457128e841311cea0f5a05c3d69b3dfcb7422b214febce6e06c83ce4d29c62f36a7fd5564e922338c800372a5ec09638671b4db1fb33ccbb1dc48d8122ffe0d30dadbfbf325f65437b2")] diff --git a/src/L10NSharp.Windows.Forms/Properties/Resources.Designer.cs b/src/L10NSharp.Windows.Forms/Properties/Resources.Designer.cs new file mode 100644 index 0000000..49026aa --- /dev/null +++ b/src/L10NSharp.Windows.Forms/Properties/Resources.Designer.cs @@ -0,0 +1,163 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace L10NSharp.Windows.Forms.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("L10NSharp.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap kimidBing { + get { + object obj = ResourceManager.GetObject("kimidBing", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap kimidCopyTranslation { + get { + object obj = ResourceManager.GetObject("kimidCopyTranslation", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap kimidCopyTranslationBig { + get { + object obj = ResourceManager.GetObject("kimidCopyTranslationBig", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap kimidGoogle { + get { + object obj = ResourceManager.GetObject("kimidGoogle", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap kimidMoveNext { + get { + object obj = ResourceManager.GetObject("kimidMoveNext", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap kimidMovePrevious { + get { + object obj = ResourceManager.GetObject("kimidMovePrevious", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Move { + get { + object obj = ResourceManager.GetObject("Move", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Move_down { + get { + object obj = ResourceManager.GetObject("Move_down", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Move_up { + get { + object obj = ResourceManager.GetObject("Move_up", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap SelectAllRows { + get { + object obj = ResourceManager.GetObject("SelectAllRows", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/src/L10NSharp/Properties/Settings.Designer.cs b/src/L10NSharp.Windows.Forms/Properties/Settings.Designer.cs similarity index 96% rename from src/L10NSharp/Properties/Settings.Designer.cs rename to src/L10NSharp.Windows.Forms/Properties/Settings.Designer.cs index 7c82023..98bcecc 100644 --- a/src/L10NSharp/Properties/Settings.Designer.cs +++ b/src/L10NSharp.Windows.Forms/Properties/Settings.Designer.cs @@ -8,11 +8,11 @@ // //------------------------------------------------------------------------------ -namespace L10NSharp.Properties { +namespace L10NSharp.Windows.Forms.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.12.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/src/L10NSharp/Properties/Settings.settings b/src/L10NSharp.Windows.Forms/Properties/Settings.settings similarity index 100% rename from src/L10NSharp/Properties/Settings.settings rename to src/L10NSharp.Windows.Forms/Properties/Settings.settings diff --git a/src/L10NSharp/UI/ColorHelper.cs b/src/L10NSharp.Windows.Forms/UIComponents/ColorHelper.cs similarity index 98% rename from src/L10NSharp/UI/ColorHelper.cs rename to src/L10NSharp.Windows.Forms/UIComponents/ColorHelper.cs index 4574a23..2d82c86 100644 --- a/src/L10NSharp/UI/ColorHelper.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/ColorHelper.cs @@ -1,6 +1,6 @@ using System.Drawing; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { internal static class ColorHelper { diff --git a/src/L10NSharp/UI/CustomDropDownComboBox.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/CustomDropDownComboBox.Designer.cs similarity index 98% rename from src/L10NSharp/UI/CustomDropDownComboBox.Designer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/CustomDropDownComboBox.Designer.cs index e05f9b4..3ee2bc0 100644 --- a/src/L10NSharp/UI/CustomDropDownComboBox.Designer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/CustomDropDownComboBox.Designer.cs @@ -1,4 +1,4 @@ -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { partial class CustomDropDownComboBox { diff --git a/src/L10NSharp/UI/CustomDropDownComboBox.cs b/src/L10NSharp.Windows.Forms/UIComponents/CustomDropDownComboBox.cs similarity index 99% rename from src/L10NSharp/UI/CustomDropDownComboBox.cs rename to src/L10NSharp.Windows.Forms/UIComponents/CustomDropDownComboBox.cs index d2136f3..dc6c5fb 100644 --- a/src/L10NSharp/UI/CustomDropDownComboBox.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/CustomDropDownComboBox.cs @@ -3,7 +3,7 @@ using System.Windows.Forms; using System.Windows.Forms.VisualStyles; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- internal partial class CustomDropDownComboBox : UserControl diff --git a/src/L10NSharp/UI/CustomDropDownComboBox.resx b/src/L10NSharp.Windows.Forms/UIComponents/CustomDropDownComboBox.resx similarity index 100% rename from src/L10NSharp/UI/CustomDropDownComboBox.resx rename to src/L10NSharp.Windows.Forms/UIComponents/CustomDropDownComboBox.resx diff --git a/src/L10NSharp/UI/DontShowThisAgainButton.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.Designer.cs similarity index 95% rename from src/L10NSharp/UI/DontShowThisAgainButton.Designer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.Designer.cs index b0e82d6..5563c81 100644 --- a/src/L10NSharp/UI/DontShowThisAgainButton.Designer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.Designer.cs @@ -1,4 +1,4 @@ -namespace L10NSharp +namespace L10NSharp.Windows.Forms.UIComponents { partial class DontShowThisAgainButton { diff --git a/src/L10NSharp/UI/DontShowThisAgainButton.cs b/src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.cs similarity index 98% rename from src/L10NSharp/UI/DontShowThisAgainButton.cs rename to src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.cs index a027399..bb47056 100644 --- a/src/L10NSharp/UI/DontShowThisAgainButton.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.cs @@ -7,7 +7,7 @@ using System.Windows.Forms; using L10NSharp.Properties; -namespace L10NSharp +namespace L10NSharp.Windows.Forms.UIComponents { public partial class DontShowThisAgainButton : CheckBox { diff --git a/src/L10NSharp/UI/EditSourceBeforeTranslatingDlg.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.Designer.cs similarity index 99% rename from src/L10NSharp/UI/EditSourceBeforeTranslatingDlg.Designer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.Designer.cs index 624a8f5..8c5432e 100644 --- a/src/L10NSharp/UI/EditSourceBeforeTranslatingDlg.Designer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.Designer.cs @@ -1,4 +1,4 @@ -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { partial class EditSourceBeforeTranslatingDlg { @@ -206,4 +206,4 @@ private void InitializeComponent() private System.Windows.Forms.Label _labelDescription; private System.Windows.Forms.Button _buttonCopyAndClose; } -} \ No newline at end of file +} diff --git a/src/L10NSharp/UI/EditSourceBeforeTranslatingDlg.cs b/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.cs similarity index 97% rename from src/L10NSharp/UI/EditSourceBeforeTranslatingDlg.cs rename to src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.cs index 243aadf..ef047a3 100644 --- a/src/L10NSharp/UI/EditSourceBeforeTranslatingDlg.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.cs @@ -4,7 +4,7 @@ using System.Windows.Forms; using L10NSharp.Translators; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { public partial class EditSourceBeforeTranslatingDlg : Form { diff --git a/src/L10NSharp/UI/EditSourceBeforeTranslatingDlg.resx b/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.resx similarity index 100% rename from src/L10NSharp/UI/EditSourceBeforeTranslatingDlg.resx rename to src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.resx diff --git a/src/L10NSharp/UI/FallbackLanguagesDlg.cs b/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlg.cs similarity index 93% rename from src/L10NSharp/UI/FallbackLanguagesDlg.cs rename to src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlg.cs index 1deca74..8a6692c 100644 --- a/src/L10NSharp/UI/FallbackLanguagesDlg.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlg.cs @@ -5,8 +5,9 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using L10NSharp; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { public class FallbackLanguagesDlg : FallbackLanguagesDlgBase { diff --git a/src/L10NSharp/UI/FallbackLanguagesDlgBase.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.Designer.cs similarity index 98% rename from src/L10NSharp/UI/FallbackLanguagesDlgBase.Designer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.Designer.cs index 8f1dcc7..d07a0c5 100644 --- a/src/L10NSharp/UI/FallbackLanguagesDlgBase.Designer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.Designer.cs @@ -1,4 +1,4 @@ -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { partial class FallbackLanguagesDlgBase { @@ -112,7 +112,7 @@ private void InitializeComponent() // // _buttonAdd // - this._buttonAdd.Image = global::L10NSharp.Properties.Resources.Move; + this._buttonAdd.Image = global::L10NSharp.Properties.Resources.Move; this._buttonAdd.ImageAlign = System.Drawing.ContentAlignment.MiddleRight; this._buttonAdd.Location = new System.Drawing.Point(188, 123); this._buttonAdd.Name = "_buttonAdd"; diff --git a/src/L10NSharp/UI/FallbackLanguagesDlgBase.cs b/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.cs similarity index 98% rename from src/L10NSharp/UI/FallbackLanguagesDlgBase.cs rename to src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.cs index 9cf9bc0..4f65c39 100644 --- a/src/L10NSharp/UI/FallbackLanguagesDlgBase.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.cs @@ -3,8 +3,9 @@ using System.Linq; using System.Globalization; using System.Windows.Forms; +using L10NSharp; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ------------------------------------------------------------------------------------ public partial class FallbackLanguagesDlgBase : Form diff --git a/src/L10NSharp/UI/FallbackLanguagesDlgBase.resx b/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.resx similarity index 100% rename from src/L10NSharp/UI/FallbackLanguagesDlgBase.resx rename to src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.resx diff --git a/src/L10NSharp/UI/Grid/LmButtonCell.cs b/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonCell.cs similarity index 99% rename from src/L10NSharp/UI/Grid/LmButtonCell.cs rename to src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonCell.cs index d277a8a..6cff553 100644 --- a/src/L10NSharp/UI/Grid/LmButtonCell.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonCell.cs @@ -3,7 +3,7 @@ using System.Windows.Forms; using System.Windows.Forms.VisualStyles; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { #region LmButtonCell class /// ---------------------------------------------------------------------------------------- diff --git a/src/L10NSharp/UI/Grid/LmButtonColumn.cs b/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonColumn.cs similarity index 99% rename from src/L10NSharp/UI/Grid/LmButtonColumn.cs rename to src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonColumn.cs index d70374a..d716b1a 100644 --- a/src/L10NSharp/UI/Grid/LmButtonColumn.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonColumn.cs @@ -2,7 +2,7 @@ using System.Drawing; using System.Windows.Forms; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- public class LmButtonColumn : DataGridViewColumn diff --git a/src/L10NSharp/UI/Grid/LmGrid.cs b/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmGrid.cs similarity index 99% rename from src/L10NSharp/UI/Grid/LmGrid.cs rename to src/L10NSharp.Windows.Forms/UIComponents/Grid/LmGrid.cs index 8a01a97..770e9ad 100644 --- a/src/L10NSharp/UI/Grid/LmGrid.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmGrid.cs @@ -7,7 +7,7 @@ using System.Windows.Forms; using System.Windows.Forms.VisualStyles; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- public class LmGrid : DataGridView diff --git a/src/L10NSharp/UI/HowToDistributeDialog.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.Designer.cs similarity index 99% rename from src/L10NSharp/UI/HowToDistributeDialog.Designer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.Designer.cs index eaa1811..2639d72 100644 --- a/src/L10NSharp/UI/HowToDistributeDialog.Designer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.Designer.cs @@ -1,4 +1,4 @@ -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { partial class HowToDistributeDialog { diff --git a/src/L10NSharp/UI/HowToDistributeDialog.cs b/src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.cs similarity index 98% rename from src/L10NSharp/UI/HowToDistributeDialog.cs rename to src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.cs index 0c42ff8..a4f954b 100644 --- a/src/L10NSharp/UI/HowToDistributeDialog.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.cs @@ -3,8 +3,9 @@ using System.IO; using System.Linq; using System.Windows.Forms; +using L10NSharp; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { public partial class HowToDistributeDialog : Form { diff --git a/src/L10NSharp/UI/HowToDistributeDialog.resx b/src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.resx similarity index 100% rename from src/L10NSharp/UI/HowToDistributeDialog.resx rename to src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.resx diff --git a/src/L10NSharp/UI/InitializationProgressDlg.cs b/src/L10NSharp.Windows.Forms/UIComponents/InitializationProgressDlg.cs similarity index 87% rename from src/L10NSharp/UI/InitializationProgressDlg.cs rename to src/L10NSharp.Windows.Forms/UIComponents/InitializationProgressDlg.cs index d434104..4dd6b2c 100644 --- a/src/L10NSharp/UI/InitializationProgressDlg.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/InitializationProgressDlg.cs @@ -5,12 +5,13 @@ using System.Drawing; using System.Reflection; using L10NSharp.CodeReader; +using L10NSharp; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { internal class InitializationProgressDlg: InitializationProgressDlgBase { - public IEnumerable ExtractedInfo { get; private set; } + public IEnumerable ExtractedInfo { get; private set; } /// ------------------------------------------------------------------------------------ public InitializationProgressDlg(string appName, IEnumerable additionalLocalizationMethods, @@ -45,14 +46,14 @@ protected override void backgroundWorker_RunWorkerCompleted(object sender, RunWo { try { - if (e.Result is IEnumerable info) + if (e.Result is IEnumerable info) { ExtractedInfo = info; } else { var got = e.Result == null ? "null" : $"{e.Result.GetType()}: {e.Result}"; - ReportError($"Expected IEnumerable but got {got}"); + ReportError($"Expected IEnumerable but got {got}"); } } catch (Exception ex) @@ -73,7 +74,7 @@ private void ReportError(string message) // 2. It provides a way for the developer to see the actual error which caused extraction to fail. ExtractedInfo = new[] { - new LocalizingInfo("StringExtractor_Error") + new LocalizingInfoWinforms("StringExtractor_Error") { LangId = "en", Text = "An error occurred while collecting strings or there were no strings to collect. " + diff --git a/src/L10NSharp/UI/InitializationProgressDlgBase.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/InitializationProgressDlgBase.Designer.cs similarity index 99% rename from src/L10NSharp/UI/InitializationProgressDlgBase.Designer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/InitializationProgressDlgBase.Designer.cs index ed524ba..955f6ab 100644 --- a/src/L10NSharp/UI/InitializationProgressDlgBase.Designer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/InitializationProgressDlgBase.Designer.cs @@ -1,4 +1,4 @@ -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { partial class InitializationProgressDlgBase { diff --git a/src/L10NSharp/UI/InitializationProgressDlgBase.cs b/src/L10NSharp.Windows.Forms/UIComponents/InitializationProgressDlgBase.cs similarity index 97% rename from src/L10NSharp/UI/InitializationProgressDlgBase.cs rename to src/L10NSharp.Windows.Forms/UIComponents/InitializationProgressDlgBase.cs index 7b7909b..e751a6b 100644 --- a/src/L10NSharp/UI/InitializationProgressDlgBase.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/InitializationProgressDlgBase.cs @@ -5,7 +5,7 @@ using System.Reflection; using System.Windows.Forms; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- internal partial class InitializationProgressDlgBase : Form diff --git a/src/L10NSharp/UI/InitializationProgressDlgBase.resx b/src/L10NSharp.Windows.Forms/UIComponents/InitializationProgressDlgBase.resx similarity index 100% rename from src/L10NSharp/UI/InitializationProgressDlgBase.resx rename to src/L10NSharp.Windows.Forms/UIComponents/InitializationProgressDlgBase.resx diff --git a/src/L10NSharp/UI/LanguageChoosingDialog.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingDialog.Designer.cs similarity index 96% rename from src/L10NSharp/UI/LanguageChoosingDialog.Designer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingDialog.Designer.cs index 7317fab..f425d7e 100644 --- a/src/L10NSharp/UI/LanguageChoosingDialog.Designer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingDialog.Designer.cs @@ -1,6 +1,6 @@ using System.Drawing; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { partial class LanguageChoosingDialog { @@ -32,7 +32,7 @@ private void InitializeComponent() { this._messageLabel = new System.Windows.Forms.Label(); this._OKButton = new System.Windows.Forms.Button(); - this.uiLanguageComboBox1 = new L10NSharp.UI.UILanguageComboBox(); + this.uiLanguageComboBox1 = new L10NSharp.Windows.Forms.UIComponents.UILanguageComboBox(); this.SuspendLayout(); // // _messageLabel diff --git a/src/L10NSharp/UI/LanguageChoosingDialog.cs b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingDialog.cs similarity index 94% rename from src/L10NSharp/UI/LanguageChoosingDialog.cs rename to src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingDialog.cs index 069f1bd..0f02438 100644 --- a/src/L10NSharp/UI/LanguageChoosingDialog.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingDialog.cs @@ -2,8 +2,9 @@ using System.Drawing; using System.Windows.Forms; using L10NSharp.Translators; +using L10NSharp; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { public partial class LanguageChoosingDialog : Form { diff --git a/src/L10NSharp/UI/LanguageChoosingSimpleDialog.resx b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingDialog.resx similarity index 100% rename from src/L10NSharp/UI/LanguageChoosingSimpleDialog.resx rename to src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingDialog.resx diff --git a/src/L10NSharp/UI/LanguageChoosingDialogViewModel.cs b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingDialogViewModel.cs similarity index 98% rename from src/L10NSharp/UI/LanguageChoosingDialogViewModel.cs rename to src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingDialogViewModel.cs index db9ee28..b433429 100644 --- a/src/L10NSharp/UI/LanguageChoosingDialogViewModel.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingDialogViewModel.cs @@ -1,8 +1,9 @@ using System; using System.Diagnostics; using L10NSharp.Translators; +using L10NSharp; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { internal class LanguageChoosingDialogViewModel { diff --git a/src/L10NSharp/UI/LanguageChoosingSimpleDialog.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingSimpleDialog.Designer.cs similarity index 92% rename from src/L10NSharp/UI/LanguageChoosingSimpleDialog.Designer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingSimpleDialog.Designer.cs index 616a8c8..4c8d667 100644 --- a/src/L10NSharp/UI/LanguageChoosingSimpleDialog.Designer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingSimpleDialog.Designer.cs @@ -1,4 +1,4 @@ -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { partial class LanguageChoosingSimpleDialog { @@ -28,7 +28,7 @@ protected override void Dispose(bool disposing) ///
private void InitializeComponent() { - this._uiLanguageListBox = new L10NSharp.UI.UILanguageListBox(); + this._uiLanguageListBox = new L10NSharp.Windows.Forms.UIComponents.UILanguageListBox(); this._btnOk = new System.Windows.Forms.Button(); this.SuspendLayout(); // @@ -77,7 +77,7 @@ private void InitializeComponent() #endregion - private L10NSharp.UI.UILanguageListBox _uiLanguageListBox; + private L10NSharp.Windows.Forms.UIComponents.UILanguageListBox _uiLanguageListBox; private System.Windows.Forms.Button _btnOk; } } diff --git a/src/L10NSharp/UI/LanguageChoosingSimpleDialog.cs b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingSimpleDialog.cs similarity index 94% rename from src/L10NSharp/UI/LanguageChoosingSimpleDialog.cs rename to src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingSimpleDialog.cs index ca9d5cc..14cbb79 100644 --- a/src/L10NSharp/UI/LanguageChoosingSimpleDialog.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingSimpleDialog.cs @@ -2,7 +2,7 @@ using System.Drawing; using System.Windows.Forms; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// /// The current thinking for use of this dialog is when an application first starts up, diff --git a/src/L10NSharp/UI/TipDialog.resx b/src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingSimpleDialog.resx similarity index 100% rename from src/L10NSharp/UI/TipDialog.resx rename to src/L10NSharp.Windows.Forms/UIComponents/LanguageChoosingSimpleDialog.resx diff --git a/src/L10NSharp/UI/LocTreeNode.cs b/src/L10NSharp.Windows.Forms/UIComponents/LocTreeNode.cs similarity index 86% rename from src/L10NSharp/UI/LocTreeNode.cs rename to src/L10NSharp.Windows.Forms/UIComponents/LocTreeNode.cs index acc4e8f..1795de3 100644 --- a/src/L10NSharp/UI/LocTreeNode.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/LocTreeNode.cs @@ -2,15 +2,15 @@ using System.Linq; using System.Windows.Forms; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- internal class LocTreeNode : TreeNode { internal string Group { get; set; } internal string Id { get; private set; } - internal ILocalizationManagerInternal Manager { get; private set; } - internal Dictionary SavedTranslationInfo { get; private set; } + internal ILocalizationManagerInternalWinforms Manager { get; private set; } + internal Dictionary SavedTranslationInfo { get; private set; } internal string SavedComment { get; set; } /// ------------------------------------------------------------------------------------ @@ -18,14 +18,14 @@ internal class LocTreeNode : TreeNode /// Initializes a new instance of the class. /// /// ------------------------------------------------------------------------------------ - internal LocTreeNode(ILocalizationManagerInternal manager, string text, string id, string key) + internal LocTreeNode(ILocalizationManagerInternalWinforms manager, string text, string id, string key) { Manager = manager; Text = text; Id = id; Name = key; - SavedTranslationInfo = new Dictionary(); + SavedTranslationInfo = new Dictionary(); } /// ------------------------------------------------------------------------------------ diff --git a/src/L10NSharp/UI/NodeComparer.cs b/src/L10NSharp.Windows.Forms/UIComponents/NodeComparer.cs similarity index 98% rename from src/L10NSharp/UI/NodeComparer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/NodeComparer.cs index a3678f2..92c7bdd 100644 --- a/src/L10NSharp/UI/NodeComparer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/NodeComparer.cs @@ -5,7 +5,7 @@ using System.Globalization; using System.Windows.Forms; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- internal class NodeComparer : IComparer> diff --git a/src/L10NSharp/UI/PaintingHelper.cs b/src/L10NSharp.Windows.Forms/UIComponents/PaintingHelper.cs similarity index 99% rename from src/L10NSharp/UI/PaintingHelper.cs rename to src/L10NSharp.Windows.Forms/UIComponents/PaintingHelper.cs index ab8d61c..a9c8618 100644 --- a/src/L10NSharp/UI/PaintingHelper.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/PaintingHelper.cs @@ -5,7 +5,7 @@ using System.Windows.Forms; using System.Windows.Forms.VisualStyles; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ------------------------------------------------------------------------------------ /// diff --git a/src/L10NSharp/UI/PopupControl.cs b/src/L10NSharp.Windows.Forms/UIComponents/PopupControl.cs similarity index 99% rename from src/L10NSharp/UI/PopupControl.cs rename to src/L10NSharp.Windows.Forms/UIComponents/PopupControl.cs index 290f3b5..7a9f82c 100644 --- a/src/L10NSharp/UI/PopupControl.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/PopupControl.cs @@ -5,7 +5,7 @@ using System.Drawing.Drawing2D; using System.Windows.Forms; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- internal partial class PopupControl : UserControl diff --git a/src/L10NSharp/UI/PopupControl.designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/PopupControl.designer.cs similarity index 94% rename from src/L10NSharp/UI/PopupControl.designer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/PopupControl.designer.cs index 1fc9b46..2e40de5 100644 --- a/src/L10NSharp/UI/PopupControl.designer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/PopupControl.designer.cs @@ -1,4 +1,4 @@ -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { partial class PopupControl { diff --git a/src/L10NSharp/UI/PopupControl.resx b/src/L10NSharp.Windows.Forms/UIComponents/PopupControl.resx similarity index 100% rename from src/L10NSharp/UI/PopupControl.resx rename to src/L10NSharp.Windows.Forms/UIComponents/PopupControl.resx diff --git a/src/L10NSharp/UI/ShortcutKeysDropDown.cs b/src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysDropDown.cs similarity index 98% rename from src/L10NSharp/UI/ShortcutKeysDropDown.cs rename to src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysDropDown.cs index 1d2710f..e937605 100644 --- a/src/L10NSharp/UI/ShortcutKeysDropDown.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysDropDown.cs @@ -1,7 +1,7 @@ using System; using System.Windows.Forms; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- internal class ShortcutKeysDropDown : CustomDropDownComboBox diff --git a/src/L10NSharp/UI/ShortcutKeysEditor.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysEditor.Designer.cs similarity index 99% rename from src/L10NSharp/UI/ShortcutKeysEditor.Designer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysEditor.Designer.cs index 5ec6a91..aed8c78 100644 --- a/src/L10NSharp/UI/ShortcutKeysEditor.Designer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysEditor.Designer.cs @@ -1,4 +1,4 @@ -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { partial class ShortcutKeysEditor { diff --git a/src/L10NSharp/UI/ShortcutKeysEditor.cs b/src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysEditor.cs similarity index 99% rename from src/L10NSharp/UI/ShortcutKeysEditor.cs rename to src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysEditor.cs index 22b30c9..5aa150a 100644 --- a/src/L10NSharp/UI/ShortcutKeysEditor.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysEditor.cs @@ -2,7 +2,7 @@ using System.Drawing; using System.Windows.Forms; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- internal partial class ShortcutKeysEditor : PopupControl diff --git a/src/L10NSharp/UI/ShortcutKeysEditor.resx b/src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysEditor.resx similarity index 100% rename from src/L10NSharp/UI/ShortcutKeysEditor.resx rename to src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysEditor.resx diff --git a/src/L10NSharp/UI/TipDialog.cs b/src/L10NSharp.Windows.Forms/UIComponents/TipDialog.cs similarity index 96% rename from src/L10NSharp/UI/TipDialog.cs rename to src/L10NSharp.Windows.Forms/UIComponents/TipDialog.cs index b858f71..2ca4230 100644 --- a/src/L10NSharp/UI/TipDialog.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/TipDialog.cs @@ -1,9 +1,9 @@ using System; using System.Drawing; using System.Windows.Forms; -using L10NSharp.Properties; +using L10NSharp.Windows.Forms.Properties; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { public partial class TipDialog : Form { diff --git a/src/L10NSharp/UI/TipDialog.designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/TipDialog.designer.cs similarity index 99% rename from src/L10NSharp/UI/TipDialog.designer.cs rename to src/L10NSharp.Windows.Forms/UIComponents/TipDialog.designer.cs index 8d15a5a..8cfa1a4 100644 --- a/src/L10NSharp/UI/TipDialog.designer.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/TipDialog.designer.cs @@ -1,4 +1,4 @@ -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { partial class TipDialog { diff --git a/src/L10NSharp/UI/L10NExtender.resx b/src/L10NSharp.Windows.Forms/UIComponents/TipDialog.resx similarity index 96% rename from src/L10NSharp/UI/L10NExtender.resx rename to src/L10NSharp.Windows.Forms/UIComponents/TipDialog.resx index ae50817..d58980a 100644 --- a/src/L10NSharp/UI/L10NExtender.resx +++ b/src/L10NSharp.Windows.Forms/UIComponents/TipDialog.resx @@ -117,7 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - False - \ No newline at end of file diff --git a/src/L10NSharp/UI/UILanguageComboBox.cs b/src/L10NSharp.Windows.Forms/UIComponents/UILanguageComboBox.cs similarity index 97% rename from src/L10NSharp/UI/UILanguageComboBox.cs rename to src/L10NSharp.Windows.Forms/UIComponents/UILanguageComboBox.cs index 7ea016a..f625a4f 100644 --- a/src/L10NSharp/UI/UILanguageComboBox.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/UILanguageComboBox.cs @@ -1,12 +1,11 @@ -using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; -using System.Globalization; using System.Linq; using System.Windows.Forms; +using L10NSharp; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- public class UILanguageComboBox : ComboBox diff --git a/src/L10NSharp/UI/UILanguageListBox.cs b/src/L10NSharp.Windows.Forms/UIComponents/UILanguageListBox.cs similarity index 98% rename from src/L10NSharp/UI/UILanguageListBox.cs rename to src/L10NSharp.Windows.Forms/UIComponents/UILanguageListBox.cs index b23c80c..0bada8b 100644 --- a/src/L10NSharp/UI/UILanguageListBox.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/UILanguageListBox.cs @@ -4,8 +4,9 @@ using System.Globalization; using System.Linq; using System.Windows.Forms; +using L10NSharp; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- public class UILanguageListBox : ListBox diff --git a/src/L10NSharp/UI/XButton.cs b/src/L10NSharp.Windows.Forms/UIComponents/XButton.cs similarity index 99% rename from src/L10NSharp/UI/XButton.cs rename to src/L10NSharp.Windows.Forms/UIComponents/XButton.cs index 6d4f881..5a199ff 100644 --- a/src/L10NSharp/UI/XButton.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/XButton.cs @@ -3,7 +3,7 @@ using System.Windows.Forms; using System.Windows.Forms.VisualStyles; -namespace L10NSharp.UI +namespace L10NSharp.Windows.Forms.UIComponents { /// ---------------------------------------------------------------------------------------- internal class XButton : Label diff --git a/src/L10NSharp.Windows.Forms/UtilsWinforms.cs b/src/L10NSharp.Windows.Forms/UtilsWinforms.cs new file mode 100644 index 0000000..e296e07 --- /dev/null +++ b/src/L10NSharp.Windows.Forms/UtilsWinforms.cs @@ -0,0 +1,56 @@ +using System.Reflection; +using System; +using System.Windows.Forms; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace L10NSharp.Windows.Forms +{ + /// ---------------------------------------------------------------------------------------- + internal static class UtilsWinforms + { + private const int WM_SETREDRAW = 0xB; + + + [DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "SendMessage")] + private static extern void SendMessageWindows(IntPtr hWnd, int msg, int wParam, int lParam); + + public static void SendMessage(IntPtr hWnd, int msg, int wParam, int lParam) + { + SendMessageWindows(hWnd, msg, wParam, lParam); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Turns window redrawing on or off. After turning on, the window will be invalidated. + /// + /// ------------------------------------------------------------------------------------ + public static void SetWindowRedraw(Control ctrl, bool turnOn) + { + SetWindowRedraw(ctrl, turnOn, true); + } + + /// ------------------------------------------------------------------------------------ + public static void SetWindowRedraw(Control ctrl, bool turnOn, + bool invalidateAfterTurningOn) + { + if (ctrl != null && !ctrl.IsDisposed && ctrl.IsHandleCreated) + { + if (L10NSharp.Utils.IsMono) + { + if (turnOn) + ctrl.ResumeLayout(invalidateAfterTurningOn); + else + ctrl.SuspendLayout(); + } + else + { + SendMessage(ctrl.Handle, WM_SETREDRAW, (turnOn ? 1 : 0), 0); + } + + if (turnOn && invalidateAfterTurningOn) + ctrl.Invalidate(true); + } + } + } +} diff --git a/src/L10NSharp.Windows.Forms/XLiffUtils/XliffLocalizationManagerWinforms.cs b/src/L10NSharp.Windows.Forms/XLiffUtils/XliffLocalizationManagerWinforms.cs new file mode 100644 index 0000000..4329fa8 --- /dev/null +++ b/src/L10NSharp.Windows.Forms/XLiffUtils/XliffLocalizationManagerWinforms.cs @@ -0,0 +1,374 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows.Forms; +using L10NSharp.XLiffUtils; + +namespace L10NSharp.Windows.Forms.XLiffUtils +{ + /// ---------------------------------------------------------------------------------------- + internal class XliffLocalizationManagerWinforms : XliffLocalizationManager, ILocalizationManagerInternalWinforms + { + /// ------------------------------------------------------------------------------------ + private static Icon _applicationIcon; + public Dictionary ToolTipCtrls { get; } + public Dictionary> LocalizableComponents { get; } + + #region XliffLocalizationManager construction/disposal + /// ------------------------------------------------------------------------------------ + internal XliffLocalizationManagerWinforms(string appId, string origExtension, string appName, + string appVersion, string directoryOfInstalledXliffFiles, + string directoryForGeneratedDefaultXliffFile, string directoryOfUserModifiedXliffFiles, + IEnumerable additionalLocalizationMethods, + params string[] namespaceBeginnings) : + base(appId, origExtension, appName, appVersion, directoryOfInstalledXliffFiles, + directoryForGeneratedDefaultXliffFile, directoryOfUserModifiedXliffFiles, + additionalLocalizationMethods, namespaceBeginnings) + { + ToolTipCtrls = new Dictionary(); + StringCache = new XliffLocalizedStringCacheWinforms(this); + LocalizableComponents = new Dictionary>(); + } + + internal XliffLocalizationManagerWinforms(string appId, string appName, string appVersion) : base(appId, appName, appVersion) + { + } + + /// Sometimes, on Linux, there is an empty DefaultStringFile. This causes problems. + private bool DefaultStringFileExistsAndHasContents() + { + return File.Exists(DefaultStringFilePath) && !string.IsNullOrWhiteSpace(File.ReadAllText(DefaultStringFilePath)); + } + + #endregion + + #region Public Properties + /// ------------------------------------------------------------------------------------ + public new ILocalizedStringCacheWinforms StringCache { get; } + + #endregion + + #region Methods for caching and localizing objects. + /// + /// Adds the specified component to the localization manager's cache of objects to be + /// localized and then applies localizations for the current UI language. + /// + /// ------------------------------------------------------------------------------------ + public void RegisterComponentForLocalizing(IComponent component, string id, string + defaultText, string defaultTooltip, string defaultShortcutKeys, string comment) + { + RegisterComponentForLocalizing(new LocalizingInfoWinforms(component, id) + { + Text = defaultText, + ToolTipText = defaultTooltip, + ShortcutKeys = defaultShortcutKeys, + Comment = comment + }, null); + } + + public void RegisterComponentForLocalizing(LocalizingInfoWinforms info, + Action successAction) + { + var component = info.Component; + var id = info.Id; + if (component == null || string.IsNullOrWhiteSpace(id)) + return; + + try + { + + // This if/else used to be more concise but sometimes there were occasions + // adding an item the first time using ComponentCache[component] = id would throw an + // index outside the bounds of the array exception. I have no clue why nor + // can I reliably reproduce the error nor do I know if this change will solve + // the problem. Hopefully it will, but my guess is the same underlying code + // will be called. + if (ComponentCache.ContainsKey(component)) + ComponentCache[component] = id; //somehow, we sometimes see "Msg: Index was outside the bounds of the array." + else + { + var lm = LocalizationManagerInternalWinforms.GetLocalizationManagerForStringWinforms(id); + if (lm != null && lm != this) + { + lm.RegisterComponentForLocalizing(info, successAction); + return; + } + if (component is ILocalizableComponent) + ComponentCache.Add(component, id); + else + { + ComponentCache.Add(component, id); + // Make it available for the config dialog to localize. + StringCache.UpdateLocalizedInfo(info); + } + } + + successAction?.Invoke(this, info); + } + catch (Exception) + { +#if DEBUG + throw; // if you hit this ( Index was outside the bounds of the array) try to figure out why. What is the hash (?) value for the component? +#endif + } + } + #endregion + + #region Non static methods for getting localized strings + /// ------------------------------------------------------------------------------------ + private Keys GetShortCutKeyFromStringCache(string uiLangId, string id) + { + var realLangId = LocalizationManagerInternal.MapToExistingLanguageIfPossible(uiLangId); + return StringCache.GetShortcutKeys(realLangId, id); + } + + #endregion + + #region Methods that apply localizations to an object. + public void ApplyLocalizationsToILocalizableComponent(LocalizingInfoWinforms locInfo) + { + if (locInfo.Component is ILocalizableComponent locComponent && + LocalizableComponents.TryGetValue(locComponent, out var idToLocInfo)) + { + ApplyLocalizationsToLocalizableComponent(locComponent, idToLocInfo); + return; + } +#if DEBUG + var msg = + "Either locInfo.component is not an ILocalizableComponent or LocalizableComponents hasn't been updated with id={0}."; + throw new ApplicationException(string.Format(msg, locInfo.Id)); +#endif + } + + /// ------------------------------------------------------------------------------------ + /// + /// Reapplies the localizations to all components in the localization manager's cache of + /// localized components. + /// + /// ------------------------------------------------------------------------------------ + public void ReapplyLocalizationsToAllComponents() + { + foreach (var component in ComponentCache.Keys) + ApplyLocalization(component); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Recreates the tooltip control and updates the tooltip text for each object having + /// a tooltip. This is necessary sometimes when controls get moved from form to form + /// during runtime. + /// + /// ------------------------------------------------------------------------------------ + public void RefreshToolTips() + { + foreach (var toolTipCtrl in ToolTipCtrls.Values) + toolTipCtrl.Dispose(); + + ToolTipCtrls.Clear(); + + // This used to be a for-each, but on rare occasions, a "Collection was + // modified; enumeration operation may not execute" exception would be + // thrown. This should solve the problem. + var controls = ComponentCache.Where(x => x.Key is Control).ToArray(); + foreach (var ctrl in controls) + { + var toolTipText = GetTooltipFromStringCache(UILanguageId, ctrl.Value); + if (!string.IsNullOrEmpty(toolTipText)) //JH: hoping to speed this up a bit + ApplyLocalizedToolTipToControl((Control)ctrl.Key, toolTipText); + } + } + + /// ------------------------------------------------------------------------------------ + /// + /// Initializes the specified component. + /// + /// ------------------------------------------------------------------------------------ + public void ApplyLocalization(IComponent component) + { + if (component == null) + return; + + if (!ComponentCache.TryGetValue(component, out var id)) + return; + + if (component is ILocalizableComponent locComponent) + { + if (LocalizableComponents.TryGetValue(locComponent, out var idToLocInfo)) + { + ApplyLocalizationsToLocalizableComponent(locComponent, idToLocInfo); + return; + } + } + + if (ApplyLocalizationsToControl(component as Control, id)) + return; + + if (ApplyLocalizationsToToolStripItem(component as ToolStripItem, id)) + return; + + if (ApplyLocalizationsToListViewColumnHeader(component as ColumnHeader, id)) + return; + + ApplyLocalizationsToDataGridViewColumn(component as DataGridViewColumn, id); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Initializes the specified ILocalizableComponent. + /// + /// ------------------------------------------------------------------------------------ + internal void ApplyLocalizationsToLocalizableComponent( + ILocalizableComponent locComponent, Dictionary idToLocInfo) + { + if (locComponent == null) + return; + + foreach (var kvp in idToLocInfo) + { + var id = kvp.Key; + var locInfo = kvp.Value; + locComponent.ApplyLocalizationToString(locInfo.Component, id, GetLocalizedString(id, locInfo.Text)); + } + } + + /// ------------------------------------------------------------------------------------ + /// + /// Initializes the specified control. + /// + /// ------------------------------------------------------------------------------------ + private bool ApplyLocalizationsToControl(Control ctrl, string id) + { + if (ctrl == null) + return false; + + var text = GetStringFromStringCache(UILanguageId, id); + var toolTipText = GetTooltipFromStringCache(UILanguageId, id); + + if (text != null && string.CompareOrdinal(ctrl.Text, text) != 0) + ctrl.Text = text; + + ApplyLocalizedToolTipToControl(ctrl, toolTipText); + return true; + } + + /// ------------------------------------------------------------------------------------ + private void ApplyLocalizedToolTipToControl(Control ctrl, string toolTipText) + { + var topCtrl = LocalizationManagerInternalWinforms.GetRealTopLevelControl(ctrl); + if (topCtrl == null) + return; + + // Check if the control's top level control has a reference to a tooltip. If + // it does, then use that tooltip for assigning tooltip text to the control. + // Otherwise, create a new tooltip and reference it using the control's top + // level control. + if (!ToolTipCtrls.TryGetValue(topCtrl, out var ttCtrl)) + { + if (string.IsNullOrEmpty(toolTipText)) + return; + + ttCtrl = new ToolTip(); + ToolTipCtrls[topCtrl] = ttCtrl; + topCtrl.ParentChanged += HandleToolTipRefChanged; + topCtrl.HandleDestroyed += HandleToolTipRefDestroyed; + } + + ttCtrl.SetToolTip(ctrl, toolTipText); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Handles the case when a tooltip instance was created and assigned to a top level + /// control that has now been added to another control, thus making the other control + /// top level instead. Therefore, we need to make sure the tooltip is reassigned to + /// the new top level control. + /// + /// ------------------------------------------------------------------------------------ + private void HandleToolTipRefChanged(object sender, EventArgs e) + { + var oldTopCtrl = sender as Control; + var newTopCtrl = LocalizationManagerInternalWinforms.GetRealTopLevelControl(oldTopCtrl); + if (oldTopCtrl == null || newTopCtrl == null) + return; + + oldTopCtrl.ParentChanged -= HandleToolTipRefChanged; + newTopCtrl.ParentChanged += HandleToolTipRefChanged; + RefreshToolTips(); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Handles removing tooltip controls from the global tool tip collection for top level + /// controls that are destroyed and have controls on them using tool tip controls from + /// that collection. + /// + /// ------------------------------------------------------------------------------------ + private void HandleToolTipRefDestroyed(object sender, EventArgs e) + { + if (!(sender is Control topCtrl)) + return; + + topCtrl.ParentChanged -= HandleToolTipRefChanged; + topCtrl.HandleDestroyed -= HandleToolTipRefDestroyed; + + if (ToolTipCtrls.TryGetValue(topCtrl, out var ttCtrl)) + ttCtrl.Dispose(); + + ToolTipCtrls.Remove(topCtrl); + } + + /// ------------------------------------------------------------------------------------ + private bool ApplyLocalizationsToToolStripItem(ToolStripItem item, string id) + { + if (item == null) + return false; + + var text = GetStringFromStringCache(UILanguageId, id); + var toolTipText = GetTooltipFromStringCache(UILanguageId, id); + item.Text = text ?? LocalizationManager.StripOffLocalizationInfoFromText(item.Text); + item.ToolTipText = toolTipText ?? LocalizationManager.StripOffLocalizationInfoFromText(item.ToolTipText); + + var shortcutKeys = GetShortCutKeyFromStringCache(UILanguageId, id); + if (item is ToolStripMenuItem menuItem && shortcutKeys != Keys.None) + menuItem.ShortcutKeys = shortcutKeys; + + return true; + } + + /// ------------------------------------------------------------------------------------ + private bool ApplyLocalizationsToListViewColumnHeader(ColumnHeader hdr, string id) + { + if (hdr == null) + return false; + + var text = GetStringFromStringCache(UILanguageId, id); + hdr.Text = text ?? LocalizationManager.StripOffLocalizationInfoFromText(hdr.Text); + return true; + } + + /// ------------------------------------------------------------------------------------ + private bool ApplyLocalizationsToDataGridViewColumn(DataGridViewColumn col, string id) + { + if (col == null) + return false; + + var text = GetStringFromStringCache(UILanguageId, id); + col.HeaderText = text ?? LocalizationManager.StripOffLocalizationInfoFromText(col.HeaderText); + col.ToolTipText = GetTooltipFromStringCache(UILanguageId, id); + return true; + } + + #endregion + + public Icon ApplicationIcon + { + get => _applicationIcon; + set => _applicationIcon = value; + } + } +} diff --git a/src/L10NSharp.Windows.Forms/XLiffUtils/XliffLocalizedStringCacheWinforms.cs b/src/L10NSharp.Windows.Forms/XLiffUtils/XliffLocalizedStringCacheWinforms.cs new file mode 100644 index 0000000..6f33d80 --- /dev/null +++ b/src/L10NSharp.Windows.Forms/XLiffUtils/XliffLocalizedStringCacheWinforms.cs @@ -0,0 +1,85 @@ +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Windows.Forms; +using L10NSharp.Windows.Forms.UIComponents; +using L10NSharp.XLiffUtils; +using L10NSharp; + +namespace L10NSharp.Windows.Forms.XLiffUtils +{ + /// ---------------------------------------------------------------------------------------- + internal class XliffLocalizedStringCacheWinforms : XliffLocalizedStringCache, ILocalizedStringCacheWinforms + { + + public List> LeafNodeList { get; private set; } + + #region Loading methods + + /// ------------------------------------------------------------------------------------ + /// + /// Loads the string cache from all the specified Xliff files + /// + /// ------------------------------------------------------------------------------------ + internal XliffLocalizedStringCacheWinforms(ILocalizationManager owningManager, bool loadAvailableXliffFiles = true) : base(owningManager, loadAvailableXliffFiles) + { + LeafNodeList = new List>(); + } + + /// ------------------------------------------------------------------------------------ + /// + /// Gets the localized tooltip text for the specified id and suffix. + /// + /// ------------------------------------------------------------------------------------ + public Keys GetShortcutKeys(string langId, string id) + { + string keys = GetValueForLangAndIdWithFallback(langId, id + kShortcutSuffix); + return ShortcutKeysEditor.KeysFromString(keys); + } + + #endregion + + #region Methods for loading a tree node collection with all the localizable strings. + + /// ------------------------------------------------------------------------------------ + /// + /// Loads the specified tree node collection with all the string groups and their + /// localizable string ids. + /// + /// ------------------------------------------------------------------------------------ + public void LoadGroupNodes(TreeNodeCollection topCollection) + { + LeafNodeList.Clear(); + + foreach (var tu in GetTranslationUnitsForTree()) + { + string id = GetBaseId(tu.Id); + var groupChain = ParseGroupAndId(GetGroup(tu.Id), id); + var nodeKey = string.Empty; + var nodeCollection = topCollection; + LocTreeNode newNode; + + for (int i = groupChain.Count - 1; i > 0; i--) + { + nodeKey = (nodeKey + "." + groupChain[i]).TrimStart('.'); + + var nodes = nodeCollection.Find(nodeKey, true); + if (nodes.Length > 0) + nodeCollection = nodes[0].Nodes; + else + { + newNode = new LocTreeNode((XliffLocalizationManagerWinforms)OwningManager, groupChain[i], null, + nodeKey); + nodeCollection.Add(newNode); + nodeCollection = newNode.Nodes; + } + } + + nodeKey = nodeKey + ("." + groupChain[0]).TrimStart('.'); + newNode = new LocTreeNode((XliffLocalizationManagerWinforms)OwningManager, groupChain[0], id, nodeKey); + nodeCollection.Add(newNode); + LeafNodeList.Add(newNode); + } + } + #endregion + } +} diff --git a/src/L10NSharp/ILocalizationManager.cs b/src/L10NSharp/ILocalizationManager.cs index ddc5899..987f67e 100644 --- a/src/L10NSharp/ILocalizationManager.cs +++ b/src/L10NSharp/ILocalizationManager.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Windows.Forms; namespace L10NSharp { @@ -81,17 +80,7 @@ public interface ILocalizationManager: IDisposable bool DoesCustomizedTranslationExistForLanguage(string langId); - /// ------------------------------------------------------------------------------------ - /// - /// Recreates the tooltip control and updates the tooltip text for each object having - /// a tooltip. This is necessary sometimes when controls get moved from form to form - /// during runtime. - /// - /// ------------------------------------------------------------------------------------ - void RefreshToolTips(); - void PrepareToCustomizeLocalizations(); - void ShowLocalizationDialogBox(bool runInReadonlyMode, IWin32Window owner = null); /// ------------------------------------------------------------------------------------ /// diff --git a/src/L10NSharp/ILocalizationManagerInternal.cs b/src/L10NSharp/ILocalizationManagerInternal.cs index 713c386..29d3bce 100644 --- a/src/L10NSharp/ILocalizationManagerInternal.cs +++ b/src/L10NSharp/ILocalizationManagerInternal.cs @@ -1,30 +1,14 @@ // Copyright © 2019-2025 SIL Global // This software is licensed under the MIT License (http://opensource.org/licenses/MIT) -using System; using System.Collections.Generic; using System.ComponentModel; -using System.Drawing; -using System.Windows.Forms; namespace L10NSharp { internal interface ILocalizationManagerInternal: ILocalizationManager { Dictionary ComponentCache { get; } - Dictionary ToolTipCtrls { get; } - Dictionary> LocalizableComponents { get; } - Icon ApplicationIcon { get; set; } - - void ApplyLocalization(IComponent component); - void ApplyLocalizationsToILocalizableComponent(LocalizingInfo locInfo); - - void ReapplyLocalizationsToAllComponents(); - - void RegisterComponentForLocalizing(IComponent component, string id, string defaultText, - string defaultTooltip, string defaultShortcutKeys, string comment); - void RegisterComponentForLocalizing(LocalizingInfo info, - Action successAction); string GetStringFromStringCache(string uiLangId, string id); diff --git a/src/L10NSharp/ILocalizedStringCache.cs b/src/L10NSharp/ILocalizedStringCache.cs index 0892f52..dc0c70d 100644 --- a/src/L10NSharp/ILocalizedStringCache.cs +++ b/src/L10NSharp/ILocalizedStringCache.cs @@ -2,9 +2,6 @@ // // This software is licensed under the MIT License (http://opensource.org/licenses/MIT) using System.Collections.Generic; -using System.Windows.Forms; -using L10NSharp.UI; -using L10NSharp.XLiffUtils; namespace L10NSharp { @@ -12,18 +9,15 @@ internal interface ILocalizedStringCache { bool TryGetDocument(string langId, out T doc); IEnumerable AvailableLangKeys { get; } - List> LeafNodeList { get; } string GetString(string langId, string id); string GetString(string langId, string id, bool formatForDisplay); string GetToolTipText(string langId, string id); string GetToolTipText(string langId, string id, bool formatForDisplay); - Keys GetShortcutKeys(string langId, string id); string GetShortcutKeysText(string langId, string id); string GetComment(string id); string GetValueForExactLangAndId(string langId, string id, bool formatForDisplay); void UpdateLocalizedInfo(LocalizingInfo locInfo); - void LoadGroupNodes(TreeNodeCollection topCollection); int NumberApproved(string lang); int NumberTranslated(string lang); diff --git a/src/L10NSharp/L10NSharp.csproj b/src/L10NSharp/L10NSharp.csproj index 39ca4a5..9399c47 100644 --- a/src/L10NSharp/L10NSharp.csproj +++ b/src/L10NSharp/L10NSharp.csproj @@ -1,14 +1,13 @@  L10NSharp - L10NSharp is a .NET localization library for Windows Forms applications. It collects strings which need localization when your application first runs and saves them in a XLIFF file. It can also dynamically collect strings at runtime. + L10NSharp is a .NET localization library. It collects strings which need localization when your application first runs and saves them in a XLIFF file. L10NSharp L10NSharp https://github.com/sillsdev/l10nsharp - + - diff --git a/src/L10NSharp/LocalizationManager.cs b/src/L10NSharp/LocalizationManager.cs index 3f335da..ff88225 100644 --- a/src/L10NSharp/LocalizationManager.cs +++ b/src/L10NSharp/LocalizationManager.cs @@ -4,20 +4,16 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics; -using System.Drawing; using System.Globalization; using System.IO; using System.Reflection; using System.Threading; -using System.Windows.Forms; using L10NSharp.TMXUtils; -using L10NSharp.UI; using L10NSharp.XLiffUtils; namespace L10NSharp { - public static class LocalizationManager + public class LocalizationManager { public const string kDefaultLang = "en"; internal const string kL10NPrefix = "_L10N_:"; @@ -63,119 +59,6 @@ public static class LocalizationManager public static string EmailForSubmissions { get; set; } - /// ------------------------------------------------------------------------------------ - /// - /// Creates a new instance of a localization manager for the specified application id. - /// If a localization manager has already been created for the specified id, then - /// that is returned. - /// - /// Translation memory type to use - /// The language code of the desired UI language. If - /// there are no translations for that ID, a message is displayed and the UI language - /// falls back to the default. - /// The application Id (e.g. 'Pa' for Phonology Assistant). - /// This should be a unique name that identifies the manager for an assembly or - /// application. May include an optional file extension, which will be stripped off but - /// used to correctly set the "original" attribute when persisting an XLIFF file. The - /// base portion must still be unique (i.e., it is not valid to create a LM for - /// "Blah.exe" and another for "Blah.dll"). - /// The application's name. This will appear to the user - /// in the localization dialog box as a parent item in the tree. - /// - /// The full folder path of the original l10n - /// files installed with the application. - /// The path, relative to - /// %appdata%, where your application stores user settings (e.g., "SIL\SayMore"). - /// A folder named "localizations" will be created there. - /// - /// This will be used in UI that helps the translator - /// know what to do with their work - /// A list of namespace beginnings indicating - /// what types to scan for localized string calls. For example, to only scan - /// types found in Pa.exe and assuming all types in that assembly begin with - /// 'Pa', then this value would only contain the string 'Pa'. - /// ------------------------------------------------------------------------------------ - [Obsolete("Use the overload without `TranslationMemory kind` parameter.")] - public static ILocalizationManager Create(TranslationMemory kind, string desiredUiLangId, - string appId, string appName, string appVersion, string directoryOfInstalledFiles, - string relativeSettingPathForLocalizationFolder, - Icon applicationIcon, string emailForSubmissions, params string[] namespaceBeginnings) - { - if (kind != TranslationMemory.XLiff) - { - throw new ArgumentException($@"Unknown translation memory kind {kind}. Only XLiff - is supported.", - nameof(kind)); - } - - return Create(desiredUiLangId, - appId, appName, appVersion, directoryOfInstalledFiles, - relativeSettingPathForLocalizationFolder, - applicationIcon, emailForSubmissions, - namespaceBeginnings); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a new instance of a localization manager for the specified application id. - /// If a localization manager has already been created for the specified id, then - /// that is returned. - /// - /// Translation memory type to use - /// The language code of the desired UI language. If - /// there are no translations for that ID, a message is displayed and the UI language - /// falls back to the default. - /// The application Id (e.g. 'Pa' for Phonology Assistant). - /// This should be a unique name that identifies the manager for an assembly or - /// application. May include an optional file extension, which will be stripped off but - /// used to correctly set the "original" attribute when persisting an XLIFF file. The - /// base portion must still be unique (i.e., it is not valid to create a LM for - /// "Blah.exe" and another for "Blah.dll"). - /// The application's name. This will appear to the user - /// in the localization dialog box as a parent item in the tree. - /// - /// The full folder path of the original l10n - /// files installed with the application. - /// The path, relative to - /// %appdata%, where your application stores user settings (e.g., "SIL\SayMore"). - /// A folder named "localizations" will be created there. - /// - /// This will be used in UI that helps the translator - /// know what to do with their work - /// MethodInfo objects representing - /// additional methods that should be regarded as calls to get localizations. If the method - /// is named "Localize", the extractor will attempt to parse its signature as an extension - /// method with the parameters (this string s, string separateId="", string comment=""). - /// Otherwise, it will be treated like a L10nSharp GetString method if its signature - /// matches one of the following: (string stringId, string englishText), - /// (string stringId, string englishText, string comment), or - /// (string stringId, string englishText, string comment, string englishToolTipText, - /// string englishShortcutKey, IComponent component). - /// A list of namespace beginnings indicating - /// what types to scan for localized string calls. For example, to only scan - /// types found in Pa.exe and assuming all types in that assembly begin with - /// 'Pa', then this value would only contain the string 'Pa'. - /// ------------------------------------------------------------------------------------ - [Obsolete("Use the overload without `TranslationMemory kind` parameter.")] - public static ILocalizationManager Create(TranslationMemory kind, string desiredUiLangId, - string appId, string appName, string appVersion, string directoryOfInstalledFiles, - string relativeSettingPathForLocalizationFolder, - Icon applicationIcon, string emailForSubmissions, - IEnumerable additionalLocalizationMethods, - params string[] namespaceBeginnings) - { - if (kind != TranslationMemory.XLiff) - { - throw new ArgumentException($@"Unknown translation memory kind {kind}. Only XLiff - is supported.", - nameof(kind)); - } - - return Create(desiredUiLangId, appId, appName, appVersion, directoryOfInstalledFiles, - relativeSettingPathForLocalizationFolder, applicationIcon, emailForSubmissions, - namespaceBeginnings, additionalLocalizationMethods); - } - /// ------------------------------------------------------------------------------------ /// /// Creates a new instance of a localization manager for the specified application id. @@ -199,7 +82,6 @@ public static ILocalizationManager Create(TranslationMemory kind, string desired /// The path, relative to /// %localappdata%, where your application stores user settings (e.g., "SIL\SayMore"). /// A folder named "localizations" will be created there. - /// /// This will be used in UI that helps the translator /// know what to do with their work /// A list of namespace beginnings indicating @@ -219,7 +101,7 @@ public static ILocalizationManager Create(TranslationMemory kind, string desired public static ILocalizationManager Create(string desiredUiLangId, string appId, string appName, string appVersion, string directoryOfInstalledFiles, string relativeSettingPathForLocalizationFolder, - Icon applicationIcon, string emailForSubmissions, + string emailForSubmissions, string[] namespaceBeginnings, IEnumerable additionalLocalizationMethods = null) { @@ -227,7 +109,7 @@ public static ILocalizationManager Create(string desiredUiLangId, EmailForSubmissions = emailForSubmissions; return LocalizationManagerInternal.CreateXliff(desiredUiLangId, appId, appName, appVersion, directoryOfInstalledFiles, - relativeSettingPathForLocalizationFolder, applicationIcon, + relativeSettingPathForLocalizationFolder, additionalLocalizationMethods, namespaceBeginnings); } @@ -269,8 +151,7 @@ public static void DeleteOldTranslationFiles(string appId, } /// ------------------------------------------------------------------------------------ - public static void SetUILanguage(string langId, - bool reapplyLocalizationsToAllObjectsInAllManagers) + public static void SetUILanguage(string langId) { if (UILanguageId == langId || string.IsNullOrEmpty(langId)) return; @@ -286,9 +167,6 @@ public static void SetUILanguage(string langId, LocalizationManagerInternal.SetAvailableFallbackLanguageIds(GetAvailableLocalizedLanguages()); break; } - - if (reapplyLocalizationsToAllObjectsInAllManagers) - ReapplyLocalizationsToAllObjectsInAllManagers(); } /// ------------------------------------------------------------------------------------ @@ -446,28 +324,6 @@ public static int StringCount(string lang) } } - public static void ShowLocalizationDialogBox(IComponent component) - { - switch (TranslationMemoryKind) - { - default: - case TranslationMemory.XLiff: - LocalizationManagerInternal.ShowLocalizationDialogBox(component); - break; - } - } - - public static void ShowLocalizationDialogBox(string id) - { - switch (TranslationMemoryKind) - { - default: - case TranslationMemory.XLiff: - LocalizationManagerInternal.ShowLocalizationDialogBox(id); - break; - } - } - /// ------------------------------------------------------------------------------------ /// /// Gets or sets the list of languages (by id) used to fallback to when looking for a @@ -727,50 +583,6 @@ internal static string GetTranslationFileNameForLanguage(string appId, string la : $"{appId}.{langId}{fileExtension}"; } - /// ------------------------------------------------------------------------------------ - /// - /// Reapplies the localizations to all objects in the localization manager's cache of - /// localized objects. - /// - /// ------------------------------------------------------------------------------------ - public static void ReapplyLocalizationsToAllObjectsInAllManagers() - { - switch (TranslationMemoryKind) - { - default: - case TranslationMemory.XLiff: - LocalizationManagerInternal.ReapplyLocalizationsToAllObjectsInAllManagers(); - break; - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Reapplies the localizations to all objects in the localization manager's cache of - /// localized objects. - /// - /// ------------------------------------------------------------------------------------ - public static void ReapplyLocalizationsToAllObjects(string localizationManagerId) - { - switch (TranslationMemoryKind) - { - default: - case TranslationMemory.XLiff: - LocalizationManagerInternal.ReapplyLocalizationsToAllObjects(localizationManagerId); - break; - } - } - - public static string GetLocalizedToolTipForControl(Control ctrl) - { - switch (TranslationMemoryKind) - { - default: - case TranslationMemory.XLiff: - return LocalizationManagerInternal.GetLocalizedToolTipForControl(ctrl); - } - } - /// /// Merge the existing English l10n file into newly collected data and write the /// result to the temp directory. diff --git a/src/L10NSharp/LocalizationManagerInternal.cs b/src/L10NSharp/LocalizationManagerInternal.cs index c55f85c..59cdc84 100644 --- a/src/L10NSharp/LocalizationManagerInternal.cs +++ b/src/L10NSharp/LocalizationManagerInternal.cs @@ -5,21 +5,18 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel; -using System.Drawing; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; -using System.Windows.Forms; -using L10NSharp.UI; using L10NSharp.XLiffUtils; // ReSharper disable StaticMemberInGenericType - these static fields are parameter-independent namespace L10NSharp { - internal static class LocalizationManagerInternal + internal class LocalizationManagerInternal { - private static List s_fallbackLanguageIds = + protected static List s_fallbackLanguageIds = new List(new[] { LocalizationManager.kDefaultLang }); /// @@ -43,24 +40,20 @@ internal static class LocalizationManagerInternal internal static object LazyLoadLock = new object(); /// - /// Function to choose a fallback language during construction. Overridable by unit tests. + /// Function to choose a fallback language. Uses LocalizationManager's default. Overridable by unit tests. /// - internal static Func ChooseFallbackLanguage = (desiredUiLangId, icon) => + internal static string ChooseFallbackLanguage() { - using (var dlg = new LanguageChoosingDialog(L10NCultureInfo.GetCultureInfo(desiredUiLangId), icon)) - { - dlg.ShowDialog(); - return dlg.SelectedLanguage; - } - }; + return LocalizationManager.kDefaultLang; + } - private static readonly Dictionary> s_loadedManagers = + protected static readonly Dictionary> s_loadedManagers = new Dictionary>(); #region Static methods for creating a LocalizationManagerInternal - private static ILocalizationManager Create(string desiredUiLangId, string appId, + protected static ILocalizationManager Create(string desiredUiLangId, string appId, string appName, string relativeSettingPathForLocalizationFolder, - Icon applicationIcon, Func> createMethod) + Func> createMethod) { if (string.IsNullOrEmpty(relativeSettingPathForLocalizationFolder)) relativeSettingPathForLocalizationFolder = appName; @@ -78,8 +71,6 @@ private static ILocalizationManager Create(string desiredUiLangId, string appId, PreviouslyLoadedManagers.Remove(appId); } - lm.ApplicationIcon = applicationIcon; - if (string.IsNullOrEmpty(desiredUiLangId)) { desiredUiLangId = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; @@ -87,17 +78,17 @@ private static ILocalizationManager Create(string desiredUiLangId, string appId, if (!IsDesiredUiCultureAvailable(desiredUiLangId)) { - desiredUiLangId = ChooseFallbackLanguage(desiredUiLangId, applicationIcon); + desiredUiLangId = ChooseFallbackLanguage(); } - LocalizationManager.SetUILanguage(desiredUiLangId, false); + LocalizationManager.SetUILanguage(desiredUiLangId); LocalizationManager.EnableClickingOnControlToBringUpLocalizationDialog = true; return lm; } - private static bool IsDesiredUiCultureAvailable(string desiredUiLangId) + protected static bool IsDesiredUiCultureAvailable(string desiredUiLangId) { if (IsLocalizationAvailable(desiredUiLangId)) return true; @@ -154,7 +145,6 @@ private static bool IsDesiredUiCultureAvailable(string desiredUiLangId) public static ILocalizationManager CreateXliff(string desiredUiLangId, string appId, string appName, string appVersion, string directoryOfInstalledXliffFiles, string relativeSettingPathForLocalizationFolder, - Icon applicationIcon, IEnumerable additionalLocalizationMethods, params string[] namespaceBeginnings) { @@ -166,7 +156,7 @@ public static ILocalizationManager CreateXliff(string desiredUiLangId, string ap appId = Path.GetFileNameWithoutExtension(appId); return Create(desiredUiLangId, appId, appName, - relativeSettingPathForLocalizationFolder, applicationIcon, + relativeSettingPathForLocalizationFolder, directoryOfWritableXliffFiles => (ILocalizationManagerInternal) new XliffLocalizationManager(appId, origExeExtension, appName, appVersion, directoryOfInstalledXliffFiles, @@ -178,7 +168,7 @@ public static ILocalizationManager CreateXliff(string desiredUiLangId, string ap /// ------------------------------------------------------------------------------------ internal static Dictionary> LoadedManagers => s_loadedManagers; - private static HashSet PreviouslyLoadedManagers = new HashSet(); + protected static HashSet PreviouslyLoadedManagers = new HashSet(); internal static void RemoveManager(string id) { @@ -189,23 +179,6 @@ internal static void RemoveManager(string id) } } - internal static void ShowLocalizationDialogBox(IComponent component, - IWin32Window owner = null) - { - if (owner == null) - owner = (component as Control)?.FindForm(); - TipDialog.ShowAltShiftClickTip(owner); - LocalizeItemDlg.ShowDialog(GetLocalizationManagerForComponent(component), - component, false, owner); - } - - public static void ShowLocalizationDialogBox(string id, IWin32Window owner = null) - { - TipDialog.ShowAltShiftClickTip(owner); - LocalizeItemDlg.ShowDialog(GetLocalizationManagerForString(id), - id, false, owner); - } - /// ------------------------------------------------------------------------------------ internal static ILocalizationManagerInternal GetLocalizationManagerForComponent( IComponent component) @@ -451,36 +424,6 @@ public static int StringCount(string lang) #endregion - /// ------------------------------------------------------------------------------------ - /// - /// Reapplies the localizations to all objects in the localization manager's cache of - /// localized objects. - /// - /// ------------------------------------------------------------------------------------ - public static void ReapplyLocalizationsToAllObjectsInAllManagers() - { - if (LoadedManagers == null) - return; - - foreach (var lm in LoadedManagers.Values) - lm.ReapplyLocalizationsToAllComponents(); - } - /// ------------------------------------------------------------------------------------ - /// - /// Reapplies the localizations to all objects in the localization manager's cache of - /// localized objects. - /// - /// ------------------------------------------------------------------------------------ - public static void ReapplyLocalizationsToAllObjects(string localizationManagerId) - { - if (LoadedManagers == null) - return; - - if (LoadedManagers.TryGetValue(localizationManagerId, out var lm)) - lm.ReapplyLocalizationsToAllComponents(); - } - - /// ------------------------------------------------------------------------------------ /// /// Gets the text for the specified component. The englishText is returned when the text @@ -715,7 +658,7 @@ internal static string GetStringFromAnyLocalizationManager(string stringId, return null; } - private static string MapToExistingLanguageOrAddMapping(string stringId, string langId, + protected static string MapToExistingLanguageOrAddMapping(string stringId, string langId, out string languageIdUsed) { var realLangId = MapToExistingLanguageIfPossible(langId); @@ -769,20 +712,6 @@ public static string GetString(string stringId, string englishText, string comme public static string GetString(string stringId, string englishText, string comment, string englishToolTipText, string englishShortcutKey, IComponent component) { - if (component != null) - { - var lm = GetLocalizationManagerForComponent(component) ?? - GetLocalizationManagerForString(stringId); - - if (lm != null) - { - lm.RegisterComponentForLocalizing(component, stringId, englishText, - englishToolTipText, englishShortcutKey, comment); - - return lm.GetLocalizedString(stringId, englishText); - } - } - return GetStringFromAnyLocalizationManager(stringId) ?? LocalizationManager.StripOffLocalizationInfoFromText(englishText); } @@ -817,33 +746,6 @@ public static string GetString(string stringId, string englishText, string comme return stringFromAnyLocalizationManager; } - /// ------------------------------------------------------------------------------------ - public static string GetLocalizedToolTipForControl(Control ctrl) - { - var lm = GetLocalizationManagerForComponent(ctrl); - var topCtrl = GetRealTopLevelControl(ctrl); - if (topCtrl == null || lm == null) - return null; - - return lm.ToolTipCtrls.TryGetValue(topCtrl, out var ttctrl) ? ttctrl.GetToolTip(ctrl) - : null; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets the real top level control (using the control's TopLevelControl property - /// seems to return null until the control is on a form). - /// - /// ------------------------------------------------------------------------------------ - internal static Control GetRealTopLevelControl(Control ctrl) - { - var parentControl = ctrl; - while (parentControl.Parent != null) - parentControl = parentControl.Parent; - - return parentControl; - } - /// /// Merge the existing English translation file into newly collected data and write the result to the temp /// directory. diff --git a/src/L10NSharp/LocalizingInfo.cs b/src/L10NSharp/LocalizingInfo.cs index d151758..9972eb6 100644 --- a/src/L10NSharp/LocalizingInfo.cs +++ b/src/L10NSharp/LocalizingInfo.cs @@ -1,7 +1,5 @@ using System; using System.ComponentModel; -using System.Windows.Forms; -using L10NSharp.UI; namespace L10NSharp { @@ -94,21 +92,19 @@ internal enum UpdateFields /// ---------------------------------------------------------------------------------------- /// - /// This class is used to keep track of all the localization information (i.e. extended - /// properties of the LocalizationExtender) for a single object extended by the - /// LocalizationExtender. The type of object is either a Control or ToolStripItem and - /// the information kept track of is the text, tooltip, shortcut keys, localization - /// priority, comment and localization category. + /// This class is used to keep track, for a single object, of localization information that can + /// be determined without knowledge of Windows forms object types. It tracks text, + /// tooltip text, shortcut keys, localization priority, comment, and localization category. /// /// ---------------------------------------------------------------------------------------- public class LocalizingInfo { - private IComponent _component; - private string _id; - private string _text; - private string _shortcutKeys; - private string _comment; - private LocalizationCategory _category = LocalizationCategory.Unspecified; + protected IComponent _component; + protected string _id; + protected string _text; + protected string _shortcutKeys; + protected string _comment; + protected LocalizationCategory _category = LocalizationCategory.Unspecified; #region Constructors /// ------------------------------------------------------------------------------------ @@ -120,17 +116,7 @@ public LocalizingInfo(IComponent component, bool initTextFromObj) { _component = component; Priority = LocalizationPriority.Medium; - Category = GetCategory(_component); UpdateFields = UpdateFields.All; - if (initTextFromObj) - UpdateTextFromObject(); - } - - public void UpdateTextFromObject() - { - Text = LocalizationManager.StripOffLocalizationInfoFromText(_component is DataGridViewColumn - ? ((DataGridViewColumn) _component).HeaderText - : Utils.GetProperty(_component, "Text") as string); } /// ------------------------------------------------------------------------------------ @@ -158,97 +144,6 @@ public LocalizingInfo(string id) #endregion #region Methods for initializing the localization id. - - internal void CreateIdIfMissing(string prefixForId) - { - if (prefixForId == null) - prefixForId = ""; - if (string.IsNullOrEmpty(_id)) - _id = MakeId(_component, idPrefixFromFormExtender: prefixForId); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Sets the id. - /// - /// ------------------------------------------------------------------------------------ - internal static string MakeId(IComponent component, string idPrefixFromFormExtender = "") - { - if (idPrefixFromFormExtender == null) - idPrefixFromFormExtender = ""; - - idPrefixFromFormExtender = idPrefixFromFormExtender.Trim('.', ' '); - if (idPrefixFromFormExtender.Length > 0) - idPrefixFromFormExtender = idPrefixFromFormExtender + "."; - - if (component is Form) - { - Form frm = (Form)component; - return (frm.Site != null && frm.Site.DesignMode ? frm.Site.Name : frm.Name) + ".WindowTitle"; - } - - if (component is Control) - return idPrefixFromFormExtender+MakeIdForCtrl(component as Control); - - if (component is ColumnHeader) - return idPrefixFromFormExtender + MakeIdForColumnHeader((ColumnHeader)component); - - if (component is DataGridViewColumn) - return idPrefixFromFormExtender + MakeIdForDataGridViewColumn((DataGridViewColumn)component); - - if (component is ToolStripItem) - { - string formName = OwningFormName(component as ToolStripItem); - return idPrefixFromFormExtender + (formName ?? "Miscellaneous") + "." + ((ToolStripItem)component).Name; - } - - return null; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Sets the id for CTRL. - /// - /// ------------------------------------------------------------------------------------ - private static string MakeIdForCtrl(Control ctrl) - { - if (ctrl == null) - return null; - - if (ctrl.Text.StartsWith(LocalizationManager.kL10NPrefix)) - return GetIdFromText(ctrl.Text); - - string prefix = GetIdPrefix(ctrl); - if (string.IsNullOrEmpty(prefix)) - return ctrl.Name; - - //return (string.IsNullOrEmpty(prefix) ? string.Empty : prefix + "." + ctrl.Name); - return prefix.Trim(new char[] { '.' }) + "." + ctrl.Name.Trim(new char[] { '.' }); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Makes an id for a column header. - /// - /// ------------------------------------------------------------------------------------ - private static string MakeIdForColumnHeader(ColumnHeader hdr) - { - return (hdr == null ? null : GetIdFromText(hdr.Name)); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Makes an id for a DataGridView column. - /// Note that in order to have a DataGridViewColumn header be localizable, one must create the HeaderText - /// in the following format: _L10N_:{ID}!{EnglishName} - /// - /// ------------------------------------------------------------------------------------ - private static string MakeIdForDataGridViewColumn(DataGridViewColumn col) - { - return (col == null || !col.HeaderText.StartsWith(LocalizationManager.kL10NPrefix) ? - null : GetIdFromText(col.HeaderText)); - } - /// ------------------------------------------------------------------------------------ public static string GetIdFromText(string text) { @@ -261,95 +156,6 @@ public static string GetIdFromText(string text) return (i < 0 ? text : text.Substring(0, i)); } - /// ------------------------------------------------------------------------------------ - /// - /// Tries to get the name of the form that hosts the specified control. That name is - /// used as the prefix for a localization id. - /// - /// ------------------------------------------------------------------------------------ - private static string GetIdPrefix(Control control) - { - if (control == null) - return "Miscellaneous"; - if (control.Parent == null) - return ""; - - while (control.Parent != null && - !control.Parent.GetType().FullName.StartsWith("System.Windows.Forms.Design")) - { - control = control.Parent; - } - - - return (control.Site != null && control.Site.DesignMode ? control.Site.Name : control.Name); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets the name of the form to which the specified ToolStripItem belongs. - /// - /// ------------------------------------------------------------------------------------ - private static string OwningFormName(ToolStripItem tsItem) - { - if (tsItem != null) - { - var item = tsItem; - while (item.OwnerItem != null) - item = item.OwnerItem; - - if (item.Owner != null) - { - var frm = item.Owner.FindForm(); - if (frm != null) - return (frm.Site != null && frm.Site.DesignMode ? frm.Site.Name : frm.Name); - } - } - - return string.Empty; - } - - #endregion - - #region Method for initializinig the category - /// ------------------------------------------------------------------------------------ - /// - /// Returns the localization category for the specified IComponent object. - /// - /// ------------------------------------------------------------------------------------ - private static LocalizationCategory GetCategory(IComponent component) - { - if (component is ILocalizableComponent) - return LocalizationCategory.LocalizableComponent; - if (component is ToolStripMenuItem) - return LocalizationCategory.MenuItem; - if (component is ToolStripItem) - return LocalizationCategory.ToolbarOrStatusBarItem; - if (component is Button) - return LocalizationCategory.Button; - if (component is TextBox) - return LocalizationCategory.TextBox; - if (component is LinkLabel) - return LocalizationCategory.LinkLabel; - if (component is Label) - return LocalizationCategory.Label; - if (component is ComboBox) - return LocalizationCategory.ComboBox; - if (component is RadioButton) - return LocalizationCategory.RadioButton; - if (component is CheckBox) - return LocalizationCategory.CheckBox; - if (component is Form) - return LocalizationCategory.WindowOrDialog; - if (component is TabPage) - return LocalizationCategory.TabPage; - if (component is ColumnHeader) - return LocalizationCategory.ListViewColumnHeading; - if (component is DataGridViewColumn) - return LocalizationCategory.ListViewColumnHeading; - - return LocalizationCategory.Other; - } - #endregion #region Properties @@ -376,7 +182,7 @@ public string Id get { if (string.IsNullOrEmpty(_id)) - _id = MakeId(_component); + _id = null; return _id; } @@ -405,8 +211,6 @@ internal IComponent Component set { _component = value; - if (_component != null && string.IsNullOrEmpty(_id)) - Id = MakeId(_component); } } @@ -483,25 +287,7 @@ public LocalizationCategory Category /// Gets or sets the shortcutKeys. /// /// ------------------------------------------------------------------------------------ - public string ShortcutKeys - { - get - { - if (_shortcutKeys == null && _component != null) - { - object keysobj = Utils.GetProperty(_component, "ShortcutKeys"); - if (keysobj != null && keysobj.GetType() == typeof(Keys)) - { - Keys keys = (Keys)keysobj; - _shortcutKeys = (keys == Keys.None ? - string.Empty : ShortcutKeysEditor.KeysToString(keys)); - } - } - - return _shortcutKeys; - } - set { _shortcutKeys = (value == Keys.None.ToString() ? string.Empty : value); } - } + public string ShortcutKeys; /// ------------------------------------------------------------------------------------ /// diff --git a/src/L10NSharp/Properties/AssemblyInfo.cs b/src/L10NSharp/Properties/AssemblyInfo.cs index 403480d..124e4c7 100644 --- a/src/L10NSharp/Properties/AssemblyInfo.cs +++ b/src/L10NSharp/Properties/AssemblyInfo.cs @@ -7,6 +7,8 @@ // sn -tp // (use the full public key, not the public key token!) -[assembly: InternalsVisibleTo("L10NSharpTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010019cae48c6e5703818db31fcca17b87012eef38df95e3961c59b035190eace2c4ee5cfa1a258b84867c7549f60eec00ec1e0004c2ed224457128e841311cea0f5a05c3d69b3dfcb7422b214febce6e06c83ce4d29c62f36a7fd5564e922338c800372a5ec09638671b4db1fb33ccbb1dc48d8122ffe0d30dadbfbf325f65437b2")] +[assembly: InternalsVisibleTo("L10NSharp.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010019cae48c6e5703818db31fcca17b87012eef38df95e3961c59b035190eace2c4ee5cfa1a258b84867c7549f60eec00ec1e0004c2ed224457128e841311cea0f5a05c3d69b3dfcb7422b214febce6e06c83ce4d29c62f36a7fd5564e922338c800372a5ec09638671b4db1fb33ccbb1dc48d8122ffe0d30dadbfbf325f65437b2")] [assembly: InternalsVisibleTo("ExtractXliff, PublicKey=002400000480000094000000060200000024000052534131000400000100010019cae48c6e5703818db31fcca17b87012eef38df95e3961c59b035190eace2c4ee5cfa1a258b84867c7549f60eec00ec1e0004c2ed224457128e841311cea0f5a05c3d69b3dfcb7422b214febce6e06c83ce4d29c62f36a7fd5564e922338c800372a5ec09638671b4db1fb33ccbb1dc48d8122ffe0d30dadbfbf325f65437b2")] [assembly: InternalsVisibleTo("CheckOrFixXliff, PublicKey=002400000480000094000000060200000024000052534131000400000100010019cae48c6e5703818db31fcca17b87012eef38df95e3961c59b035190eace2c4ee5cfa1a258b84867c7549f60eec00ec1e0004c2ed224457128e841311cea0f5a05c3d69b3dfcb7422b214febce6e06c83ce4d29c62f36a7fd5564e922338c800372a5ec09638671b4db1fb33ccbb1dc48d8122ffe0d30dadbfbf325f65437b2")] +[assembly: InternalsVisibleTo("L10NSharp.Windows.Forms, PublicKey=002400000480000094000000060200000024000052534131000400000100010019cae48c6e5703818db31fcca17b87012eef38df95e3961c59b035190eace2c4ee5cfa1a258b84867c7549f60eec00ec1e0004c2ed224457128e841311cea0f5a05c3d69b3dfcb7422b214febce6e06c83ce4d29c62f36a7fd5564e922338c800372a5ec09638671b4db1fb33ccbb1dc48d8122ffe0d30dadbfbf325f65437b2")] +[assembly: InternalsVisibleTo("L10NSharp.Windows.Forms.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010019cae48c6e5703818db31fcca17b87012eef38df95e3961c59b035190eace2c4ee5cfa1a258b84867c7549f60eec00ec1e0004c2ed224457128e841311cea0f5a05c3d69b3dfcb7422b214febce6e06c83ce4d29c62f36a7fd5564e922338c800372a5ec09638671b4db1fb33ccbb1dc48d8122ffe0d30dadbfbf325f65437b2")] diff --git a/src/L10NSharp/Properties/Resources.resx b/src/L10NSharp/Properties/Resources.resx deleted file mode 100644 index f26f49d..0000000 --- a/src/L10NSharp/Properties/Resources.resx +++ /dev/null @@ -1,152 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - ..\Resources\bing.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\Copy_Translation.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\Copy_Translation (toolbar).png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\Google.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\Move_Next.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\Move_Previous.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\Move_down.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\Move_up.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\Move.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - - ..\Resources\SelectAllRows.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - \ No newline at end of file diff --git a/src/L10NSharp/Resources/Copy_Translation (toolbar).png b/src/L10NSharp/Resources/Copy_Translation (toolbar).png deleted file mode 100644 index 6dc60d8..0000000 Binary files a/src/L10NSharp/Resources/Copy_Translation (toolbar).png and /dev/null differ diff --git a/src/L10NSharp/Resources/Copy_Translation.png b/src/L10NSharp/Resources/Copy_Translation.png deleted file mode 100644 index 4b15498..0000000 Binary files a/src/L10NSharp/Resources/Copy_Translation.png and /dev/null differ diff --git a/src/L10NSharp/Resources/Google.png b/src/L10NSharp/Resources/Google.png deleted file mode 100644 index 8a7439f..0000000 Binary files a/src/L10NSharp/Resources/Google.png and /dev/null differ diff --git a/src/L10NSharp/Resources/Move.png b/src/L10NSharp/Resources/Move.png deleted file mode 100644 index 5731d8f..0000000 Binary files a/src/L10NSharp/Resources/Move.png and /dev/null differ diff --git a/src/L10NSharp/Resources/Move_Next.png b/src/L10NSharp/Resources/Move_Next.png deleted file mode 100644 index fd4621c..0000000 Binary files a/src/L10NSharp/Resources/Move_Next.png and /dev/null differ diff --git a/src/L10NSharp/Resources/Move_Previous.png b/src/L10NSharp/Resources/Move_Previous.png deleted file mode 100644 index 1019521..0000000 Binary files a/src/L10NSharp/Resources/Move_Previous.png and /dev/null differ diff --git a/src/L10NSharp/Resources/Move_down.png b/src/L10NSharp/Resources/Move_down.png deleted file mode 100644 index fcff222..0000000 Binary files a/src/L10NSharp/Resources/Move_down.png and /dev/null differ diff --git a/src/L10NSharp/Resources/Move_up.png b/src/L10NSharp/Resources/Move_up.png deleted file mode 100644 index d39a96b..0000000 Binary files a/src/L10NSharp/Resources/Move_up.png and /dev/null differ diff --git a/src/L10NSharp/Resources/SelectAllRows.png b/src/L10NSharp/Resources/SelectAllRows.png deleted file mode 100644 index 560a458..0000000 Binary files a/src/L10NSharp/Resources/SelectAllRows.png and /dev/null differ diff --git a/src/L10NSharp/Resources/bing.png b/src/L10NSharp/Resources/bing.png deleted file mode 100644 index 91884f3..0000000 Binary files a/src/L10NSharp/Resources/bing.png and /dev/null differ diff --git a/src/L10NSharp/UI/LocalizeItemDlg.Designer.cs b/src/L10NSharp/UI/LocalizeItemDlg.Designer.cs deleted file mode 100644 index 3a76700..0000000 --- a/src/L10NSharp/UI/LocalizeItemDlg.Designer.cs +++ /dev/null @@ -1,1061 +0,0 @@ -namespace L10NSharp.UI -{ - partial class LocalizeItemDlg - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); - this._textBoxTgtTranslation = new System.Windows.Forms.TextBox(); - this._labelStringId = new System.Windows.Forms.Label(); - this._buttonOK = new System.Windows.Forms.Button(); - this._buttonCancel = new System.Windows.Forms.Button(); - this._labelStringIdValue = new System.Windows.Forms.Label(); - this._groupBoxComment = new System.Windows.Forms.GroupBox(); - this._textBoxComment = new System.Windows.Forms.TextBox(); - this._groupBoxImage = new System.Windows.Forms.GroupBox(); - this._pictureImage = new System.Windows.Forms.PictureBox(); - this.splitContainer = new System.Windows.Forms.SplitContainer(); - this._treeView = new System.Windows.Forms.TreeView(); - this._toolStripLeftSide = new System.Windows.Forms.ToolStrip(); - this._labelGroups = new System.Windows.Forms.ToolStripLabel(); - this._buttonMoveNext = new L10NSharp.UI.XButton(); - this._grid = new L10NSharp.UI.LmGrid(); - this._colId = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this._colSourceText = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this._colTargetText = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this._colSrcToolTip = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this._colTgtToolTip = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this._colComments = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this._buttonMovePrev = new L10NSharp.UI.XButton(); - this._toolStripRightSide = new System.Windows.Forms.ToolStrip(); - this._buttonBingTranslator = new System.Windows.Forms.ToolStripSplitButton(); - this._menuTranslateUsingBing = new System.Windows.Forms.ToolStripMenuItem(); - this._menuEditSourceAndTranslate = new System.Windows.Forms.ToolStripMenuItem(); - this._comboTargetLang = new System.Windows.Forms.ToolStripComboBox(); - this._labelTargetLang = new System.Windows.Forms.ToolStripLabel(); - this._comboSourceLang = new System.Windows.Forms.ToolStripComboBox(); - this._labelSourceLang = new System.Windows.Forms.ToolStripLabel(); - this._tableLayout = new System.Windows.Forms.TableLayoutPanel(); - this._panelIdentifier = new System.Windows.Forms.Panel(); - this.btnCopyToolTip = new L10NSharp.UI.XButton(); - this.btnCopyShortcutKeys = new L10NSharp.UI.XButton(); - this.btnCopyText = new L10NSharp.UI.XButton(); - this._panelTargetText = new System.Windows.Forms.Panel(); - this._groupBoxTgtTranslation = new System.Windows.Forms.GroupBox(); - this._labelTgtShortcutKeys = new System.Windows.Forms.Label(); - this._shortcutKeysDropDown = new L10NSharp.UI.ShortcutKeysDropDown(); - this._labelTgtToolTip = new System.Windows.Forms.Label(); - this._textBoxTgtToolTip = new System.Windows.Forms.TextBox(); - this._panelSourceText = new System.Windows.Forms.Panel(); - this._groupBoxSrcTranslation = new System.Windows.Forms.GroupBox(); - this._textBoxSrcTranslation = new System.Windows.Forms.TextBox(); - this._textBoxSrcShortcutKeys = new System.Windows.Forms.TextBox(); - this._labelSrcShortcutKeys = new System.Windows.Forms.Label(); - this._labelSrcToolTip = new System.Windows.Forms.Label(); - this._textBoxSrcToolTip = new System.Windows.Forms.TextBox(); - this._panelButtons = new System.Windows.Forms.Panel(); - this._howToDistribute = new System.Windows.Forms.LinkLabel(); - this._buttonFallbackLanguages = new System.Windows.Forms.Button(); - this.toolStrip = new System.Windows.Forms.ToolStrip(); - this.tbbCopy = new System.Windows.Forms.ToolStripDropDownButton(); - this.mnuCopyText = new System.Windows.Forms.ToolStripMenuItem(); - this.mnuCopyToolTip = new System.Windows.Forms.ToolStripMenuItem(); - this.mnuCopyShortcutKeys = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); - this.mnuCopyAll = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); - this.tbbGoogleTranslate = new System.Windows.Forms.ToolStripButton(); - this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); - this.tcboSearch = new System.Windows.Forms.ToolStripComboBox(); - this.tblblSearch = new System.Windows.Forms.ToolStripLabel(); - this._tooltip = new System.Windows.Forms.ToolTip(this.components); - this._statusStrip = new System.Windows.Forms.StatusStrip(); - this._labelCount = new System.Windows.Forms.ToolStripStatusLabel(); - this._progressBar = new System.Windows.Forms.ToolStripProgressBar(); - this._groupBoxComment.SuspendLayout(); - this._groupBoxImage.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this._pictureImage)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); - this.splitContainer.Panel1.SuspendLayout(); - this.splitContainer.Panel2.SuspendLayout(); - this.splitContainer.SuspendLayout(); - this._toolStripLeftSide.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this._grid)).BeginInit(); - this._toolStripRightSide.SuspendLayout(); - this._tableLayout.SuspendLayout(); - this._panelIdentifier.SuspendLayout(); - this._panelTargetText.SuspendLayout(); - this._groupBoxTgtTranslation.SuspendLayout(); - this._panelSourceText.SuspendLayout(); - this._groupBoxSrcTranslation.SuspendLayout(); - this._panelButtons.SuspendLayout(); - this.toolStrip.SuspendLayout(); - this._statusStrip.SuspendLayout(); - this.SuspendLayout(); - // - // _textBoxTgtTranslation - // - this._textBoxTgtTranslation.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this._textBoxTgtTranslation.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._textBoxTgtTranslation.Location = new System.Drawing.Point(6, 18); - this._textBoxTgtTranslation.Multiline = true; - this._textBoxTgtTranslation.Name = "_textBoxTgtTranslation"; - this._textBoxTgtTranslation.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this._textBoxTgtTranslation.Size = new System.Drawing.Size(314, 37); - this._textBoxTgtTranslation.TabIndex = 0; - // - // _labelStringId - // - this._labelStringId.AutoSize = true; - this._labelStringId.BackColor = System.Drawing.Color.Transparent; - this._labelStringId.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._labelStringId.Location = new System.Drawing.Point(6, 14); - this._labelStringId.Name = "_labelStringId"; - this._labelStringId.Size = new System.Drawing.Size(93, 15); - this._labelStringId.TabIndex = 0; - this._labelStringId.Text = "Item Identifier:"; - // - // _buttonOK - // - this._buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this._buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK; - this._buttonOK.Location = new System.Drawing.Point(662, 7); - this._buttonOK.Name = "_buttonOK"; - this._buttonOK.Size = new System.Drawing.Size(75, 26); - this._buttonOK.TabIndex = 1; - this._buttonOK.Text = "OK"; - this._buttonOK.UseVisualStyleBackColor = true; - // - // _buttonCancel - // - this._buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this._buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this._buttonCancel.Location = new System.Drawing.Point(743, 7); - this._buttonCancel.Name = "_buttonCancel"; - this._buttonCancel.Size = new System.Drawing.Size(75, 26); - this._buttonCancel.TabIndex = 2; - this._buttonCancel.Text = "Cancel"; - this._buttonCancel.UseVisualStyleBackColor = true; - // - // _labelStringIdValue - // - this._labelStringIdValue.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this._labelStringIdValue.AutoEllipsis = true; - this._labelStringIdValue.BackColor = System.Drawing.Color.Transparent; - this._labelStringIdValue.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._labelStringIdValue.ForeColor = System.Drawing.Color.MediumBlue; - this._labelStringIdValue.Location = new System.Drawing.Point(18, 32); - this._labelStringIdValue.Name = "_labelStringIdValue"; - this._labelStringIdValue.Size = new System.Drawing.Size(240, 32); - this._labelStringIdValue.TabIndex = 1; - this._labelStringIdValue.Text = "#"; - // - // _groupBoxComment - // - this._groupBoxComment.Controls.Add(this._textBoxComment); - this._groupBoxComment.Dock = System.Windows.Forms.DockStyle.Fill; - this._groupBoxComment.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._groupBoxComment.Location = new System.Drawing.Point(3, 257); - this._groupBoxComment.Margin = new System.Windows.Forms.Padding(3, 3, 3, 0); - this._groupBoxComment.Name = "_groupBoxComment"; - this._groupBoxComment.Padding = new System.Windows.Forms.Padding(5, 3, 2, 2); - this._groupBoxComment.Size = new System.Drawing.Size(326, 70); - this._groupBoxComment.TabIndex = 1; - this._groupBoxComment.TabStop = false; - this._groupBoxComment.Text = "Comment"; - // - // _textBoxComment - // - this._textBoxComment.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this._textBoxComment.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._textBoxComment.Location = new System.Drawing.Point(5, 19); - this._textBoxComment.Multiline = true; - this._textBoxComment.Name = "_textBoxComment"; - this._textBoxComment.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this._textBoxComment.Size = new System.Drawing.Size(315, 46); - this._textBoxComment.TabIndex = 0; - // - // _groupBoxImage - // - this._groupBoxImage.Controls.Add(this._pictureImage); - this._groupBoxImage.Dock = System.Windows.Forms.DockStyle.Right; - this._groupBoxImage.Location = new System.Drawing.Point(264, 0); - this._groupBoxImage.Name = "_groupBoxImage"; - this._groupBoxImage.Size = new System.Drawing.Size(62, 68); - this._groupBoxImage.TabIndex = 2; - this._groupBoxImage.TabStop = false; - // - // _pictureImage - // - this._pictureImage.Location = new System.Drawing.Point(6, 14); - this._pictureImage.Name = "_pictureImage"; - this._pictureImage.Size = new System.Drawing.Size(50, 50); - this._pictureImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this._pictureImage.TabIndex = 14; - this._pictureImage.TabStop = false; - // - // splitContainer - // - this.splitContainer.BackColor = System.Drawing.Color.Transparent; - this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer.Location = new System.Drawing.Point(0, 0); - this.splitContainer.Name = "splitContainer"; - // - // splitContainer.Panel1 - // - this.splitContainer.Panel1.Controls.Add(this._treeView); - this.splitContainer.Panel1.Controls.Add(this._toolStripLeftSide); - this.splitContainer.Panel1.Padding = new System.Windows.Forms.Padding(8, 7, 0, 0); - // - // splitContainer.Panel2 - // - this.splitContainer.Panel2.Controls.Add(this._buttonMoveNext); - this.splitContainer.Panel2.Controls.Add(this._grid); - this.splitContainer.Panel2.Controls.Add(this._buttonMovePrev); - this.splitContainer.Panel2.Controls.Add(this._toolStripRightSide); - this.splitContainer.Panel2.Controls.Add(this._tableLayout); - this.splitContainer.Panel2.Padding = new System.Windows.Forms.Padding(0, 7, 5, 0); - this.splitContainer.Size = new System.Drawing.Size(826, 456); - this.splitContainer.SplitterDistance = 269; - this.splitContainer.SplitterWidth = 6; - this.splitContainer.TabIndex = 0; - // - // _treeView - // - this._treeView.AllowDrop = true; - this._treeView.Dock = System.Windows.Forms.DockStyle.Fill; - this._treeView.HideSelection = false; - this._treeView.Location = new System.Drawing.Point(8, 37); - this._treeView.Name = "_treeView"; - this._treeView.Size = new System.Drawing.Size(261, 419); - this._treeView.TabIndex = 1; - this._treeView.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.HandleTreeViewBeforeSelect); - // - // _toolStripLeftSide - // - this._toolStripLeftSide.AutoSize = false; - this._toolStripLeftSide.BackColor = System.Drawing.Color.LightSteelBlue; - this._toolStripLeftSide.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; - this._toolStripLeftSide.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this._labelGroups}); - this._toolStripLeftSide.Location = new System.Drawing.Point(8, 7); - this._toolStripLeftSide.Name = "_toolStripLeftSide"; - this._toolStripLeftSide.Size = new System.Drawing.Size(261, 30); - this._toolStripLeftSide.TabIndex = 0; - this._toolStripLeftSide.Text = "toolStrip2"; - // - // _labelGroups - // - this._labelGroups.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._labelGroups.Name = "_labelGroups"; - this._labelGroups.Size = new System.Drawing.Size(50, 27); - this._labelGroups.Text = "Groups:"; - // - // _buttonMoveNext - // - this._buttonMoveNext.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this._buttonMoveNext.BackColor = System.Drawing.Color.Transparent; - this._buttonMoveNext.CanBeChecked = false; - this._buttonMoveNext.Checked = false; - this._buttonMoveNext.DrawEmpty = false; - this._buttonMoveNext.DrawLeftArrowButton = false; - this._buttonMoveNext.DrawRightArrowButton = false; - this._buttonMoveNext.Font = new System.Drawing.Font("Marlett", 9F); - this._buttonMoveNext.Image = global::L10NSharp.Properties.Resources.kimidMoveNext; - this._buttonMoveNext.Location = new System.Drawing.Point(403, 133); - this._buttonMoveNext.Name = "_buttonMoveNext"; - this._buttonMoveNext.Size = new System.Drawing.Size(20, 20); - this._buttonMoveNext.TabIndex = 2; - this._tooltip.SetToolTip(this._buttonMoveNext, "Move to next localizable string"); - this._buttonMoveNext.Visible = false; - this._buttonMoveNext.Click += new System.EventHandler(this._buttonMoveNext_Click); - // - // _grid - // - this._grid.AllowUserToAddRows = false; - this._grid.AllowUserToDeleteRows = false; - this._grid.AllowUserToOrderColumns = true; - this._grid.AllowUserToResizeRows = false; - this._grid.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders; - this._grid.BackgroundColor = System.Drawing.SystemColors.Window; - this._grid.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; - this._grid.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.Disable; - this._grid.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; - dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI Semibold", 8.25F, System.Drawing.FontStyle.Bold); - dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this._grid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; - this._grid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; - this._grid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this._colId, - this._colSourceText, - this._colTargetText, - this._colSrcToolTip, - this._colTgtToolTip, - this._colComments}); - this._grid.DrawTextBoxEditControlBorder = false; - this._grid.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; - this._grid.Font = new System.Drawing.Font("Segoe UI Semibold", 8.25F, System.Drawing.FontStyle.Bold); - this._grid.FullRowFocusRectangleColor = System.Drawing.SystemColors.ControlDark; - this._grid.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(225)))), ((int)(((byte)(225)))), ((int)(((byte)(225))))); - this._grid.IsDirty = true; - this._grid.Location = new System.Drawing.Point(13, 370); - this._grid.MultiSelect = false; - this._grid.Name = "_grid"; - this._grid.PaintFullRowFocusRectangle = true; - this._grid.PaintHeaderAcrossFullGridWidth = true; - this._grid.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; - this._grid.RowHeadersWidth = 22; - this._grid.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; - this._grid.SelectedCellBackColor = System.Drawing.Color.Empty; - this._grid.SelectedCellForeColor = System.Drawing.Color.Empty; - this._grid.SelectedRowBackColor = System.Drawing.Color.Empty; - this._grid.SelectedRowForeColor = System.Drawing.Color.Empty; - this._grid.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this._grid.ShowWaterMarkWhenDirty = false; - this._grid.Size = new System.Drawing.Size(514, 63); - this._grid.TabIndex = 1; - this._grid.TextBoxEditControlBorderColor = System.Drawing.Color.Silver; - this._grid.VirtualMode = true; - this._grid.WaterMark = "!"; - this._grid.CurrentRowChanged += new System.EventHandler(this.HandleGridCurrentRowChanged); - this._grid.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.HandleGridCellFormatting); - this._grid.CellMouseEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.HandleGridCellMouseEnter); - this._grid.CellMouseLeave += new System.Windows.Forms.DataGridViewCellEventHandler(this.HandleGridCellMouseLeave); - this._grid.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.HandleGridCellPainting); - this._grid.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.HandleGridCellValueNeeded); - this._grid.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.HandleGridCellValuePushed); - this._grid.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.HandleColumnHeaderMouseClick); - // - // _colId - // - this._colId.HeaderText = "Identifier"; - this._colId.Name = "_colId"; - this._colId.ReadOnly = true; - // - // _colSourceText - // - this._colSourceText.HeaderText = "#"; - this._colSourceText.Name = "_colSourceText"; - this._colSourceText.ReadOnly = true; - // - // _colTargetText - // - this._colTargetText.HeaderText = "#"; - this._colTargetText.Name = "_colTargetText"; - // - // _colSrcToolTip - // - this._colSrcToolTip.HeaderText = "#"; - this._colSrcToolTip.Name = "_colSrcToolTip"; - this._colSrcToolTip.ReadOnly = true; - // - // _colTgtToolTip - // - this._colTgtToolTip.HeaderText = "#"; - this._colTgtToolTip.Name = "_colTgtToolTip"; - // - // _colComments - // - this._colComments.HeaderText = "Comments"; - this._colComments.Name = "_colComments"; - // - // _buttonMovePrev - // - this._buttonMovePrev.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this._buttonMovePrev.BackColor = System.Drawing.Color.Transparent; - this._buttonMovePrev.CanBeChecked = false; - this._buttonMovePrev.Checked = false; - this._buttonMovePrev.DrawEmpty = false; - this._buttonMovePrev.DrawLeftArrowButton = false; - this._buttonMovePrev.DrawRightArrowButton = false; - this._buttonMovePrev.Font = new System.Drawing.Font("Marlett", 9F); - this._buttonMovePrev.Image = global::L10NSharp.Properties.Resources.kimidMovePrevious; - this._buttonMovePrev.Location = new System.Drawing.Point(403, 107); - this._buttonMovePrev.Name = "_buttonMovePrev"; - this._buttonMovePrev.Size = new System.Drawing.Size(20, 20); - this._buttonMovePrev.TabIndex = 1; - this._tooltip.SetToolTip(this._buttonMovePrev, "Move to previous localizable string"); - this._buttonMovePrev.Visible = false; - this._buttonMovePrev.Click += new System.EventHandler(this._buttonMovePrev_Click); - // - // _toolStripRightSide - // - this._toolStripRightSide.AutoSize = false; - this._toolStripRightSide.BackColor = System.Drawing.Color.LightSteelBlue; - this._toolStripRightSide.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; - this._toolStripRightSide.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this._buttonBingTranslator, - this._comboTargetLang, - this._labelTargetLang, - this._comboSourceLang, - this._labelSourceLang}); - this._toolStripRightSide.Location = new System.Drawing.Point(0, 7); - this._toolStripRightSide.Name = "_toolStripRightSide"; - this._toolStripRightSide.Size = new System.Drawing.Size(546, 30); - this._toolStripRightSide.TabIndex = 2; - this._toolStripRightSide.Text = "toolStrip1"; - // - // _buttonBingTranslator - // - this._buttonBingTranslator.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this._buttonBingTranslator.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this._menuTranslateUsingBing, - this._menuEditSourceAndTranslate}); - this._buttonBingTranslator.Enabled = false; - this._buttonBingTranslator.Image = global::L10NSharp.Properties.Resources.kimidBing; - this._buttonBingTranslator.ImageTransparentColor = System.Drawing.Color.Magenta; - this._buttonBingTranslator.Margin = new System.Windows.Forms.Padding(7, 1, 5, 2); - this._buttonBingTranslator.Name = "_buttonBingTranslator"; - this._buttonBingTranslator.Size = new System.Drawing.Size(32, 27); - this._buttonBingTranslator.ToolTipText = "Translate Using Bing"; - this._buttonBingTranslator.ButtonClick += new System.EventHandler(this.HandleTranslatorServiceButtonClick); - // - // _menuTranslateUsingBing - // - this._menuTranslateUsingBing.Name = "_menuTranslateUsingBing"; - this._menuTranslateUsingBing.Size = new System.Drawing.Size(265, 22); - this._menuTranslateUsingBing.Text = "Translate Using Bing"; - this._menuTranslateUsingBing.Click += new System.EventHandler(this.HandleTranslatorServiceButtonClick); - // - // _menuEditSourceAndTranslate - // - this._menuEditSourceAndTranslate.Name = "_menuEditSourceAndTranslate"; - this._menuEditSourceAndTranslate.Size = new System.Drawing.Size(265, 22); - this._menuEditSourceAndTranslate.Text = "Edit Source && Translate Using Bing..."; - this._menuEditSourceAndTranslate.Click += new System.EventHandler(this.HandleEditSourceBeforeTranslatingUsingBing); - // - // _comboTargetLang - // - this._comboTargetLang.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; - this._comboTargetLang.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this._comboTargetLang.Margin = new System.Windows.Forms.Padding(1, 0, 8, 0); - this._comboTargetLang.Name = "_comboTargetLang"; - this._comboTargetLang.Size = new System.Drawing.Size(130, 30); - this._comboTargetLang.SelectedIndexChanged += new System.EventHandler(this.HandleTargetLangChanged); - // - // _labelTargetLang - // - this._labelTargetLang.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; - this._labelTargetLang.Margin = new System.Windows.Forms.Padding(8, 1, 0, 2); - this._labelTargetLang.Name = "_labelTargetLang"; - this._labelTargetLang.Size = new System.Drawing.Size(98, 27); - this._labelTargetLang.Text = "Target Language:"; - // - // _comboSourceLang - // - this._comboSourceLang.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; - this._comboSourceLang.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this._comboSourceLang.Name = "_comboSourceLang"; - this._comboSourceLang.Size = new System.Drawing.Size(130, 30); - this._comboSourceLang.SelectedIndexChanged += new System.EventHandler(this.HandleSourceLangChanged); - // - // _labelSourceLang - // - this._labelSourceLang.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; - this._labelSourceLang.Margin = new System.Windows.Forms.Padding(5, 1, 0, 2); - this._labelSourceLang.Name = "_labelSourceLang"; - this._labelSourceLang.Size = new System.Drawing.Size(101, 27); - this._labelSourceLang.Text = "Source Language:"; - // - // _tableLayout - // - this._tableLayout.ColumnCount = 1; - this._tableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this._tableLayout.Controls.Add(this._panelIdentifier, 0, 0); - this._tableLayout.Controls.Add(this._groupBoxComment, 0, 3); - this._tableLayout.Controls.Add(this._panelTargetText, 0, 2); - this._tableLayout.Controls.Add(this._panelSourceText, 0, 1); - this._tableLayout.Location = new System.Drawing.Point(13, 36); - this._tableLayout.Margin = new System.Windows.Forms.Padding(0); - this._tableLayout.Name = "_tableLayout"; - this._tableLayout.RowCount = 4; - this._tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 74F)); - this._tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 45F)); - this._tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 55F)); - this._tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 72F)); - this._tableLayout.Size = new System.Drawing.Size(332, 327); - this._tableLayout.TabIndex = 0; - // - // _panelIdentifier - // - this._panelIdentifier.Controls.Add(this.btnCopyToolTip); - this._panelIdentifier.Controls.Add(this._labelStringIdValue); - this._panelIdentifier.Controls.Add(this.btnCopyShortcutKeys); - this._panelIdentifier.Controls.Add(this.btnCopyText); - this._panelIdentifier.Controls.Add(this._labelStringId); - this._panelIdentifier.Controls.Add(this._groupBoxImage); - this._panelIdentifier.Dock = System.Windows.Forms.DockStyle.Fill; - this._panelIdentifier.Location = new System.Drawing.Point(3, 3); - this._panelIdentifier.Name = "_panelIdentifier"; - this._panelIdentifier.Size = new System.Drawing.Size(326, 68); - this._panelIdentifier.TabIndex = 0; - // - // btnCopyToolTip - // - this.btnCopyToolTip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnCopyToolTip.BackColor = System.Drawing.Color.Transparent; - this.btnCopyToolTip.CanBeChecked = false; - this.btnCopyToolTip.Checked = false; - this.btnCopyToolTip.DrawEmpty = false; - this.btnCopyToolTip.DrawLeftArrowButton = false; - this.btnCopyToolTip.DrawRightArrowButton = false; - this.btnCopyToolTip.Font = new System.Drawing.Font("Marlett", 9F); - this.btnCopyToolTip.Image = global::L10NSharp.Properties.Resources.kimidCopyTranslation; - this.btnCopyToolTip.Location = new System.Drawing.Point(128, 6); - this.btnCopyToolTip.Name = "btnCopyToolTip"; - this.btnCopyToolTip.Size = new System.Drawing.Size(11, 15); - this.btnCopyToolTip.TabIndex = 5; - this._tooltip.SetToolTip(this.btnCopyToolTip, "Copy Source Tool Tip to Target (Ctrl+Alt+O)"); - this.btnCopyToolTip.Visible = false; - this.btnCopyToolTip.Click += new System.EventHandler(this.btnCopyToolTip_Click); - // - // btnCopyShortcutKeys - // - this.btnCopyShortcutKeys.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnCopyShortcutKeys.BackColor = System.Drawing.Color.Transparent; - this.btnCopyShortcutKeys.CanBeChecked = false; - this.btnCopyShortcutKeys.Checked = false; - this.btnCopyShortcutKeys.DrawEmpty = false; - this.btnCopyShortcutKeys.DrawLeftArrowButton = false; - this.btnCopyShortcutKeys.DrawRightArrowButton = false; - this.btnCopyShortcutKeys.Font = new System.Drawing.Font("Marlett", 9F); - this.btnCopyShortcutKeys.Image = global::L10NSharp.Properties.Resources.kimidCopyTranslation; - this.btnCopyShortcutKeys.Location = new System.Drawing.Point(187, 6); - this.btnCopyShortcutKeys.Name = "btnCopyShortcutKeys"; - this.btnCopyShortcutKeys.Size = new System.Drawing.Size(11, 15); - this.btnCopyShortcutKeys.TabIndex = 7; - this._tooltip.SetToolTip(this.btnCopyShortcutKeys, "Copy Source Shortcut Keys to Target (Ctrl+Alt+S)"); - this.btnCopyShortcutKeys.Visible = false; - this.btnCopyShortcutKeys.Click += new System.EventHandler(this.btnCopyShortcutKeys_Click); - // - // btnCopyText - // - this.btnCopyText.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnCopyText.BackColor = System.Drawing.Color.Transparent; - this.btnCopyText.CanBeChecked = false; - this.btnCopyText.Checked = false; - this.btnCopyText.DrawEmpty = false; - this.btnCopyText.DrawLeftArrowButton = false; - this.btnCopyText.DrawRightArrowButton = false; - this.btnCopyText.Font = new System.Drawing.Font("Marlett", 9F); - this.btnCopyText.Image = global::L10NSharp.Properties.Resources.kimidCopyTranslation; - this.btnCopyText.Location = new System.Drawing.Point(155, 6); - this.btnCopyText.Name = "btnCopyText"; - this.btnCopyText.Size = new System.Drawing.Size(11, 13); - this.btnCopyText.TabIndex = 6; - this._tooltip.SetToolTip(this.btnCopyText, "Copy Source Translation to Target (Ctrl+Alt+T)"); - this.btnCopyText.Visible = false; - this.btnCopyText.Click += new System.EventHandler(this.btnCopyText_Click); - // - // _panelTargetText - // - this._panelTargetText.Controls.Add(this._groupBoxTgtTranslation); - this._panelTargetText.Dock = System.Windows.Forms.DockStyle.Fill; - this._panelTargetText.Location = new System.Drawing.Point(3, 158); - this._panelTargetText.Name = "_panelTargetText"; - this._panelTargetText.Size = new System.Drawing.Size(326, 93); - this._panelTargetText.TabIndex = 4; - // - // _groupBoxTgtTranslation - // - this._groupBoxTgtTranslation.Controls.Add(this._labelTgtShortcutKeys); - this._groupBoxTgtTranslation.Controls.Add(this._shortcutKeysDropDown); - this._groupBoxTgtTranslation.Controls.Add(this._labelTgtToolTip); - this._groupBoxTgtTranslation.Controls.Add(this._textBoxTgtToolTip); - this._groupBoxTgtTranslation.Controls.Add(this._textBoxTgtTranslation); - this._groupBoxTgtTranslation.Dock = System.Windows.Forms.DockStyle.Fill; - this._groupBoxTgtTranslation.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._groupBoxTgtTranslation.Location = new System.Drawing.Point(0, 0); - this._groupBoxTgtTranslation.Name = "_groupBoxTgtTranslation"; - this._groupBoxTgtTranslation.Size = new System.Drawing.Size(326, 93); - this._groupBoxTgtTranslation.TabIndex = 0; - this._groupBoxTgtTranslation.TabStop = false; - // - // _labelTgtShortcutKeys - // - this._labelTgtShortcutKeys.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this._labelTgtShortcutKeys.AutoSize = true; - this._labelTgtShortcutKeys.BackColor = System.Drawing.Color.Transparent; - this._labelTgtShortcutKeys.Enabled = false; - this._labelTgtShortcutKeys.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._labelTgtShortcutKeys.Location = new System.Drawing.Point(113, 66); - this._labelTgtShortcutKeys.Name = "_labelTgtShortcutKeys"; - this._labelTgtShortcutKeys.Size = new System.Drawing.Size(79, 13); - this._labelTgtShortcutKeys.TabIndex = 3; - this._labelTgtShortcutKeys.Text = "Shortcut &Keys:"; - // - // _shortcutKeysDropDown - // - this._shortcutKeysDropDown.AlignDropToLeft = false; - this._shortcutKeysDropDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this._shortcutKeysDropDown.BackColor = System.Drawing.SystemColors.Window; - this._shortcutKeysDropDown.Location = new System.Drawing.Point(198, 61); - this._shortcutKeysDropDown.Name = "_shortcutKeysDropDown"; - this._shortcutKeysDropDown.Padding = new System.Windows.Forms.Padding(1); - this._shortcutKeysDropDown.ShortcutKeys = System.Windows.Forms.Keys.None; - this._shortcutKeysDropDown.ShortcutKeysAsString = "None"; - this._shortcutKeysDropDown.Size = new System.Drawing.Size(122, 22); - this._shortcutKeysDropDown.TabIndex = 4; - // - // _labelTgtToolTip - // - this._labelTgtToolTip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this._labelTgtToolTip.AutoSize = true; - this._labelTgtToolTip.BackColor = System.Drawing.Color.Transparent; - this._labelTgtToolTip.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._labelTgtToolTip.Location = new System.Drawing.Point(6, 66); - this._labelTgtToolTip.Name = "_labelTgtToolTip"; - this._labelTgtToolTip.Size = new System.Drawing.Size(49, 13); - this._labelTgtToolTip.TabIndex = 1; - this._labelTgtToolTip.Text = "&Tool Tip:"; - // - // _textBoxTgtToolTip - // - this._textBoxTgtToolTip.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this._textBoxTgtToolTip.BackColor = System.Drawing.SystemColors.Window; - this._textBoxTgtToolTip.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._textBoxTgtToolTip.Location = new System.Drawing.Point(62, 61); - this._textBoxTgtToolTip.Name = "_textBoxTgtToolTip"; - this._textBoxTgtToolTip.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this._textBoxTgtToolTip.Size = new System.Drawing.Size(45, 22); - this._textBoxTgtToolTip.TabIndex = 2; - // - // _panelSourceText - // - this._panelSourceText.Controls.Add(this._groupBoxSrcTranslation); - this._panelSourceText.Dock = System.Windows.Forms.DockStyle.Fill; - this._panelSourceText.Location = new System.Drawing.Point(3, 77); - this._panelSourceText.Name = "_panelSourceText"; - this._panelSourceText.Size = new System.Drawing.Size(326, 75); - this._panelSourceText.TabIndex = 5; - // - // _groupBoxSrcTranslation - // - this._groupBoxSrcTranslation.BackColor = System.Drawing.Color.Transparent; - this._groupBoxSrcTranslation.Controls.Add(this._textBoxSrcTranslation); - this._groupBoxSrcTranslation.Controls.Add(this._textBoxSrcShortcutKeys); - this._groupBoxSrcTranslation.Controls.Add(this._labelSrcShortcutKeys); - this._groupBoxSrcTranslation.Controls.Add(this._labelSrcToolTip); - this._groupBoxSrcTranslation.Controls.Add(this._textBoxSrcToolTip); - this._groupBoxSrcTranslation.Dock = System.Windows.Forms.DockStyle.Fill; - this._groupBoxSrcTranslation.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._groupBoxSrcTranslation.Location = new System.Drawing.Point(0, 0); - this._groupBoxSrcTranslation.Name = "_groupBoxSrcTranslation"; - this._groupBoxSrcTranslation.Size = new System.Drawing.Size(326, 75); - this._groupBoxSrcTranslation.TabIndex = 0; - this._groupBoxSrcTranslation.TabStop = false; - this._groupBoxSrcTranslation.Paint += new System.Windows.Forms.PaintEventHandler(this.HandleGroupSrcTranslationPaint); - // - // _textBoxSrcTranslation - // - this._textBoxSrcTranslation.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this._textBoxSrcTranslation.BorderStyle = System.Windows.Forms.BorderStyle.None; - this._textBoxSrcTranslation.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._textBoxSrcTranslation.ForeColor = System.Drawing.Color.Black; - this._textBoxSrcTranslation.Location = new System.Drawing.Point(6, 18); - this._textBoxSrcTranslation.Multiline = true; - this._textBoxSrcTranslation.Name = "_textBoxSrcTranslation"; - this._textBoxSrcTranslation.ReadOnly = true; - this._textBoxSrcTranslation.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this._textBoxSrcTranslation.Size = new System.Drawing.Size(314, 23); - this._textBoxSrcTranslation.TabIndex = 0; - // - // _textBoxSrcShortcutKeys - // - this._textBoxSrcShortcutKeys.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this._textBoxSrcShortcutKeys.BorderStyle = System.Windows.Forms.BorderStyle.None; - this._textBoxSrcShortcutKeys.Enabled = false; - this._textBoxSrcShortcutKeys.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._textBoxSrcShortcutKeys.Location = new System.Drawing.Point(198, 50); - this._textBoxSrcShortcutKeys.Name = "_textBoxSrcShortcutKeys"; - this._textBoxSrcShortcutKeys.ReadOnly = true; - this._textBoxSrcShortcutKeys.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this._textBoxSrcShortcutKeys.Size = new System.Drawing.Size(122, 15); - this._textBoxSrcShortcutKeys.TabIndex = 4; - // - // _labelSrcShortcutKeys - // - this._labelSrcShortcutKeys.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this._labelSrcShortcutKeys.AutoSize = true; - this._labelSrcShortcutKeys.BackColor = System.Drawing.Color.Transparent; - this._labelSrcShortcutKeys.Enabled = false; - this._labelSrcShortcutKeys.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._labelSrcShortcutKeys.Location = new System.Drawing.Point(113, 50); - this._labelSrcShortcutKeys.Name = "_labelSrcShortcutKeys"; - this._labelSrcShortcutKeys.Size = new System.Drawing.Size(79, 13); - this._labelSrcShortcutKeys.TabIndex = 3; - this._labelSrcShortcutKeys.Text = "Shortcut Keys:"; - // - // _labelSrcToolTip - // - this._labelSrcToolTip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this._labelSrcToolTip.AutoSize = true; - this._labelSrcToolTip.BackColor = System.Drawing.Color.Transparent; - this._labelSrcToolTip.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._labelSrcToolTip.Location = new System.Drawing.Point(6, 50); - this._labelSrcToolTip.Name = "_labelSrcToolTip"; - this._labelSrcToolTip.Size = new System.Drawing.Size(49, 13); - this._labelSrcToolTip.TabIndex = 1; - this._labelSrcToolTip.Text = "Tool Tip:"; - // - // _textBoxSrcToolTip - // - this._textBoxSrcToolTip.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this._textBoxSrcToolTip.BorderStyle = System.Windows.Forms.BorderStyle.None; - this._textBoxSrcToolTip.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._textBoxSrcToolTip.Location = new System.Drawing.Point(62, 50); - this._textBoxSrcToolTip.Name = "_textBoxSrcToolTip"; - this._textBoxSrcToolTip.ReadOnly = true; - this._textBoxSrcToolTip.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this._textBoxSrcToolTip.Size = new System.Drawing.Size(45, 15); - this._textBoxSrcToolTip.TabIndex = 2; - // - // _panelButtons - // - this._panelButtons.BackColor = System.Drawing.Color.Transparent; - this._panelButtons.Controls.Add(this._howToDistribute); - this._panelButtons.Controls.Add(this._buttonFallbackLanguages); - this._panelButtons.Controls.Add(this._buttonCancel); - this._panelButtons.Controls.Add(this._buttonOK); - this._panelButtons.Dock = System.Windows.Forms.DockStyle.Bottom; - this._panelButtons.Location = new System.Drawing.Point(0, 456); - this._panelButtons.Name = "_panelButtons"; - this._panelButtons.Size = new System.Drawing.Size(826, 41); - this._panelButtons.TabIndex = 1; - // - // _howToDistribute - // - this._howToDistribute.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this._howToDistribute.AutoSize = true; - this._howToDistribute.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._howToDistribute.Location = new System.Drawing.Point(392, 12); - this._howToDistribute.Name = "_howToDistribute"; - this._howToDistribute.Size = new System.Drawing.Size(248, 17); - this._howToDistribute.TabIndex = 3; - this._howToDistribute.TabStop = true; - this._howToDistribute.Text = "How to distribute your translation work"; - this._howToDistribute.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this._howToDistribute_LinkClicked); - // - // _buttonFallbackLanguages - // - this._buttonFallbackLanguages.Location = new System.Drawing.Point(8, 7); - this._buttonFallbackLanguages.Name = "_buttonFallbackLanguages"; - this._buttonFallbackLanguages.Size = new System.Drawing.Size(156, 26); - this._buttonFallbackLanguages.TabIndex = 0; - this._buttonFallbackLanguages.Text = "&Fallback Languages..."; - this._buttonFallbackLanguages.UseVisualStyleBackColor = true; - this._buttonFallbackLanguages.Visible = false; - this._buttonFallbackLanguages.Click += new System.EventHandler(this._buttonFallbackLanguages_Click); - // - // toolStrip - // - this.toolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; - this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.tbbCopy, - this.toolStripSeparator2, - this.tbbGoogleTranslate, - this.toolStripSeparator3, - this.tcboSearch, - this.tblblSearch}); - this.toolStrip.Location = new System.Drawing.Point(0, 0); - this.toolStrip.Name = "toolStrip"; - this.toolStrip.Size = new System.Drawing.Size(809, 25); - this.toolStrip.TabIndex = 0; - this.toolStrip.Text = "toolStrip1"; - this.toolStrip.Visible = false; - // - // tbbCopy - // - this.tbbCopy.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.mnuCopyText, - this.mnuCopyToolTip, - this.mnuCopyShortcutKeys, - this.toolStripMenuItem1, - this.mnuCopyAll}); - this.tbbCopy.Image = global::L10NSharp.Properties.Resources.kimidCopyTranslationBig; - this.tbbCopy.ImageTransparentColor = System.Drawing.Color.Magenta; - this.tbbCopy.Margin = new System.Windows.Forms.Padding(5, 1, 0, 2); - this.tbbCopy.Name = "tbbCopy"; - this.tbbCopy.Size = new System.Drawing.Size(64, 22); - this.tbbCopy.Text = "Copy"; - this.tbbCopy.Visible = false; - // - // mnuCopyText - // - this.mnuCopyText.Name = "mnuCopyText"; - this.mnuCopyText.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Alt) - | System.Windows.Forms.Keys.T))); - this.mnuCopyText.Size = new System.Drawing.Size(329, 22); - this.mnuCopyText.Text = "Copy Source Translation to Target"; - this.mnuCopyText.Click += new System.EventHandler(this.btnCopyText_Click); - // - // mnuCopyToolTip - // - this.mnuCopyToolTip.Name = "mnuCopyToolTip"; - this.mnuCopyToolTip.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Alt) - | System.Windows.Forms.Keys.O))); - this.mnuCopyToolTip.Size = new System.Drawing.Size(329, 22); - this.mnuCopyToolTip.Text = "Copy Source Tool Tip to Target"; - this.mnuCopyToolTip.Click += new System.EventHandler(this.btnCopyToolTip_Click); - // - // mnuCopyShortcutKeys - // - this.mnuCopyShortcutKeys.Name = "mnuCopyShortcutKeys"; - this.mnuCopyShortcutKeys.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Alt) - | System.Windows.Forms.Keys.S))); - this.mnuCopyShortcutKeys.Size = new System.Drawing.Size(329, 22); - this.mnuCopyShortcutKeys.Text = "Copy Source Shortcut Keys to Target"; - this.mnuCopyShortcutKeys.Click += new System.EventHandler(this.btnCopyShortcutKeys_Click); - // - // toolStripMenuItem1 - // - this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(326, 6); - // - // mnuCopyAll - // - this.mnuCopyAll.Name = "mnuCopyAll"; - this.mnuCopyAll.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Alt) - | System.Windows.Forms.Keys.A))); - this.mnuCopyAll.Size = new System.Drawing.Size(329, 22); - this.mnuCopyAll.Text = "Copy All"; - this.mnuCopyAll.Click += new System.EventHandler(this.mnuCopyAll_Click); - // - // toolStripSeparator2 - // - this.toolStripSeparator2.Name = "toolStripSeparator2"; - this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25); - // - // tbbGoogleTranslate - // - this.tbbGoogleTranslate.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this.tbbGoogleTranslate.Enabled = false; - this.tbbGoogleTranslate.Image = global::L10NSharp.Properties.Resources.kimidGoogle; - this.tbbGoogleTranslate.ImageTransparentColor = System.Drawing.Color.Magenta; - this.tbbGoogleTranslate.Margin = new System.Windows.Forms.Padding(5, 1, 0, 2); - this.tbbGoogleTranslate.Name = "tbbGoogleTranslate"; - this.tbbGoogleTranslate.Size = new System.Drawing.Size(23, 22); - this.tbbGoogleTranslate.ToolTipText = "Use Google Translator"; - this.tbbGoogleTranslate.Visible = false; - this.tbbGoogleTranslate.Click += new System.EventHandler(this.HandleTranslatorServiceButtonClick); - // - // toolStripSeparator3 - // - this.toolStripSeparator3.Name = "toolStripSeparator3"; - this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25); - // - // tcboSearch - // - this.tcboSearch.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; - this.tcboSearch.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; - this.tcboSearch.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; - this.tcboSearch.Margin = new System.Windows.Forms.Padding(3, 0, 1, 0); - this.tcboSearch.Name = "tcboSearch"; - this.tcboSearch.Size = new System.Drawing.Size(170, 23); - this.tcboSearch.Visible = false; - this.tcboSearch.Enter += new System.EventHandler(this.tcboSearch_Enter); - this.tcboSearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tcboSearch_KeyDown); - // - // tblblSearch - // - this.tblblSearch.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; - this.tblblSearch.Margin = new System.Windows.Forms.Padding(3, 1, 0, 2); - this.tblblSearch.Name = "tblblSearch"; - this.tblblSearch.Size = new System.Drawing.Size(45, 22); - this.tblblSearch.Text = "Search:"; - this.tblblSearch.Visible = false; - // - // _statusStrip - // - this._statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this._labelCount, - this._progressBar}); - this._statusStrip.Location = new System.Drawing.Point(0, 497); - this._statusStrip.Name = "_statusStrip"; - this._statusStrip.Size = new System.Drawing.Size(826, 22); - this._statusStrip.TabIndex = 2; - this._statusStrip.Text = "statusStrip1"; - // - // _labelCount - // - this._labelCount.BackColor = System.Drawing.Color.Transparent; - this._labelCount.Margin = new System.Windows.Forms.Padding(0, 3, 5, 2); - this._labelCount.Name = "_labelCount"; - this._labelCount.Size = new System.Drawing.Size(806, 17); - this._labelCount.Spring = true; - this._labelCount.Text = "#"; - this._labelCount.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // - // _progressBar - // - this._progressBar.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; - this._progressBar.Name = "_progressBar"; - this._progressBar.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never; - this._progressBar.Size = new System.Drawing.Size(200, 16); - this._progressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous; - this._progressBar.Visible = false; - // - // LocalizeItemDlg - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BackColor = System.Drawing.SystemColors.Control; - this.ClientSize = new System.Drawing.Size(826, 519); - this.Controls.Add(this.splitContainer); - this.Controls.Add(this._panelButtons); - this.Controls.Add(this._statusStrip); - this.Controls.Add(this.toolStrip); - this.DoubleBuffered = true; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "LocalizeItemDlg"; - this.ShowIcon = false; - this.ShowInTaskbar = false; - this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; - this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; - this.Text = "Localize User Interface (L10NSharp)"; - this.Load += new System.EventHandler(this.LocalizeItemDlg_Load); - this._groupBoxComment.ResumeLayout(false); - this._groupBoxComment.PerformLayout(); - this._groupBoxImage.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this._pictureImage)).EndInit(); - this.splitContainer.Panel1.ResumeLayout(false); - this.splitContainer.Panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); - this.splitContainer.ResumeLayout(false); - this._toolStripLeftSide.ResumeLayout(false); - this._toolStripLeftSide.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this._grid)).EndInit(); - this._toolStripRightSide.ResumeLayout(false); - this._toolStripRightSide.PerformLayout(); - this._tableLayout.ResumeLayout(false); - this._panelIdentifier.ResumeLayout(false); - this._panelIdentifier.PerformLayout(); - this._panelTargetText.ResumeLayout(false); - this._groupBoxTgtTranslation.ResumeLayout(false); - this._groupBoxTgtTranslation.PerformLayout(); - this._panelSourceText.ResumeLayout(false); - this._groupBoxSrcTranslation.ResumeLayout(false); - this._groupBoxSrcTranslation.PerformLayout(); - this._panelButtons.ResumeLayout(false); - this._panelButtons.PerformLayout(); - this.toolStrip.ResumeLayout(false); - this.toolStrip.PerformLayout(); - this._statusStrip.ResumeLayout(false); - this._statusStrip.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.TextBox _textBoxTgtTranslation; - private System.Windows.Forms.Label _labelStringId; - private System.Windows.Forms.Button _buttonOK; - private System.Windows.Forms.Button _buttonCancel; - private System.Windows.Forms.Label _labelStringIdValue; - private System.Windows.Forms.GroupBox _groupBoxComment; - private System.Windows.Forms.TextBox _textBoxComment; - private System.Windows.Forms.GroupBox _groupBoxImage; - private System.Windows.Forms.PictureBox _pictureImage; - private System.Windows.Forms.SplitContainer splitContainer; - private System.Windows.Forms.Panel _panelButtons; - private System.Windows.Forms.TreeView _treeView; - private System.Windows.Forms.ToolStrip toolStrip; - private System.Windows.Forms.Label _labelSrcToolTip; - private System.Windows.Forms.GroupBox _groupBoxSrcTranslation; - private System.Windows.Forms.TextBox _textBoxSrcToolTip; - private System.Windows.Forms.TextBox _textBoxSrcShortcutKeys; - private System.Windows.Forms.Label _labelSrcShortcutKeys; - private System.Windows.Forms.GroupBox _groupBoxTgtTranslation; - private System.Windows.Forms.Label _labelTgtShortcutKeys; - private System.Windows.Forms.Label _labelTgtToolTip; - private System.Windows.Forms.TextBox _textBoxTgtToolTip; - private System.Windows.Forms.ToolStripButton tbbGoogleTranslate; - private System.Windows.Forms.TextBox _textBoxSrcTranslation; - private System.Windows.Forms.TableLayoutPanel _tableLayout; - private System.Windows.Forms.Panel _panelIdentifier; - private ShortcutKeysDropDown _shortcutKeysDropDown; - private XButton btnCopyToolTip; - private XButton btnCopyText; - private System.Windows.Forms.ToolTip _tooltip; - private XButton btnCopyShortcutKeys; - private System.Windows.Forms.ToolStripDropDownButton tbbCopy; - private System.Windows.Forms.ToolStripMenuItem mnuCopyText; - private System.Windows.Forms.ToolStripMenuItem mnuCopyToolTip; - private System.Windows.Forms.ToolStripMenuItem mnuCopyShortcutKeys; - private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; - private System.Windows.Forms.ToolStripMenuItem mnuCopyAll; - private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; - private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; - private System.Windows.Forms.ToolStripComboBox tcboSearch; - private System.Windows.Forms.ToolStripLabel tblblSearch; - private System.Windows.Forms.StatusStrip _statusStrip; - private System.Windows.Forms.ToolStripStatusLabel _labelCount; - private System.Windows.Forms.Button _buttonFallbackLanguages; - private XButton _buttonMovePrev; - private XButton _buttonMoveNext; - private System.Windows.Forms.Panel _panelTargetText; - private System.Windows.Forms.Panel _panelSourceText; - private LmGrid _grid; - private System.Windows.Forms.ToolStripProgressBar _progressBar; - private System.Windows.Forms.ToolStrip _toolStripRightSide; - private System.Windows.Forms.ToolStripComboBox _comboTargetLang; - private System.Windows.Forms.ToolStripLabel _labelTargetLang; - private System.Windows.Forms.ToolStripComboBox _comboSourceLang; - private System.Windows.Forms.ToolStripLabel _labelSourceLang; - private System.Windows.Forms.ToolStrip _toolStripLeftSide; - private System.Windows.Forms.ToolStripLabel _labelGroups; - private System.Windows.Forms.ToolStripSplitButton _buttonBingTranslator; - private System.Windows.Forms.ToolStripMenuItem _menuTranslateUsingBing; - private System.Windows.Forms.ToolStripMenuItem _menuEditSourceAndTranslate; - private System.Windows.Forms.DataGridViewTextBoxColumn _colId; - private System.Windows.Forms.DataGridViewTextBoxColumn _colSourceText; - private System.Windows.Forms.DataGridViewTextBoxColumn _colTargetText; - private System.Windows.Forms.DataGridViewTextBoxColumn _colSrcToolTip; - private System.Windows.Forms.DataGridViewTextBoxColumn _colTgtToolTip; - private System.Windows.Forms.DataGridViewTextBoxColumn _colComments; - private System.Windows.Forms.LinkLabel _howToDistribute; - } -} diff --git a/src/L10NSharp/UI/LocalizeItemDlg.cs b/src/L10NSharp/UI/LocalizeItemDlg.cs deleted file mode 100644 index 7dd2c1f..0000000 --- a/src/L10NSharp/UI/LocalizeItemDlg.cs +++ /dev/null @@ -1,911 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Drawing; -using System.Globalization; -using System.Text; -using System.Windows.Forms; -using L10NSharp.Properties; - -namespace L10NSharp.UI -{ - /// ---------------------------------------------------------------------------------------- - public partial class LocalizeItemDlg : Form - { - public static Font DefaultDisplayFont { get; set; } - - /// ------------------------------------------------------------------------------------ - public delegate void StringsLocalizedHandler(ILocalizationManager localizationManager); - /// ------------------------------------------------------------------------------------ - public delegate string SetDialogSettingsHandler(LocalizeItemDlg dlg); - /// ------------------------------------------------------------------------------------ - public delegate void SaveDialogSettingsHandler(LocalizeItemDlg dlg, string settings); - /// ------------------------------------------------------------------------------------ - public static event SetDialogSettingsHandler SetDialogSettings; - /// ------------------------------------------------------------------------------------ - public static event SaveDialogSettingsHandler SaveDialogSettings; - /// ------------------------------------------------------------------------------------ - public static event StringsLocalizedHandler StringsLocalized; - - private readonly LocalizeItemDlgViewModel _viewModel; - private readonly ILocalizationManagerInternal _callingManager; - private int _tmpSplitDistance; - private DateTime _timeToGiveUpLookingForTranslator; - - - /// ------------------------------------------------------------------------------------ - internal static DialogResult ShowDialog(ILocalizationManagerInternal callingManager, - IComponent component, bool runInReadonlyMode, IWin32Window owner = null) - { - if (callingManager != null && !callingManager.CanCustomizeLocalizations) - runInReadonlyMode = true; - - var viewModel = new LocalizeItemDlgViewModel(runInReadonlyMode); - - var id = (callingManager == null ? viewModel.GetObjIdFromAnyCache(component) : - callingManager.ComponentCache.FirstOrDefault(kvp => kvp.Key == component).Value); - - using (var dlg = new LocalizeItemDlg(viewModel, id, callingManager)) - { - if (owner != null) - dlg.StartPosition = FormStartPosition.CenterParent; - return dlg.ShowDialog(owner); - } - } - - /// ------------------------------------------------------------------------------------ - internal static DialogResult ShowDialog(ILocalizationManagerInternal callingManager, - string id, bool runInReadonlyMode, IWin32Window owner = null) - { - if (callingManager != null && !callingManager.CanCustomizeLocalizations) - runInReadonlyMode = true; - - var viewModel = new LocalizeItemDlgViewModel(runInReadonlyMode); - - using (var dlg = new LocalizeItemDlg(viewModel, id, callingManager)) - { - if (owner != null) - dlg.StartPosition = FormStartPosition.CenterParent; - return dlg.ShowDialog(owner); - } - } - - #region Constrution/initialization - /// ------------------------------------------------------------------------------------ - private LocalizeItemDlg() - { - if (DefaultDisplayFont == null) - DefaultDisplayFont = SystemFonts.MenuFont; - - InitializeComponent(); - } - - /// ------------------------------------------------------------------------------------ - private LocalizeItemDlg(LocalizeItemDlgViewModel viewModel, string id, - ILocalizationManagerInternal callingManager) : this() - { - _viewModel = viewModel; - _callingManager = callingManager; - - Initialize(); - - if (id == null) - return; - - var node = _viewModel.FindNode(id, _treeView.Nodes); - if (node == null) - return; - - _viewModel.CurrentNode = node; - _treeView.SelectedNode = node; - UpdateSingleItemView(); - } - - /// ------------------------------------------------------------------------------------ - private void Initialize() - { - _tableLayout.Dock = DockStyle.Fill; - _grid.Dock = DockStyle.Fill; - - _tableLayout.BringToFront(); - _grid.BringToFront(); - - _toolStripLeftSide.Renderer = new NoToolStripBorderRenderer(); - _toolStripRightSide.Renderer = new NoToolStripBorderRenderer(); - - InitializeColorsAndFonts(); - - GetDialogBoxSettings(); - - _comboSourceLang.Items.AddRange(LocalizationManagerInternal.GetUILanguages(true).ToArray()); - _comboTargetLang.Items.AddRange(LocalizationManagerInternal.GetUILanguages(false).ToArray()); - _comboSourceLang.ComboBox.DisplayMember = "NativeName"; - _comboTargetLang.ComboBox.DisplayMember = "NativeName"; - - UpdateLanguageSensitiveControls(); - _viewModel.LoadTreeNodes(_treeView); - _labelCount.Text = _viewModel.GetNumberOfTranslatedItemsString(); - _grid.MultiSelect = true; - UpdateGridSortGlyph(); - } - - /// ------------------------------------------------------------------------------------ - private void InitializeColorsAndFonts() - { - _textBoxSrcTranslation.BackColor = PaintingHelper.CalculateColor(SystemColors.Control, Color.White, 140); - _textBoxSrcToolTip.BackColor = _textBoxSrcTranslation.BackColor; - _textBoxSrcShortcutKeys.BackColor = _textBoxSrcTranslation.BackColor; - btnCopyText.BackColor = _textBoxSrcTranslation.BackColor; - btnCopyToolTip.BackColor = _textBoxSrcTranslation.BackColor; - btnCopyShortcutKeys.BackColor = _textBoxSrcTranslation.BackColor; - - _grid.Font = DefaultDisplayFont; - _grid.ColumnHeadersDefaultCellStyle.Font = DefaultDisplayFont; - _shortcutKeysDropDown.Font = DefaultDisplayFont; - _textBoxSrcTranslation.Font = DefaultDisplayFont; - _colSrcToolTip.DefaultCellStyle.Font = DefaultDisplayFont; - _colTgtToolTip.DefaultCellStyle.Font = DefaultDisplayFont; - _treeView.Font = DefaultDisplayFont; - _textBoxSrcToolTip.Font = new Font(DefaultDisplayFont.FontFamily, - _textBoxSrcToolTip.Font.SizeInPoints, FontStyle.Regular); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Get the splitter position from the caller. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnShown(EventArgs e) - { - base.OnShown(e); - - if (_tmpSplitDistance > 0) - splitContainer.SplitterDistance = _tmpSplitDistance; - - _grid.AutoResizeColumnHeadersHeight(); - _grid.ColumnHeadersHeight += 8; - - _grid.Visible = (_grid.RowCount > 0); - _tableLayout.Visible = (_grid.RowCount == 0); - - _treeView.AfterSelect -= HandleTreeViewAfterSelect; - _treeView.AfterSelect += HandleTreeViewAfterSelect; - _viewModel.SetNodeColors(); - Activate(); - - if (_viewModel.CurrentNode == null && _treeView.Nodes.Count > 0) - { - _treeView.Nodes[0].Expand(); - Application.DoEvents(); - HandleTreeViewAfterSelect(null, new TreeViewEventArgs(_treeView.Nodes[0])); - } - - if (_viewModel.BingTranslator != null) - { - _buttonBingTranslator.Enabled = true; - return; - } - - // Attempt to enable the translator button for 5 seconds. - _timeToGiveUpLookingForTranslator = DateTime.Now.AddSeconds(5d); - Application.Idle += HandleCheckingForTranslator; - } - - /// ------------------------------------------------------------------------------------ - void HandleCheckingForTranslator(object sender, EventArgs e) - { - _buttonBingTranslator.Enabled = - (_viewModel.BingTranslator != null && _viewModel.CurrentNode != null); - - if (_buttonBingTranslator.Enabled || DateTime.Now >= _timeToGiveUpLookingForTranslator) - Application.Idle -= HandleCheckingForTranslator; - } - - #endregion - - #region Misc. updating methods - /// ------------------------------------------------------------------------------------ - private void UpdateLanguageSensitiveControls() - { - var ci = L10NCultureInfo.GetCultureInfo(_viewModel.SrcLangId); - _comboSourceLang.SelectedItem = ci; - _comboSourceLang.ToolTipText = ci.DisplayName; - _groupBoxSrcTranslation.Text = _colSourceText.HeaderText = ci.NativeName; - _colSrcToolTip.HeaderText = string.Format("{0} Tooltip", ci.NativeName); - - ci = L10NCultureInfo.GetCultureInfo(_viewModel.TgtLangId); - _comboTargetLang.SelectedItem = ci; - _comboTargetLang.ToolTipText = ci.DisplayName; - _groupBoxTgtTranslation.Text = _colTargetText.HeaderText = ci.NativeName; - _colTgtToolTip.HeaderText = string.Format("{0} Tooltip", ci.NativeName); - } - - /// ------------------------------------------------------------------------------------ - private void UpdateViewAfterSavingChange() - { - _viewModel.SetNodeColors(); - _labelCount.Text = _viewModel.GetNumberOfTranslatedItemsString(); - } - - #endregion - - #region Methods for updating and saving changes in the single-item view - /// ------------------------------------------------------------------------------------ - private void ResetSingleItemView() - { - _buttonBingTranslator.Enabled = - (_viewModel.BingTranslator != null && _viewModel.CurrentNode != null); - - _groupBoxImage.Visible = false; - - _labelSrcToolTip.Enabled = _labelTgtToolTip.Enabled = false; - _textBoxSrcToolTip.Enabled = _textBoxTgtToolTip.Enabled = false; - _labelSrcShortcutKeys.Enabled = _labelTgtShortcutKeys.Enabled = false; - _textBoxSrcShortcutKeys.Enabled = _shortcutKeysDropDown.Enabled = false; - _groupBoxComment.Enabled = _groupBoxSrcTranslation.Enabled = _groupBoxTgtTranslation.Enabled = false; - _labelStringId.Enabled = false; - - _labelStringIdValue.Text = string.Empty; - _textBoxSrcTranslation.Text = string.Empty; - _textBoxTgtTranslation.Text = string.Empty; - _textBoxSrcToolTip.Text = string.Empty; - _textBoxTgtToolTip.Text = string.Empty; - _textBoxSrcShortcutKeys.Text = string.Empty; - _textBoxComment.Text = string.Empty; - } - - /// ------------------------------------------------------------------------------------ - private void UpdateSingleItemView() - { - Utils.SetWindowRedraw(this, false, false); - - ResetSingleItemView(); - - if (_viewModel.CurrentNode == null || _viewModel.CurrentNode.Id == null) - { - Utils.SetWindowRedraw(this, true, true); - return; - } - - _textBoxTgtTranslation.Enabled = _textBoxTgtToolTip.Enabled = _groupBoxTgtTranslation.Enabled = - (_viewModel.CurrentNode.Id != null && !_viewModel.TgtLangId.StartsWith(LocalizationManager.kDefaultLang)); - - _groupBoxComment.Enabled = _groupBoxSrcTranslation.Enabled = (_viewModel.CurrentNode.Id != null); - - _labelStringId.Enabled = (_viewModel.CurrentNode.Id != null); - _labelStringIdValue.Text = _viewModel.CurrentNode.Id; - _textBoxSrcTranslation.Text = _viewModel.CurrentNodeSourceText; - _textBoxTgtTranslation.Text = _viewModel.CurrentNodeTargetText; - _textBoxSrcToolTip.Text = _viewModel.CurrentNodeSourceToolTip; - _textBoxTgtToolTip.Text = _viewModel.CurrentNodeTargetToolTip; - _textBoxSrcShortcutKeys.Text = _viewModel.CurrentNodeSourceShortcutKeys; - _shortcutKeysDropDown.ShortcutKeysAsString = _viewModel.CurrentNodeTargetShortcutKeys; - _textBoxComment.Text = _viewModel.CurrentNodeComment; - - //btnCopyText.Enabled = (txtSrcTranslation.Text != string.Empty); - //btnCopyToolTip.Enabled = (txtSrcToolTip.Text != string.Empty); - //btnCopyShortcutKeys.Enabled = (txtSrcShortcutKeys.Text != string.Empty); - - _textBoxSrcTranslation.Text = _textBoxSrcTranslation.Text.Replace( - LocalizedStringCache.s_literalNewline, Environment.NewLine); - - _textBoxTgtTranslation.Text = _textBoxTgtTranslation.Text.Replace( - LocalizedStringCache.s_literalNewline, Environment.NewLine); - - _textBoxTgtTranslation.SelectAll(); - var component = _viewModel.GetFirstObjectForId(); - - if (component != null) - UpdateSingleItemViewForComponent(component); - - var fnt = _viewModel.GetFontForObject(component); - - _textBoxSrcTranslation.Font = fnt; - _textBoxTgtTranslation.Font = fnt; - _colSourceText.DefaultCellStyle.Font = fnt; - _colTargetText.DefaultCellStyle.Font = fnt; - - Utils.SetWindowRedraw(this, true, true); - } - - /// ------------------------------------------------------------------------------------ - private void UpdateSingleItemViewForComponent(IComponent component) - { - var img = _viewModel.GetObjectsImage(component); - if (img != null) - { - _pictureImage.Image = img; - _groupBoxImage.Visible = true; - } - - if (component is Control) - { - _labelSrcToolTip.Enabled = _labelTgtToolTip.Enabled = true; - _textBoxSrcToolTip.Enabled = _textBoxTgtToolTip.Enabled = true; - } - else if (component is ToolStripItem) - { - _labelSrcToolTip.Enabled = _labelTgtToolTip.Enabled = true; - _textBoxSrcToolTip.Enabled = _textBoxTgtToolTip.Enabled = true; - - if (component is ToolStripMenuItem) - { - _labelSrcShortcutKeys.Enabled = _labelTgtShortcutKeys.Enabled = true; - _textBoxSrcShortcutKeys.Enabled = _shortcutKeysDropDown.Enabled = true; - } - } - } - - /// ------------------------------------------------------------------------------------ - private void SaveChangesFromSingleItemView() - { - var node = _viewModel.CurrentNode; - - if (_grid.Visible || node == null) - return; - - var locInfo = new LocalizingInfo(node.Id); - locInfo.Text = _textBoxTgtTranslation.Text.Trim(); - locInfo.ToolTipText = _textBoxTgtToolTip.Text.Trim(); - locInfo.ShortcutKeys = _shortcutKeysDropDown.Text.Trim(); - locInfo.Comment = _textBoxComment.Text.Trim(); - - _viewModel.SaveChangesInMemory(locInfo); - UpdateViewAfterSavingChange(); - } - - #endregion - - #region Methods for handling the form closing - /// ------------------------------------------------------------------------------------ - /// - /// Allow delegates to save some settings. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnFormClosing(FormClosingEventArgs e) - { - base.OnFormClosing(e); - - SaveDialogBoxSettings(); - - if (DialogResult != DialogResult.OK) - { - if (e.CloseReason == CloseReason.None || !_viewModel.GetIsDirty()) - return; - - var result = MessageBox.Show(this, "Would you like to save your changes?", - Application.ProductName, MessageBoxButtons.YesNoCancel); - - if (result != DialogResult.Yes) - { - e.Cancel = (result == DialogResult.Cancel); - return; - } - } - - if (!_grid.Visible) - SaveChangesFromSingleItemView(); - else if (_grid.IsCurrentCellInEditMode) - _grid.EndEdit(DataGridViewDataErrorContexts.Commit); - - if (_viewModel.Save()) - { - foreach (var manager in _viewModel.GetModifiedManagers()) - FireStringsLocalizedEvent(manager); - } - } - - /// ------------------------------------------------------------------------------------ - internal static void FireStringsLocalizedEvent(ILocalizationManager lm) - { - StringsLocalized?.Invoke(lm); - } - - #endregion - - #region Saving and Getting Settings - /// ------------------------------------------------------------------------------------ - private void SaveDialogBoxSettings() - { - var bldr = new StringBuilder(); - bldr.AppendFormat("{0},", _viewModel.SrcLangId); - bldr.AppendFormat("{0},", _viewModel.TgtLangId); - bldr.AppendFormat("{0},", Bounds.X); - bldr.AppendFormat("{0},", Bounds.Y); - bldr.AppendFormat("{0},", Bounds.Width); - bldr.AppendFormat("{0},", Bounds.Height); - bldr.AppendFormat("{0},", splitContainer.SplitterDistance); - bldr.AppendFormat("{0},", (int)_viewModel.GridSortField); - - if (_viewModel.GridSortOrder == SortOrder.None) - bldr.AppendFormat("{0},", 0); - else - bldr.AppendFormat("{0},", _viewModel.GridSortOrder == SortOrder.Ascending ? 1 : 2); - - foreach (DataGridViewColumn col in _grid.Columns) - bldr.AppendFormat("{0},", col.Width); - - var allSettings = bldr.ToString().TrimEnd(','); - - if (SaveDialogSettings != null) - SaveDialogSettings(this, allSettings); - - Settings.Default.LocalizationDialogSettings = allSettings; - Settings.Default.Save(); - } - - /// ------------------------------------------------------------------------------------ - private void GetDialogBoxSettings() - { - var allSettings = (SetDialogSettings != null ? SetDialogSettings(this) : - Settings.Default.LocalizationDialogSettings); - - if (string.IsNullOrEmpty(allSettings)) - return; - - var settings = allSettings.Split(','); - if (settings.Length < 9) - return; - - try - { - if (_viewModel.SrcLangId == _viewModel.TgtLangId) - { - var srcLangId = settings[0]; - var tgtLangId = settings[1]; - _viewModel.SetLanguageIds(srcLangId, tgtLangId); - } - } - catch - { - _viewModel.SetLanguageIds(null, null); - } - - try - { - var bounds = Bounds; - int value; - - if (int.TryParse(settings[2], out value)) - bounds.X = value; - if (int.TryParse(settings[3], out value)) - bounds.Y = value; - if (int.TryParse(settings[4], out value)) - bounds.Width = value; - if (int.TryParse(settings[5], out value)) - bounds.Height = value; - - Bounds = bounds; - - if (int.TryParse(settings[6], out value)) - _tmpSplitDistance = value; - if (int.TryParse(settings[7], out value)) - _viewModel.GridSortField = (NodeComparer.SortField)value; - if (int.TryParse(settings[8], out value)) - _viewModel.GridSortOrder = (value == 2 ? SortOrder.Descending : SortOrder.Ascending); - - int i = 9; - foreach (DataGridViewColumn col in _grid.Columns) - { - if (i == settings.Length) - return; - - if (int.TryParse(settings[i++], out value)) - col.Width = value; - } - } - catch { } - } - - #endregion - - #region Methods for kicking off a translation - /// ------------------------------------------------------------------------------------ - /// - /// Translate the source text using Bing translating service. - /// - /// ------------------------------------------------------------------------------------ - private void HandleTranslatorServiceButtonClick(object sender, EventArgs e) - { - Dictionary> nodesToTranslate = null; - - if (!_grid.Visible) - { - nodesToTranslate = new Dictionary>(); - nodesToTranslate[0] = _treeView.SelectedNode as LocTreeNode; - } - else - { - if (_grid.IsCurrentCellInEditMode) - { - _grid.EndEdit(DataGridViewDataErrorContexts.Commit); - _grid.CurrentCell = _grid[0, _grid.CurrentCellAddress.Y]; - } - - nodesToTranslate = _grid.SelectedRows.Cast().OrderBy(r => r.Index) - .ToDictionary(r => r.Index, r => _viewModel.AllLeafNodesShowingInGrid[r.Index]); - } - - TranslateSelectedItems(nodesToTranslate); - } - - /// ------------------------------------------------------------------------------------ - private void TranslateSelectedItems(IDictionary> nodesToTranslate) - { - if (nodesToTranslate == null || nodesToTranslate.Count == 0) - return; - - _progressBar.Visible = true; - _progressBar.Maximum = nodesToTranslate.Count; - _progressBar.Value = 0; - Cursor = Cursors.WaitCursor; - - _viewModel.Translate(nodesToTranslate, (progressBarValue, translatedNodeIndex) => - { - _progressBar.Value = progressBarValue; - - if (_grid.Visible) - _grid.InvalidateRow(translatedNodeIndex); - else - UpdateSingleItemView(); - - _labelCount.Text = _viewModel.GetNumberOfTranslatedItemsString(); - }); - - while (_viewModel.TranslatorBusy) - Application.DoEvents(); - - _progressBar.Visible = false; - _viewModel.SetNodeColors(); - Cursor = Cursors.Default; - } - - #endregion - - #region TreeView event handlers - /// ------------------------------------------------------------------------------------ - /// - /// Update the string cache for the node the user is leaving. - /// - /// ------------------------------------------------------------------------------------ - private void HandleTreeViewBeforeSelect(object sender, TreeViewCancelEventArgs e) - { - SaveChangesFromSingleItemView(); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Update the right side of the dialog with the information for the node just selected. - /// - /// ------------------------------------------------------------------------------------ - private void HandleTreeViewAfterSelect(object sender, TreeViewEventArgs e) - { - var node = e.Node as LocTreeNode; - - _grid.RowCount = 0; - - if (node == null) - return; - - Cursor = Cursors.WaitCursor; - _viewModel.CurrentNode = node; - _grid.RowCount = _viewModel.AllLeafNodesShowingInGrid.Count; - _grid.Visible = (_grid.RowCount > 0); - _tableLayout.Visible = (_grid.RowCount == 0); - UpdateSingleItemView(); - _grid.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders); - Cursor = Cursors.Default; - } - - #endregion - - #region Event handlers for for copying, moving from item to item and for searching - /// ------------------------------------------------------------------------------------ - /// - /// Handles the Click event of the btnCopyText control. - /// - /// ------------------------------------------------------------------------------------ - private void btnCopyText_Click(object sender, EventArgs e) - { - //txtTgtTranslation.Text = txtSrcTranslation.Text; - //txtTgtTranslation.SelectAll(); - //txtTgtTranslation.Focus(); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Handles the Click event of the btnCopyToolTip control. - /// - /// ------------------------------------------------------------------------------------ - private void btnCopyToolTip_Click(object sender, EventArgs e) - { - //txtTgtToolTip.Text = txtSrcToolTip.Text; - //txtTgtToolTip.SelectAll(); - //txtTgtToolTip.Focus(); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Handles the Click event of the btnCopyShortcutKeys control. - /// - /// ------------------------------------------------------------------------------------ - private void btnCopyShortcutKeys_Click(object sender, EventArgs e) - { - //shortcutKeysDropDown.ShortcutKeysAsString = txtSrcShortcutKeys.Text; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Handles the Click event of the mnuCopyAll control. - /// - /// ------------------------------------------------------------------------------------ - private void mnuCopyAll_Click(object sender, EventArgs e) - { - //txtTgtTranslation.Text = txtSrcTranslation.Text; - //txtTgtToolTip.Text = txtSrcToolTip.Text; - //shortcutKeysDropDown.ShortcutKeysAsString = txtSrcShortcutKeys.Text; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Handles the KeyDown event of the tcboSearch control. - /// - /// ------------------------------------------------------------------------------------ - private void tcboSearch_KeyDown(object sender, KeyEventArgs e) - { - if (e.KeyCode != Keys.Enter) - return; - - var text = tcboSearch.Text.Trim(); - if (text == string.Empty) - return; - - if (tcboSearch.Items.Contains(text)) - tcboSearch.Items.Remove(text); - - tcboSearch.Items.Insert(0, text); - tcboSearch.Text = text; - tcboSearch.SelectAll(); - - // TODO: Do search - } - - /// ------------------------------------------------------------------------------------ - private void tcboSearch_Enter(object sender, EventArgs e) - { - tcboSearch.SelectAll(); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Move to the previous leaf node in the tree. - /// - /// ------------------------------------------------------------------------------------ - private void _buttonMovePrev_Click(object sender, EventArgs e) - { - //int i = _leafNodes.IndexOf(tvGroups.SelectedNode as LocTreeNode); - //if (i - 1 >= 0) - // tvGroups.SelectedNode = _leafNodes[i - 1]; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Move to the next leaf node in the tree. - /// - /// ------------------------------------------------------------------------------------ - private void _buttonMoveNext_Click(object sender, EventArgs e) - { - //int i = _leafNodes.IndexOf(tvGroups.SelectedNode as LocTreeNode); - //if (i >= 0 && i + 1 < _leafNodes.Count) - // tvGroups.SelectedNode = _leafNodes[i + 1]; - } - - #endregion - - #region Language ComboBox event handlers - /// ------------------------------------------------------------------------------------ - private void HandleEditSourceBeforeTranslatingUsingBing(object sender, EventArgs e) - { - _viewModel.ShowEditSourceBeforeTranslatingDlg(this); - } - - /// ------------------------------------------------------------------------------------ - private void HandleSourceLangChanged(object sender, EventArgs e) - { - SaveChangesFromSingleItemView(); - _viewModel.SrcLangId = ((L10NCultureInfo)_comboSourceLang.SelectedItem).Name; - UpdateLanguageSensitiveControls(); - UpdateSingleItemView(); - _viewModel.SetNodeColors(); - } - - /// ------------------------------------------------------------------------------------ - private void HandleTargetLangChanged(object sender, EventArgs e) - { - SaveChangesFromSingleItemView(); - _viewModel.TgtLangId = ((L10NCultureInfo)_comboTargetLang.SelectedItem).Name; - UpdateLanguageSensitiveControls(); - UpdateSingleItemView(); - _viewModel.SetNodeColors(); - } - - #endregion - - #region Grid event handlers - /// ------------------------------------------------------------------------------------ - private void HandleGridCellPainting(object sender, DataGridViewCellPaintingEventArgs e) - { - if (e.ColumnIndex == -1 && e.RowIndex == -1) - { - // Draw an icon in the upper, left cell where the user can click to select all the rows. - e.Paint(e.CellBounds, e.PaintParts); - e.Handled = true; - var img = Resources.SelectAllRows; - var rc = new Rectangle(0, 0, img.Width, img.Height); - rc.X = e.CellBounds.X + (int)(Math.Round((e.CellBounds.Width - img.Width) / 2f, MidpointRounding.AwayFromZero)); - rc.Y = e.CellBounds.Y + (int)(Math.Round((e.CellBounds.Height - img.Height) / 2f, MidpointRounding.AwayFromZero)); - e.Graphics.DrawImage(img, rc); - } - } - - /// ------------------------------------------------------------------------------------ - private void HandleGridCellMouseEnter(object sender, DataGridViewCellEventArgs e) - { - if (e.ColumnIndex == -1 && e.RowIndex == -1) - { - var pt = PointToClient(MousePosition); - pt.Y += (SystemInformation.CaptionHeight + Cursor.Size.Height - 3); - _tooltip.Show("Select All Rows", this, pt); - } - } - - /// ------------------------------------------------------------------------------------ - private void HandleGridCellMouseLeave(object sender, DataGridViewCellEventArgs e) - { - if (e.ColumnIndex == -1 && e.RowIndex == -1) - _tooltip.Hide(_grid); - } - - /// ------------------------------------------------------------------------------------ - private void HandleGridCurrentRowChanged(object sender, EventArgs e) - { - _viewModel.SetCurrentNodeFromGridIndex(_grid.CurrentCellAddress.Y); - } - - /// ------------------------------------------------------------------------------------ - private void HandleGridCellFormatting(object sender, DataGridViewCellFormattingEventArgs e) - { - var gridNodes = _viewModel.AllLeafNodesShowingInGrid; - - if (gridNodes == null || e.RowIndex >= gridNodes.Count || e.ColumnIndex < 1 || e.ColumnIndex > 2) - return; - - var node = gridNodes[e.RowIndex]; - var objInfo = node.Manager.ComponentCache.FirstOrDefault(kvp => kvp.Value == node.Id); - e.CellStyle.Font = _viewModel.GetFontForObject(objInfo.Key); - } - - /// ------------------------------------------------------------------------------------ - private void HandleGridCellValueNeeded(object sender, DataGridViewCellValueEventArgs e) - { - var parentNode = _treeView.SelectedNode as LocTreeNode; - - switch (e.ColumnIndex) - { - case 0: e.Value = _viewModel.GetStringIdForGridIndex(e.RowIndex, parentNode.Name); break; - case 1: e.Value = _viewModel.GetSourceTextForGridIndex(e.RowIndex); break; - case 2: e.Value = _viewModel.GetTargetTextForGridIndex(e.RowIndex); break; - case 3: e.Value = _viewModel.GetSourceToolTipForGridIndex(e.RowIndex); break; - case 4: e.Value = _viewModel.GetTargetToolTipForGridIndex(e.RowIndex); break; - case 5: e.Value = _viewModel.GetCommentForGridIndex(e.RowIndex); break; - default: e.Value = null; break; - } - } - - /// ------------------------------------------------------------------------------------ - private void HandleGridCellValuePushed(object sender, DataGridViewCellValueEventArgs e) - { - if (_viewModel.AllLeafNodesShowingInGrid == null || e.RowIndex >= _viewModel.AllLeafNodesShowingInGrid.Count) - return; - - var locInfo = new LocalizingInfo(_viewModel.CurrentNode.Id); - locInfo.UpdateFields = UpdateFields.None; - switch (e.ColumnIndex) - { - case 2: - locInfo.Text = (e.Value as string) ?? string.Empty; - locInfo.UpdateFields = UpdateFields.Text; - break; - - case 4: - locInfo.ToolTipText = (e.Value as string) ?? string.Empty; - locInfo.UpdateFields = UpdateFields.ToolTip; - break; - - case 5: - locInfo.Comment = (e.Value as string) ?? string.Empty; - locInfo.UpdateFields = UpdateFields.Comment; - break; - - default: return; - } - - _viewModel.SaveChangesInMemory(locInfo); - UpdateViewAfterSavingChange(); - } - - /// ------------------------------------------------------------------------------------ - private void HandleColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) - { - var sortColumn = (int)_viewModel.GridSortField; - - if (sortColumn != e.ColumnIndex) - _viewModel.GridSortOrder = SortOrder.Ascending; - else - { - _viewModel.GridSortOrder = (_grid.Columns[sortColumn].HeaderCell.SortGlyphDirection == SortOrder.Ascending ? - SortOrder.Descending : SortOrder.Ascending); - } - - _viewModel.GridSortField = (NodeComparer.SortField)e.ColumnIndex; - UpdateGridSortGlyph(); - _viewModel.SortGridNodes(); - _viewModel.SetCurrentNodeFromGridIndex(_grid.CurrentCellAddress.Y); - _grid.Invalidate(); - } - - /// ------------------------------------------------------------------------------------ - private void UpdateGridSortGlyph() - { - var sortColumn = (int)_viewModel.GridSortField; - - foreach (DataGridViewColumn col in _grid.Columns) - col.HeaderCell.SortGlyphDirection = SortOrder.None; - - _grid.Columns[sortColumn].HeaderCell.SortGlyphDirection = _viewModel.GridSortOrder; - } - - #endregion - - /// ------------------------------------------------------------------------------------ - private void _buttonFallbackLanguages_Click(object sender, EventArgs e) - { - // TODO: Uncomment this button and test to see if the fallback system works. - using (var dlg = new FallbackLanguagesDlg()) - { - if (dlg.ShowDialog(this) == DialogResult.OK) - LocalizationManagerInternal.FallbackLanguageIds = dlg.FallbackLanguageIds.ToList(); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Paint a faint line between the source translation and the source tooltip and - /// shortcut keys text boxes. - /// - /// ------------------------------------------------------------------------------------ - private void HandleGroupSrcTranslationPaint(object sender, PaintEventArgs e) - { - using (var pen = new Pen(PaintingHelper.CalculateColor(Color.Black, Color.White, 45))) - { - e.Graphics.DrawLine(pen, _textBoxSrcTranslation.Left, _textBoxSrcTranslation.Bottom + 5, - _textBoxSrcTranslation.Right - 1, _textBoxSrcTranslation.Bottom + 5); - } - } - - private void _howToDistribute_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) - { - using (var dlg = new HowToDistributeDialog(LocalizationManager.EmailForSubmissions, - _callingManager.GetPathForLanguage(_viewModel.TgtLangId, true))) - { - dlg.ShowDialog(); - } - } - - private void LocalizeItemDlg_Load(object sender, EventArgs e) - { - - } - } -} diff --git a/src/L10NSharp/UI/LocalizeItemDlg.resx b/src/L10NSharp/UI/LocalizeItemDlg.resx deleted file mode 100644 index dd8299f..0000000 --- a/src/L10NSharp/UI/LocalizeItemDlg.resx +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 506, 11 - - - 111, 17 - - - True - - - True - - - True - - - True - - - True - - - True - - - 329, 17 - - - 17, 17 - - - 214, 17 - - - 41 - - \ No newline at end of file diff --git a/src/L10NSharp/UI/LocalizeItemDlgViewModel.cs b/src/L10NSharp/UI/LocalizeItemDlgViewModel.cs deleted file mode 100644 index 98795fe..0000000 --- a/src/L10NSharp/UI/LocalizeItemDlgViewModel.cs +++ /dev/null @@ -1,591 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Linq; -using System.Windows.Forms; -using L10NSharp.Translators; - -namespace L10NSharp.UI -{ - internal class LocalizeItemDlgViewModel - { - private bool _runInReadonlyMode; - private readonly Color _untranslatedNodeColor = Color.Peru; - private string _tgtLangId; - private string _srcLangId; - private LocTreeNode _currentNode; - private TreeNodeCollection _allNodes; - private BackgroundWorker _translationWorker; - - public List> AllLeafNodesShowingInGrid { get; private set; } - public List> AllLeafNodes { get; private set; } - public List> EnabledManagers; - private readonly Dictionary, HashSet> _modifiedManagersAndLanguages = - new Dictionary, HashSet>(); - public ITranslator BingTranslator { get; private set; } - public NodeComparer.SortField GridSortField { get; set; } - public SortOrder GridSortOrder { get; set; } - - /// ------------------------------------------------------------------------------------ - public LocalizeItemDlgViewModel(bool runInReadonlyMode) - { - _runInReadonlyMode = runInReadonlyMode; - AllLeafNodesShowingInGrid = new List>(); - SetLanguageIds(null, null); - } - - /// ------------------------------------------------------------------------------------ - public void SetLanguageIds(string srcLangId, string tgtLangId) - { - _srcLangId = srcLangId ?? LocalizationManagerInternal.FallbackLanguageIds.ToArray()[0]; - _tgtLangId = tgtLangId ?? LocalizationManager.UILanguageId; - CreateTranslator(); - } - - #region Properties - /// ------------------------------------------------------------------------------------ - public string SrcLangId - { - get { return _srcLangId; } - set - { - _srcLangId = value; - CreateTranslator(); - } - } - - /// ------------------------------------------------------------------------------------ - public string TgtLangId - { - get { return _tgtLangId; } - set - { - _tgtLangId = value; - CreateTranslator(); - } - } - - /// ------------------------------------------------------------------------------------ - public LocTreeNode CurrentNode - { - get { return _currentNode; } - set - { - _currentNode = value; - - AllLeafNodesShowingInGrid = (_currentNode == null || _currentNode.FirstNode == null ? - new List>() : GetLeafNodesOfNode(_currentNode).ToList()); - - SortGridNodes(); - } - } - - /// ------------------------------------------------------------------------------------ - public void SetCurrentNodeFromGridIndex(int index) - { - if (index >= 0 && index < AllLeafNodesShowingInGrid.Count) - _currentNode = AllLeafNodesShowingInGrid[index]; - } - - /// ------------------------------------------------------------------------------------ - public string CurrentNodeSourceText - { - get { return (_currentNode != null ? _currentNode.GetText(_srcLangId) : null); } - } - - /// ------------------------------------------------------------------------------------ - public string CurrentNodeTargetText - { - get - { - if (_currentNode == null) - return null; - - return (_currentNode.GetTranslatedText(_tgtLangId) ?? _currentNode.GetText(_tgtLangId)); - } - } - - /// ------------------------------------------------------------------------------------ - public string CurrentNodeSourceToolTip - { - get { return (_currentNode != null ? _currentNode.GetToolTip(_srcLangId) : null); } - } - - /// ------------------------------------------------------------------------------------ - public string CurrentNodeTargetToolTip - { - get - { - if (_currentNode == null) - return null; - - return (_currentNode.GetTranslatedToolTip(_tgtLangId) ?? _currentNode.GetToolTip(_tgtLangId)); - } - } - - /// ------------------------------------------------------------------------------------ - public string CurrentNodeSourceShortcutKeys - { - get { return (_currentNode != null ? _currentNode.GetShortcutKeys(_srcLangId) : null); } - } - - /// ------------------------------------------------------------------------------------ - public string CurrentNodeTargetShortcutKeys - { - get - { - if (_currentNode == null) - return null; - - return (_currentNode.GetTranslatedShortcutKeys(_tgtLangId) ?? _currentNode.GetShortcutKeys(_tgtLangId)); - } - } - - /// ------------------------------------------------------------------------------------ - public string CurrentNodeComment - { - get { return (_currentNode != null ? _currentNode.GetComment() : null); } - } - - /// ------------------------------------------------------------------------------------ - public bool TranslatorBusy - { - get { return (_translationWorker != null && _translationWorker.IsBusy); } - } - - #endregion - - /// ------------------------------------------------------------------------------------ - private void CreateTranslator() - { - var worker = new BackgroundWorker(); - worker.DoWork += delegate { BingTranslator = new BingTranslator(_srcLangId, _tgtLangId); }; - worker.RunWorkerAsync(); - } - - /// ------------------------------------------------------------------------------------ - public void LoadTreeNodes(TreeView treeVw) - { - AllLeafNodes = new List>(); - - EnabledManagers = LocalizationManagerInternal.LoadedManagers.Values - .OrderBy(lm => lm.Name).ToList(); - - foreach (var lm in EnabledManagers) - { - _runInReadonlyMode |= !lm.CanCustomizeLocalizations; - var node = new LocTreeNode(lm, lm.Name, null, lm.Name); - treeVw.Nodes.Add(node); - var childNodes = node.Nodes; - - lm.StringCache.LoadGroupNodes(childNodes); - AllLeafNodes.AddRange(lm.StringCache.LeafNodeList); - _allNodes = treeVw.Nodes; - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Finds the node in the specified node collection having the specified id. If a - /// node cannot be found, then each nodes node collection will be searched, and so on. - /// - /// ------------------------------------------------------------------------------------ - public LocTreeNode FindNode(string id, TreeNodeCollection nodeCollection) - { - if (id == null) - return null; - - foreach (LocTreeNode node in nodeCollection) - { - if (node.Id == id) - return node; - - var nd = FindNode(id, node.Nodes); - if (nd != null) - return nd; - } - - return null; - } - - /// ------------------------------------------------------------------------------------ - public bool GetIsDirty() - { - return (AllLeafNodes.Any(n => n.GetHasModifications(true))); - } - - /// ------------------------------------------------------------------------------------ - public IEnumerable> GetModifiedManagers( - string langId = null) => - _modifiedManagersAndLanguages.Where(m => m.Value.Contains( - langId ?? LocalizationManager.UILanguageId)).Select(m => m.Key); - - /// ------------------------------------------------------------------------------------ - public bool Save() - { - if (_runInReadonlyMode) - return false; - - var stringsLocalized = false; - - foreach (var node in AllLeafNodes.Where(n => n.SavedTranslationInfo.Count > 0)) - { - stringsLocalized = true; - - foreach (var locInfo in node.SavedTranslationInfo.Values) - node.Manager.StringCache.UpdateLocalizedInfo(locInfo); - - // Update each object with the specified id, with the localized string(s). - foreach (var component in GetComponentsForId(node.Manager, node.Id).Where(o => o != null)) - node.Manager.ApplyLocalization(component); - } - - foreach (var lm in _modifiedManagersAndLanguages.Keys) - { - lm.PrepareToCustomizeLocalizations(); - lm.SaveIfDirty(_modifiedManagersAndLanguages[lm]); - - // If saving fails, the LocalizationManagerInternal will record the problem . - _runInReadonlyMode |= !lm.CanCustomizeLocalizations; - } - - return stringsLocalized; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Saves localization changes. - /// - /// ------------------------------------------------------------------------------------ - public void SaveChangesInMemory(LocalizingInfo locInfo) - { - if (locInfo?.Id == null || locInfo.UpdateFields == UpdateFields.None) - return; - - SaveChangesInMemory(CurrentNode, locInfo); - } - - /// ------------------------------------------------------------------------------------ - public void SaveChangesInMemory(LocTreeNode node, LocalizingInfo locInfo) - { - if (locInfo?.Id == null || locInfo.UpdateFields == UpdateFields.None || _tgtLangId == _srcLangId) - { - return; - } - - if (locInfo.Text == (node.GetText(_tgtLangId) ?? string.Empty) && - locInfo.ToolTipText == (node.GetToolTip(_tgtLangId) ?? string.Empty) && - locInfo.ShortcutKeys == (node.GetShortcutKeys(_tgtLangId) ?? string.Empty)) - { - return; - } - - locInfo.LangId = _tgtLangId; - - if (!_modifiedManagersAndLanguages.TryGetValue(node.Manager, out var modifiedLangIds)) - { - _modifiedManagersAndLanguages[node.Manager] = modifiedLangIds = new HashSet(); - } - modifiedLangIds.Add(_tgtLangId); - - if (!node.SavedTranslationInfo.ContainsKey(_tgtLangId)) - node.SavedTranslationInfo[_tgtLangId] = locInfo; - else - { - if ((locInfo.UpdateFields & UpdateFields.Text) == UpdateFields.Text) - node.SavedTranslationInfo[_tgtLangId].Text = (locInfo.Text == string.Empty ? null : locInfo.Text); - - if ((locInfo.UpdateFields & UpdateFields.ToolTip) == UpdateFields.ToolTip) - node.SavedTranslationInfo[_tgtLangId].ToolTipText = (locInfo.ToolTipText == string.Empty ? null : locInfo.ToolTipText); - - if ((locInfo.UpdateFields & UpdateFields.ShortcutKeys) == UpdateFields.ShortcutKeys) - node.SavedTranslationInfo[_tgtLangId].ShortcutKeys = (locInfo.ShortcutKeys == string.Empty ? null : locInfo.ShortcutKeys); - - if ((locInfo.UpdateFields & UpdateFields.Comment) == UpdateFields.Comment) - node.SavedComment = (locInfo.Comment == string.Empty ? null : locInfo.Comment); - - node.SavedTranslationInfo[_tgtLangId].UpdateFields |= locInfo.UpdateFields; - } - } - - /// ------------------------------------------------------------------------------------ - private IEnumerable GetComponentsForId(ILocalizationManagerInternal lm, string id) - { - return lm.ComponentCache.Where(kvp => kvp.Value == id).Select(kvp => kvp.Key); - } - - /// ------------------------------------------------------------------------------------ - public string GetNumberOfTranslatedItemsString() - { - int numStringsTranslated = EnabledManagers.Sum(lm => AllLeafNodes.Count(n => - (n.GetHasModifications(false) || lm.StringCache.DoTranslationsExist(TgtLangId, n.Id)))); - - return $"{numStringsTranslated} of {AllLeafNodes.Count} Items Translated"; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Goes through each loaded LocalizationManagerInternal, looking for the one whose component - /// cache contains the specified component. When it's found, that component's id is returned. - /// - /// ------------------------------------------------------------------------------------ - public string GetObjIdFromAnyCache(IComponent component) - { - if (component != null) - { - foreach (var manager in LocalizationManagerInternal.LoadedManagers.Values) - { - string id; - if (manager.ComponentCache.TryGetValue(component, out id)) - return id; - } - } - - return null; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Attempts to get the image for the specified object, if one exists. - /// - /// ------------------------------------------------------------------------------------ - public Image GetObjectsImage(object obj) - { - var img = Utils.GetProperty(obj, "Image") as Image; - if (img != null) - return img; - - var imgList = Utils.GetProperty(obj, "ImageList") as ImageList; - if (imgList != null) - { - var index = Utils.GetProperty(obj, "ImageIndex"); - if (index != null && index is int) - { - int i = (int)index; - if (i >= 0 && i < imgList.Images.Count) - return imgList.Images[i]; - } - } - - return null; - } - - /// ------------------------------------------------------------------------------------ - public Font GetFontForObject(object obj) - { - return (obj == null ? null : - Utils.GetProperty(obj, "Font") as Font) ?? LocalizeItemDlg.DefaultDisplayFont; - } - - /// ------------------------------------------------------------------------------------ - public IComponent GetFirstObjectForId() - { - return CurrentNode.Manager.ComponentCache.FirstOrDefault(k => k.Value == CurrentNode.Id).Key; - } - - /// ------------------------------------------------------------------------------------ - public void Translate(IDictionary> nodesToTranslate, - Action progressAction) - { - _translationWorker = new BackgroundWorker(); - _translationWorker.WorkerReportsProgress = true; - _translationWorker.WorkerSupportsCancellation = true; - _translationWorker.DoWork += HandleTranslateItems; - - if (progressAction != null) - { - _translationWorker.ProgressChanged += ((sender, args) => - progressAction(args.ProgressPercentage, (int)args.UserState)); - } - - _translationWorker.RunWorkerAsync(nodesToTranslate); - } - - /// ------------------------------------------------------------------------------------ - private void HandleTranslateItems(object sender, DoWorkEventArgs e) - { - var worker = sender as BackgroundWorker; - var nodesToTranslate = e.Argument as IDictionary>; - int i = 0; - - foreach (var kvp in nodesToTranslate) - { - var node = kvp.Value; - var locInfo = new LocalizingInfo(node.Id); - locInfo.UpdateFields = UpdateFields.None; - locInfo.LangId = TgtLangId; - - var text = node.GetText(SrcLangId); - if (!string.IsNullOrEmpty(text)) - { - text = (BingTranslator.TranslateText(text) ?? string.Empty).Trim(); - if (text != string.Empty) - { - locInfo.Text = text; - locInfo.UpdateFields |= UpdateFields.Text; - } - } - - text = node.GetToolTip(SrcLangId); - if (!string.IsNullOrEmpty(text)) - { - text = (BingTranslator.TranslateText(text) ?? string.Empty).Trim(); - if (text != string.Empty) - { - locInfo.ToolTipText = text; - locInfo.UpdateFields |= UpdateFields.ToolTip; - } - } - - if (locInfo.UpdateFields != UpdateFields.None) - { - SaveChangesInMemory(node, locInfo); - worker.ReportProgress(++i, kvp.Key); - } - } - } - - /// ------------------------------------------------------------------------------------ - private IEnumerable> GetLeafNodesOfNode(LocTreeNode node) - { - foreach (var childNode in node.Nodes.Cast>()) - { - if (AllLeafNodes.Contains(childNode)) - yield return childNode; - else - { - foreach (var leafNode in GetLeafNodesOfNode(childNode)) - yield return leafNode; - } - } - } - - /// ------------------------------------------------------------------------------------ - public string GetStringIdForGridIndex(int index, string prefixToRemove) - { - if (index >= AllLeafNodesShowingInGrid.Count || index < 0) - return null; - - var node = AllLeafNodesShowingInGrid[index]; - var id = node.Id; - if (!string.IsNullOrEmpty(prefixToRemove)) - id = id.Replace(prefixToRemove, string.Empty).Trim('.'); - return id; - } - - /// ------------------------------------------------------------------------------------ - public void SortGridNodes() - { - AllLeafNodesShowingInGrid.Sort( - new NodeComparer(_srcLangId, _tgtLangId, GridSortOrder, GridSortField)); - } - - #region Methods for returning various grid fields for a specified index - /// ------------------------------------------------------------------------------------ - public string GetSourceTextForGridIndex(int index) - { - return (index >= AllLeafNodesShowingInGrid.Count ? null : - AllLeafNodesShowingInGrid[index].GetText(_srcLangId)); - } - - /// ------------------------------------------------------------------------------------ - public string GetTargetTextForGridIndex(int index) - { - if (index >= AllLeafNodesShowingInGrid.Count) - return null; - - return (AllLeafNodesShowingInGrid[index].GetTranslatedText(_tgtLangId) ?? - AllLeafNodesShowingInGrid[index].GetText(_tgtLangId)); - } - - /// ------------------------------------------------------------------------------------ - public string GetSourceToolTipForGridIndex(int index) - { - return (index >= AllLeafNodesShowingInGrid.Count ? null : - AllLeafNodesShowingInGrid[index].GetToolTip(_srcLangId)); - } - - /// ------------------------------------------------------------------------------------ - public string GetTargetToolTipForGridIndex(int index) - { - if (index >= AllLeafNodesShowingInGrid.Count) - return null; - - return (AllLeafNodesShowingInGrid[index].GetTranslatedToolTip(_tgtLangId) ?? - AllLeafNodesShowingInGrid[index].GetToolTip(_tgtLangId)); - } - - /// ------------------------------------------------------------------------------------ - public string GetCommentForGridIndex(int index) - { - return (index >= AllLeafNodesShowingInGrid.Count ? null : - AllLeafNodesShowingInGrid[index].GetComment()); - } - - #endregion - - #region Methods for setting node colors - /// ------------------------------------------------------------------------------------ - public Color SetNodeColors() - { - return SetNodeColors(_allNodes); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Sets the color of the specified node (and all its parents) based on whether or - /// not the node represents a localization entry for which translations exist - /// (other than for the default, that is). - /// - /// ------------------------------------------------------------------------------------ - private Color SetNodeColors(TreeNodeCollection nodeCollection) - { - if (nodeCollection == null) - return Color.Empty; - - var clrParent = Color.Empty; - - foreach (LocTreeNode node in nodeCollection) - { - if (node.Nodes.Count > 0) - { - clrParent = SetNodeColors(node.Nodes); - node.ForeColor = clrParent; - } - else if (node.Id != null) - { - if (node.SavedTranslationInfo != null || - node.Manager.StringCache.DoTranslationsExist(_tgtLangId, node.Id)) - { - node.ForeColor = SystemColors.WindowText; - } - else - { - node.ForeColor = _untranslatedNodeColor; - if (clrParent == Color.Empty) - clrParent = _untranslatedNodeColor; - } - } - } - - return clrParent; - } - - #endregion - - /// ------------------------------------------------------------------------------------ - public void ShowEditSourceBeforeTranslatingDlg(IWin32Window parent) - { - if (BingTranslator == null) - return; - - using (var dlg = new EditSourceBeforeTranslatingDlg(CurrentNodeSourceText, - _srcLangId, _tgtLangId, "Bing", BingTranslator)) - { - dlg.ShowDialog(parent); - } - } - } - -} diff --git a/src/L10NSharp/UI/Utils.cs b/src/L10NSharp/Utils.cs similarity index 68% rename from src/L10NSharp/UI/Utils.cs rename to src/L10NSharp/Utils.cs index 9515bc0..5e5ef9b 100644 --- a/src/L10NSharp/UI/Utils.cs +++ b/src/L10NSharp/Utils.cs @@ -1,9 +1,8 @@ using System; using System.Reflection; using System.Runtime.InteropServices; -using System.Windows.Forms; -namespace L10NSharp.UI +namespace L10NSharp { /// ---------------------------------------------------------------------------------------- internal static class Utils @@ -22,56 +21,6 @@ public static bool IsMono } } - - [DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "SendMessage")] - private static extern void SendMessageWindows(IntPtr hWnd, int msg, int wParam, int lParam); - - public static void SendMessage(IntPtr hWnd, int msg, int wParam, int lParam) - { - if (IsMono) - Console.WriteLine("Warning--using unimplemented method SendMessage"); // FIXME Linux - else - { - SendMessageWindows(hWnd, msg, wParam, lParam); - } - } - - - private const int WM_SETREDRAW = 0xB; - - /// ------------------------------------------------------------------------------------ - /// - /// Turns window redrawing on or off. After turning on, the window will be invalidated. - /// - /// ------------------------------------------------------------------------------------ - public static void SetWindowRedraw(Control ctrl, bool turnOn) - { - SetWindowRedraw(ctrl, turnOn, true); - } - - /// ------------------------------------------------------------------------------------ - public static void SetWindowRedraw(Control ctrl, bool turnOn, - bool invalidateAfterTurningOn) - { - if (ctrl != null && !ctrl.IsDisposed && ctrl.IsHandleCreated) - { - if (IsMono) - { - if (turnOn) - ctrl.ResumeLayout(invalidateAfterTurningOn); - else - ctrl.SuspendLayout(); - } - else - { - SendMessage(ctrl.Handle, WM_SETREDRAW, (turnOn ? 1 : 0), 0); - } - - if (turnOn && invalidateAfterTurningOn) - ctrl.Invalidate(true); - } - } - /// ------------------------------------------------------------------------------------ /// /// Asks whether the specified property on the specified binding exists. diff --git a/src/L10NSharp/XLiffUtils/XLiffBody.cs b/src/L10NSharp/XLiffUtils/XLiffBody.cs index cb396f6..1a14658 100644 --- a/src/L10NSharp/XLiffUtils/XLiffBody.cs +++ b/src/L10NSharp/XLiffUtils/XLiffBody.cs @@ -20,7 +20,6 @@ using System.Collections.Generic; using System.Threading; using System.Xml.Serialization; -using L10NSharp.XLiffUtils; namespace L10NSharp.XLiffUtils { diff --git a/src/L10NSharp/XLiffUtils/XliffLocalizationManager.cs b/src/L10NSharp/XLiffUtils/XliffLocalizationManager.cs index 867ee6d..7a6a961 100644 --- a/src/L10NSharp/XLiffUtils/XliffLocalizationManager.cs +++ b/src/L10NSharp/XLiffUtils/XliffLocalizationManager.cs @@ -2,16 +2,13 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; -using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Security; using System.Security.Permissions; using System.Text.RegularExpressions; -using System.Windows.Forms; using System.Xml.Linq; -using L10NSharp.UI; namespace L10NSharp.XLiffUtils { @@ -20,8 +17,6 @@ internal class XliffLocalizationManager : ILocalizationManagerInternal ComponentCache { get; } - public Dictionary ToolTipCtrls { get; } - public Dictionary> LocalizableComponents { get; } #region Static methods /// ------------------------------------------------------------------------------------ @@ -131,10 +124,7 @@ internal XliffLocalizationManager(string appId, string origExtension, string app } ComponentCache = new Dictionary(); - ToolTipCtrls = new Dictionary(); StringCache = new XliffLocalizedStringCache(this); - LocalizableComponents = new Dictionary>(); } /// @@ -284,33 +274,6 @@ public void Dispose() #endregion - #region Methods for showing localization dialog box - /// ------------------------------------------------------------------------------------ - public void ShowLocalizationDialogBox(bool runInReadonlyMode, IWin32Window owner = null) - { - LocalizeItemDlg.ShowDialog(this, "", runInReadonlyMode, owner); - } - - /// ------------------------------------------------------------------------------------ - public static void ShowLocalizationDialogBox(IComponent component, - IWin32Window owner = null) - { - if (owner == null) - owner = (component as Control)?.FindForm(); - TipDialog.ShowAltShiftClickTip(owner); - LocalizeItemDlg.ShowDialog(LocalizationManagerInternal.GetLocalizationManagerForComponent(component), - component, false, owner); - } - - /// ------------------------------------------------------------------------------------ - public static void ShowLocalizationDialogBox(string id, IWin32Window owner = null) - { - TipDialog.ShowAltShiftClickTip(owner); - LocalizeItemDlg.ShowDialog(LocalizationManagerInternal.GetLocalizationManagerForString(id), id, false, owner); - } - - #endregion - #region Public Properties /// ------------------------------------------------------------------------------------ /// @@ -454,139 +417,6 @@ public IEnumerable FilenamesToAddToCache #endregion #region Methods for caching and localizing objects. - /// ------------------------------------------------------------------------------------ - /// - /// Adds the specified component to the localization manager's cache of objects to be - /// localized and then applies localizations for the current UI language. - /// - /// ------------------------------------------------------------------------------------ - public void RegisterComponentForLocalizing(IComponent component, string id, string - defaultText, string defaultTooltip, string defaultShortcutKeys, string comment) - { - RegisterComponentForLocalizing(new LocalizingInfo(component, id) - { - Text = defaultText, - ToolTipText = defaultTooltip, - ShortcutKeys = defaultShortcutKeys, - Comment = comment - }, null); - } - - public void RegisterComponentForLocalizing(LocalizingInfo info, - Action successAction) - { - var component = info.Component; - var id = info.Id; - if (component == null || string.IsNullOrWhiteSpace(id)) - return; - - try - { - - // This if/else used to be more concise but sometimes there were occasions - // adding an item the first time using ComponentCache[component] = id would throw an - // index outside the bounds of the array exception. I have no clue why nor - // can I reliably reproduce the error nor do I know if this change will solve - // the problem. Hopefully it will, but my guess is the same underlying code - // will be called. - if (ComponentCache.ContainsKey(component)) - ComponentCache[component] = id; //somehow, we sometimes see "Msg: Index was outside the bounds of the array." - else - { - var lm = LocalizationManagerInternal.GetLocalizationManagerForString(id); - if (lm != null && lm != this) - { - lm.RegisterComponentForLocalizing(info, successAction); - return; - } - if (component is ILocalizableComponent) - ComponentCache.Add(component, id); - else - { - // If this is the first time this object has passed this way, then - // prepare it to be available for end-user localization. - PrepareComponentForRuntimeLocalization(component); - ComponentCache.Add(component, id); - // Make it available for the config dialog to localize. - StringCache.UpdateLocalizedInfo(info); - } - } - - successAction?.Invoke(this, info); - } - catch (Exception) - { -#if DEBUG - throw; // if you hit this ( Index was outside the bounds of the array) try to figure out why. What is the hash (?) value for the component? -#endif - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Prepares the specified component for runtime localization by subscribing to a - /// mouse down event that will monitor whether or not to show the localization - /// dialog box. - /// - /// ------------------------------------------------------------------------------------ - private void PrepareComponentForRuntimeLocalization(IComponent component) - { - var toolStripItem = component as ToolStripItem; - if (toolStripItem != null) - { - toolStripItem.MouseDown += HandleToolStripItemMouseDown; - toolStripItem.Disposed += HandleToolStripItemDisposed; - return; - } - - // For component that are part of an owning parent control that needs to - // do some special handling when the user wants to localize, we need - // the parent to subscribe to the mouse event, but we don't want to - // subscribe once per column/page, so we first unsubscribe and then - // subscribe. It's a little ugly, but there doesn't seem to be a better way: - // http://stackoverflow.com/questions/399648/preventing-same-event-handler-assignment-multiple-times - - var ctrl = component as Control; - if (ctrl != null) - { - ctrl.Disposed += HandleControlDisposed; - - TabPage tpg = ctrl as TabPage; - if (tpg != null && tpg.Parent is TabControl) - { - tpg.Parent.MouseDown -= HandleControlMouseDown; - tpg.Parent.MouseDown += HandleControlMouseDown; - tpg.Parent.Disposed -= HandleControlDisposed; - tpg.Parent.Disposed += HandleControlDisposed; - tpg.Disposed += HandleTabPageDisposed; - return; - } - - ctrl.MouseDown += HandleControlMouseDown; - return; - } - - var columnHeader = component as ColumnHeader; - if (columnHeader != null && columnHeader.ListView != null) - { - columnHeader.ListView.Disposed -= HandleListViewDisposed; - columnHeader.ListView.Disposed += HandleListViewDisposed; - columnHeader.ListView.ColumnClick -= HandleListViewColumnHeaderClicked; - columnHeader.ListView.ColumnClick += HandleListViewColumnHeaderClicked; - columnHeader.Disposed += HandleListViewColumnDisposed; - } - - var dataGridViewColumn = component as DataGridViewColumn; - if (dataGridViewColumn != null && dataGridViewColumn.DataGridView != null) - { - dataGridViewColumn.DataGridView.CellMouseDown -= HandleDataGridViewCellMouseDown; - dataGridViewColumn.DataGridView.CellMouseDown += HandleDataGridViewCellMouseDown; - dataGridViewColumn.DataGridView.Disposed -= HandleDataGridViewDisposed; - dataGridViewColumn.DataGridView.Disposed += HandleDataGridViewDisposed; - dataGridViewColumn.Disposed += HandleColumnDisposed; - } - } - /// ------------------------------------------------------------------------------------ public void SaveIfDirty(ICollection langIdsToForceCreate) { @@ -598,7 +428,7 @@ public void SaveIfDirty(ICollection langIdsToForceCreate) { CanCustomizeLocalizations = false; if (langIdsToForceCreate != null && langIdsToForceCreate.Any()) - MessageBox.Show(e.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); + throw new IOException(e.Message); } } @@ -721,18 +551,18 @@ public string GetStringFromStringCache(string uiLangId, string id) } /// ------------------------------------------------------------------------------------ - private string GetTooltipFromStringCache(string uiLangId, string id) + protected string GetTooltipFromStringCache(string uiLangId, string id) { var realLangId = LocalizationManagerInternal.MapToExistingLanguageIfPossible(uiLangId); return StringCache.GetToolTipText(realLangId, id); } /// ------------------------------------------------------------------------------------ - private Keys GetShortCutKeyFromStringCache(string uiLangId, string id) + /*private Keys GetShortCutKeyFromStringCache(string uiLangId, string id) { var realLangId = LocalizationManagerInternal.MapToExistingLanguageIfPossible(uiLangId); return StringCache.GetShortcutKeys(realLangId, id); - } + }*/ #endregion @@ -751,456 +581,8 @@ private Keys GetShortCutKeyFromStringCache(string uiLangId, string id) #endregion #region Methods that apply localizations to an object. - public void ApplyLocalizationsToILocalizableComponent(LocalizingInfo locInfo) - { - if (locInfo.Component is ILocalizableComponent locComponent && - LocalizableComponents.TryGetValue(locComponent, out var idToLocInfo)) - { - ApplyLocalizationsToLocalizableComponent(locComponent, idToLocInfo); - return; - } -#if DEBUG - var msg = - "Either locInfo.component is not an ILocalizableComponent or LocalizableComponents hasn't been updated with id={0}."; - throw new ApplicationException(string.Format(msg, locInfo.Id)); -#endif - } - - /// ------------------------------------------------------------------------------------ - /// - /// Reapplies the localizations to all components in the localization manager's cache of - /// localized components. - /// - /// ------------------------------------------------------------------------------------ - public void ReapplyLocalizationsToAllComponents() - { - foreach (var component in ComponentCache.Keys) - ApplyLocalization(component); - - LocalizeItemDlg.FireStringsLocalizedEvent(this); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Recreates the tooltip control and updates the tooltip text for each object having - /// a tooltip. This is necessary sometimes when controls get moved from form to form - /// during runtime. - /// - /// ------------------------------------------------------------------------------------ - public void RefreshToolTips() - { - foreach (var toolTipCtrl in ToolTipCtrls.Values) - toolTipCtrl.Dispose(); - - ToolTipCtrls.Clear(); - - // This used to be a for-each, but on rare occasions, a "Collection was - // modified; enumeration operation may not execute" exception would be - // thrown. This should solve the problem. - var controls = ComponentCache.Where(x => x.Key is Control).ToArray(); - foreach (var ctrl in controls) - { - var toolTipText = GetTooltipFromStringCache(UILanguageId, ctrl.Value); - if (!string.IsNullOrEmpty(toolTipText)) //JH: hoping to speed this up a bit - ApplyLocalizedToolTipToControl((Control)ctrl.Key, toolTipText); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Initializes the specified component. - /// - /// ------------------------------------------------------------------------------------ - public void ApplyLocalization(IComponent component) - { - if (component == null) - return; - - if (!ComponentCache.TryGetValue(component, out var id)) - return; - - if (component is ILocalizableComponent locComponent) - { - if (LocalizableComponents.TryGetValue(locComponent, out var idToLocInfo)) - { - ApplyLocalizationsToLocalizableComponent(locComponent, idToLocInfo); - return; - } - } - - if (ApplyLocalizationsToControl(component as Control, id)) - return; - - if (ApplyLocalizationsToToolStripItem(component as ToolStripItem, id)) - return; + protected static string UILanguageId => LocalizationManager.UILanguageId; - if (ApplyLocalizationsToListViewColumnHeader(component as ColumnHeader, id)) - return; - - ApplyLocalizationsToDataGridViewColumn(component as DataGridViewColumn, id); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Initializes the specified ILocalizableComponent. - /// - /// ------------------------------------------------------------------------------------ - internal void ApplyLocalizationsToLocalizableComponent( - ILocalizableComponent locComponent, Dictionary idToLocInfo) - { - if (locComponent == null) - return; - - foreach (var kvp in idToLocInfo) - { - var id = kvp.Key; - var locInfo = kvp.Value; - locComponent.ApplyLocalizationToString(locInfo.Component, id, GetLocalizedString(id, locInfo.Text)); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Initializes the specified control. - /// - /// ------------------------------------------------------------------------------------ - private bool ApplyLocalizationsToControl(Control ctrl, string id) - { - if (ctrl == null) - return false; - - var text = GetStringFromStringCache(UILanguageId, id); - var toolTipText = GetTooltipFromStringCache(UILanguageId, id); - - if (text != null && string.CompareOrdinal(ctrl.Text, text) != 0) - ctrl.Text = text; - - ApplyLocalizedToolTipToControl(ctrl, toolTipText); - return true; - } - - /// ------------------------------------------------------------------------------------ - private void ApplyLocalizedToolTipToControl(Control ctrl, string toolTipText) - { - var topCtrl = LocalizationManagerInternal.GetRealTopLevelControl(ctrl); - if (topCtrl == null) - return; - - // Check if the control's top level control has a reference to a tooltip. If - // it does, then use that tooltip for assigning tooltip text to the control. - // Otherwise, create a new tooltip and reference it using the control's top - // level control. - if (!ToolTipCtrls.TryGetValue(topCtrl, out var ttCtrl)) - { - if (string.IsNullOrEmpty(toolTipText)) - return; - - ttCtrl = new ToolTip(); - ToolTipCtrls[topCtrl] = ttCtrl; - topCtrl.ParentChanged += HandleToolTipRefChanged; - topCtrl.HandleDestroyed += HandleToolTipRefDestroyed; - } - - ttCtrl.SetToolTip(ctrl, toolTipText); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Handles the case when a tooltip instance was created and assigned to a top level - /// control that has now been added to another control, thus making the other control - /// top level instead. Therefore, we need to make sure the tooltip is reassigned to - /// the new top level control. - /// - /// ------------------------------------------------------------------------------------ - private void HandleToolTipRefChanged(object sender, EventArgs e) - { - var oldTopCtrl = sender as Control; - var newTopCtrl = LocalizationManagerInternal.GetRealTopLevelControl(oldTopCtrl); - if (oldTopCtrl == null || newTopCtrl == null) - return; - - oldTopCtrl.ParentChanged -= HandleToolTipRefChanged; - newTopCtrl.ParentChanged += HandleToolTipRefChanged; - RefreshToolTips(); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Handles removing tooltip controls from the global tool tip collection for top level - /// controls that are destroyed and have controls on them using tool tip controls from - /// that collection. - /// - /// ------------------------------------------------------------------------------------ - private void HandleToolTipRefDestroyed(object sender, EventArgs e) - { - if (!(sender is Control topCtrl)) - return; - - topCtrl.ParentChanged -= HandleToolTipRefChanged; - topCtrl.HandleDestroyed -= HandleToolTipRefDestroyed; - - if (ToolTipCtrls.TryGetValue(topCtrl, out var ttCtrl)) - ttCtrl.Dispose(); - - ToolTipCtrls.Remove(topCtrl); - } - - private static string UILanguageId => LocalizationManager.UILanguageId; - - /// ------------------------------------------------------------------------------------ - private bool ApplyLocalizationsToToolStripItem(ToolStripItem item, string id) - { - if (item == null) - return false; - - var text = GetStringFromStringCache(UILanguageId, id); - var toolTipText = GetTooltipFromStringCache(UILanguageId, id); - item.Text = text ?? LocalizationManager.StripOffLocalizationInfoFromText(item.Text); - item.ToolTipText = toolTipText ?? LocalizationManager.StripOffLocalizationInfoFromText(item.ToolTipText); - - var shortcutKeys = GetShortCutKeyFromStringCache(UILanguageId, id); - if (item is ToolStripMenuItem menuItem && shortcutKeys != Keys.None) - menuItem.ShortcutKeys = shortcutKeys; - - return true; - } - - /// ------------------------------------------------------------------------------------ - private bool ApplyLocalizationsToListViewColumnHeader(ColumnHeader hdr, string id) - { - if (hdr == null) - return false; - - var text = GetStringFromStringCache(UILanguageId, id); - hdr.Text = text ?? LocalizationManager.StripOffLocalizationInfoFromText(hdr.Text); - return true; - } - - /// ------------------------------------------------------------------------------------ - private bool ApplyLocalizationsToDataGridViewColumn(DataGridViewColumn col, string id) - { - if (col == null) - return false; - - var text = GetStringFromStringCache(UILanguageId, id); - col.HeaderText = text ?? LocalizationManager.StripOffLocalizationInfoFromText(col.HeaderText); - col.ToolTipText = GetTooltipFromStringCache(UILanguageId, id); - return true; - } - - #endregion - - #region Mouse down, handle destroyed, and dispose handlers - /// ------------------------------------------------------------------------------------ - /// - /// Handles Ctrl-Shift-Click on ToolStripItems; - /// - /// ------------------------------------------------------------------------------------ - internal void HandleToolStripItemMouseDown(object sender, MouseEventArgs e) - { - if (!DoHandleMouseDown) - return; - - // Make sure all drop-downs are closed that are in the - // chain of menu items for this item. - Form owningForm = null; - if (sender is ToolStripDropDownItem tsddi) - { - owningForm = tsddi.Owner?.FindForm(); - while (tsddi != null) - { - tsddi.DropDown.Close(); - - if (tsddi.Owner is ContextMenuStrip menuStrip) - menuStrip.Close(); - - tsddi = tsddi.OwnerItem as ToolStripDropDownItem; - } - } - - LocalizeItemDlg.ShowDialog(this, (IComponent)sender, false, - owningForm); - } - - private static bool DoHandleMouseDown => - LocalizationManager.EnableClickingOnControlToBringUpLocalizationDialog && - Control.ModifierKeys == (Keys.Alt | Keys.Shift); - - public Icon ApplicationIcon - { - get => _applicationIcon; - set => _applicationIcon = value; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Handles the tool strip item disposed. - /// - /// ------------------------------------------------------------------------------------ - private void HandleToolStripItemDisposed(object sender, EventArgs e) - { - if (sender is ToolStripItem item) - { - item.MouseDown -= HandleToolStripItemMouseDown; - item.Disposed -= HandleToolStripItemDisposed; - - ComponentCache.Remove(item); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Handles Alt-Shift-Click on controls. - /// - /// ------------------------------------------------------------------------------------ - internal void HandleControlMouseDown(object sender, MouseEventArgs e) - { - if (!DoHandleMouseDown) - return; - - var ctrl = sender as Control; - - if (ctrl is TabControl tabControl) - { - for (int i = 0; i < tabControl.TabPages.Count; i++) - { - if (tabControl.GetTabRect(i).Contains(e.Location)) - { - ctrl = tabControl.TabPages[i]; - break; - } - } - } - - var lm = LocalizationManagerInternal.GetLocalizationManagerForComponent(ctrl); - - LocalizationManager.OnLaunchingLocalizationDialog(lm); - LocalizeItemDlg.ShowDialog(lm, ctrl, false, ctrl?.FindForm()); - LocalizationManager.OnClosingLocalizationDialog(lm); - } - - /// ------------------------------------------------------------------------------------ - /// - /// When controls get destroyed, do a little clean-up. - /// - /// ------------------------------------------------------------------------------------ - internal void HandleControlDisposed(object sender, EventArgs e) - { - var ctrl = sender as Control; - if (ctrl == null) - return; - - ctrl.Disposed -= HandleControlDisposed; - ctrl.MouseDown -= HandleControlMouseDown; - - ComponentCache.Remove(ctrl); - } - - /// ------------------------------------------------------------------------------------ - /// - /// When a TabPage gets disposed, remove reference to it from the object cache. - /// - /// ------------------------------------------------------------------------------------ - internal void HandleTabPageDisposed(object sender, EventArgs e) - { - if (!(sender is TabPage tabPage)) - return; - - tabPage.Disposed -= HandleTabPageDisposed; - ComponentCache.Remove(tabPage); - } - - /// ------------------------------------------------------------------------------------ - /// - /// When DataGridView controls get disposed, do a little clean-up. - /// - /// ------------------------------------------------------------------------------------ - internal void HandleDataGridViewDisposed(object sender, EventArgs e) - { - if (!(sender is DataGridView grid)) - return; - - grid.Disposed -= HandleControlDisposed; - grid.CellMouseDown -= HandleDataGridViewCellMouseDown; - - ComponentCache.Remove(grid); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Handles ListView column header clicks. Unfortunately, even if the localization - /// dialog box is shown, this click on the header will not get eaten (like it does - /// for other controls). Therefore, if clicking on the column header sorts the column, - /// that sorting will take place after the dialog box is closed. - /// - /// ------------------------------------------------------------------------------------ - internal void HandleListViewColumnHeaderClicked(object sender, ColumnClickEventArgs e) - { - if (!DoHandleMouseDown) - return; - - if (sender is ListView lv && ComponentCache.ContainsKey(lv.Columns[e.Column])) - LocalizeItemDlg.ShowDialog(this, lv.Columns[e.Column], false, - lv.FindForm()); - } - - /// ------------------------------------------------------------------------------------ - /// - /// When ListView controls get disposed, do a little clean-up. - /// - /// ------------------------------------------------------------------------------------ - internal void HandleListViewDisposed(object sender, EventArgs e) - { - if (!(sender is ListView lv)) - return; - - lv.Disposed -= HandleListViewDisposed; - lv.ColumnClick -= HandleListViewColumnHeaderClicked; - } - - /// ------------------------------------------------------------------------------------ - /// - /// When ListView ColumnHeader controls get disposed, remove the reference to it from the - /// object cache. - /// - /// ------------------------------------------------------------------------------------ - internal void HandleListViewColumnDisposed(object sender, EventArgs e) - { - if (!(sender is ColumnHeader column)) - return; - - column.Disposed -= HandleListViewColumnDisposed; - ComponentCache.Remove(column); - } - - /// ------------------------------------------------------------------------------------ - internal void HandleDataGridViewCellMouseDown(object sender, DataGridViewCellMouseEventArgs e) - { - if (!DoHandleMouseDown) - return; - - if (sender is DataGridView grid && e.RowIndex < 0 && - ComponentCache.ContainsKey(grid.Columns[e.ColumnIndex])) - { - LocalizeItemDlg.ShowDialog(this, grid.Columns[e.ColumnIndex], false, - grid.FindForm()); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// When DataGridViewColumn controls get disposed, remove the reference to it from the - /// object cache. - /// - /// ------------------------------------------------------------------------------------ - internal void HandleColumnDisposed(object sender, EventArgs e) - { - if (!(sender is DataGridViewColumn column)) - return; - - column.Disposed -= HandleColumnDisposed; - ComponentCache.Remove(column); - } #endregion /// ------------------------------------------------------------------------------------ diff --git a/src/L10NSharp/XLiffUtils/XliffLocalizedStringCache.cs b/src/L10NSharp/XLiffUtils/XliffLocalizedStringCache.cs index 761cc4d..93f6766 100644 --- a/src/L10NSharp/XLiffUtils/XliffLocalizedStringCache.cs +++ b/src/L10NSharp/XLiffUtils/XliffLocalizedStringCache.cs @@ -7,8 +7,6 @@ using System.Security; using System.Text; using System.Text.RegularExpressions; -using System.Windows.Forms; -using L10NSharp.UI; namespace L10NSharp.XLiffUtils { @@ -17,7 +15,6 @@ internal class XliffLocalizedStringCache : LocalizedStringCache, ILocalizedStrin { private readonly XliffTransUnitUpdater _tuUpdater; - public List> LeafNodeList { get; private set; } internal XliffLocalizationManager OwningManager { get; private set; } private XLiffDocument DefaultXliffDocument { get; set; } // matches LanguageManager.kDefaultLanguage @@ -51,9 +48,9 @@ internal XliffLocalizedStringCache(ILocalizationManager owningManager, bool load } catch (Exception e) { - MessageBox.Show("Error occurred reading localization file:" + Environment.NewLine + e.Message, - Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); - LocalizationManager.SetUILanguage(LocalizationManager.kDefaultLang, false); + Console.WriteLine("Error occurred reading localization file:"); + Console.WriteLine(e.Message); + LocalizationManager.SetUILanguage(LocalizationManager.kDefaultLang); } } else @@ -72,7 +69,6 @@ internal XliffLocalizedStringCache(ILocalizationManager owningManager, bool load if (replacement != null) s_literalNewline = replacement; - LeafNodeList = new List>(); IsDirty = false; } @@ -493,17 +489,6 @@ public string GetToolTipText(string langId, string id, bool formatForDisplay) return GetValueForExactLangAndId(langId, id + kToolTipSuffix, formatForDisplay); } - /// ------------------------------------------------------------------------------------ - /// - /// Gets the localized tooltip text for the specified id and suffix. - /// - /// ------------------------------------------------------------------------------------ - public Keys GetShortcutKeys(string langId, string id) - { - string keys = GetValueForLangAndIdWithFallback(langId, id + kShortcutSuffix); - return ShortcutKeysEditor.KeysFromString(keys); - } - /// ------------------------------------------------------------------------------------ /// /// Gets the localized tooltip text for the specified id and suffix. @@ -521,7 +506,7 @@ public string GetShortcutKeysText(string langId, string id) /// fails, then the default (i.e. "en") is used. /// /// ------------------------------------------------------------------------------------ - private string GetValueForLangAndIdWithFallback(string langId, string id) + protected string GetValueForLangAndIdWithFallback(string langId, string id) { var value = GetValueForExactLangAndId(langId, id, true); if (value != null) @@ -686,54 +671,13 @@ internal string GetBaseId(string tuid) return tuid; } - /// ------------------------------------------------------------------------------------ - /// - /// Loads the specified tree node collection with all the string groups and their - /// localizable string ids. - /// - /// ------------------------------------------------------------------------------------ - public void LoadGroupNodes(TreeNodeCollection topCollection) - { - LeafNodeList.Clear(); - - foreach (var tu in GetTranslationUnitsForTree()) - { - string id = GetBaseId(tu.Id); - var groupChain = ParseGroupAndId(GetGroup(tu.Id), id); - var nodeKey = string.Empty; - var nodeCollection = topCollection; - LocTreeNode newNode; - - for (int i = groupChain.Count - 1; i > 0; i--) - { - nodeKey = (nodeKey + "." + groupChain[i]).TrimStart('.'); - - var nodes = nodeCollection.Find(nodeKey, true); - if (nodes.Length > 0) - nodeCollection = nodes[0].Nodes; - else - { - newNode = new LocTreeNode(OwningManager, groupChain[i], null, - nodeKey); - nodeCollection.Add(newNode); - nodeCollection = newNode.Nodes; - } - } - - nodeKey = nodeKey + ("." + groupChain[0]).TrimStart('.'); - newNode = new LocTreeNode(OwningManager, groupChain[0], id, nodeKey); - nodeCollection.Add(newNode); - LeafNodeList.Add(newNode); - } - } - /// ------------------------------------------------------------------------------------ /// /// Gets a list of only those translation units that should show up in the localizing /// dialog's tree control. /// /// ------------------------------------------------------------------------------------ - private IEnumerable GetTranslationUnitsForTree() + protected IEnumerable GetTranslationUnitsForTree() { foreach (var tu in DefaultXliffDocument.File.Body.TransUnitsUnordered) { @@ -769,7 +713,7 @@ private IEnumerable GetTranslationUnitsForTree() /// Parses the group and id and returns all the pieces between periods. /// /// ------------------------------------------------------------------------------------ - private static List ParseGroupAndId(string group, string id) + protected static List ParseGroupAndId(string group, string id) { var allPieces = new List(); string[] pieces; diff --git a/src/L10NSharp/XLiffUtils/XliffTransUnitUpdater.cs b/src/L10NSharp/XLiffUtils/XliffTransUnitUpdater.cs index f58f395..a3dcae0 100644 --- a/src/L10NSharp/XLiffUtils/XliffTransUnitUpdater.cs +++ b/src/L10NSharp/XLiffUtils/XliffTransUnitUpdater.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using L10NSharp.XLiffUtils; namespace L10NSharp.XLiffUtils { diff --git a/src/SampleApp/Form1.Designer.cs b/src/SampleApp/Form1.Designer.cs index ef8b6f6..5e2bfa8 100644 --- a/src/SampleApp/Form1.Designer.cs +++ b/src/SampleApp/Form1.Designer.cs @@ -32,65 +32,53 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - this.localizationExtender1 = new L10NSharp.UI.L10NSharpExtender(this.components); + this.localizationExtender1 = new L10NSharp.Windows.Forms.L10NSharpExtender(this.components); this._getDynamicStringButton = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.uiLanguageComboBox1 = new L10NSharp.UI.UILanguageComboBox(); - this.linkLabel1 = new System.Windows.Forms.LinkLabel(); + this.uiLanguageComboBox1 = new L10NSharp.Windows.Forms.UIComponents.UILanguageComboBox(); this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.dataGridView1 = new System.Windows.Forms.DataGridView(); - this.listView1 = new System.Windows.Forms.ListView(); this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.listView1 = new System.Windows.Forms.ListView(); ((System.ComponentModel.ISupportInitialize)(this.localizationExtender1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); - // + // // localizationExtender1 - // + // this.localizationExtender1.LocalizationManagerId = "SampleApp"; this.localizationExtender1.PrefixForNewItems = "TheSampleForm"; - // + // // _getDynamicStringButton - // + // this.localizationExtender1.SetLocalizableToolTip(this._getDynamicStringButton, null); this.localizationExtender1.SetLocalizationComment(this._getDynamicStringButton, null); this.localizationExtender1.SetLocalizingId(this._getDynamicStringButton, "TheSampleForm.button1"); - this._getDynamicStringButton.Location = new System.Drawing.Point(38, 161); + this._getDynamicStringButton.Location = new System.Drawing.Point(51, 198); + this._getDynamicStringButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this._getDynamicStringButton.Name = "_getDynamicStringButton"; - this._getDynamicStringButton.Size = new System.Drawing.Size(126, 23); + this._getDynamicStringButton.Size = new System.Drawing.Size(168, 28); this._getDynamicStringButton.TabIndex = 0; this._getDynamicStringButton.Text = "Get Name Dynamically"; this._getDynamicStringButton.UseVisualStyleBackColor = true; this._getDynamicStringButton.Click += new System.EventHandler(this.button1_Click); - // + // // label1 - // + // this.label1.AutoSize = true; this.localizationExtender1.SetLocalizableToolTip(this.label1, null); this.localizationExtender1.SetLocalizationComment(this.label1, null); this.localizationExtender1.SetLocalizingId(this.label1, "TheSampleForm.ASubHeading.Label"); - this.label1.Location = new System.Drawing.Point(40, 212); + this.label1.Location = new System.Drawing.Point(53, 261); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(73, 13); + this.label1.Size = new System.Drawing.Size(89, 16); this.label1.TabIndex = 1; this.label1.Text = "A Static Label"; - // - // label2 - // - this.label2.AutoSize = true; - this.localizationExtender1.SetLocalizableToolTip(this.label2, null); - this.localizationExtender1.SetLocalizationComment(this.label2, null); - this.localizationExtender1.SetLocalizingId(this.label2, "TheSampleForm.label2"); - this.label2.Location = new System.Drawing.Point(73, 111); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(202, 13); - this.label2.TabIndex = 2; - this.label2.Text = "or Alt+Shift Click on items to localize them"; - // + // // uiLanguageComboBox1 - // + // this.uiLanguageComboBox1.DisplayMember = "NativeName"; this.uiLanguageComboBox1.DropDownHeight = 200; this.uiLanguageComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; @@ -99,90 +87,81 @@ private void InitializeComponent() this.uiLanguageComboBox1.IntegralHeight = false; this.localizationExtender1.SetLocalizableToolTip(this.uiLanguageComboBox1, null); this.localizationExtender1.SetLocalizationComment(this.uiLanguageComboBox1, null); - this.localizationExtender1.SetLocalizationPriority(this.uiLanguageComboBox1, LocalizationPriority.NotLocalizable); + this.localizationExtender1.SetLocalizationPriority(this.uiLanguageComboBox1, L10NSharp.LocalizationPriority.NotLocalizable); this.localizationExtender1.SetLocalizingId(this.uiLanguageComboBox1, "uiLanguageComboBox1.uiLanguageComboBox1"); - this.uiLanguageComboBox1.Location = new System.Drawing.Point(40, 41); + this.uiLanguageComboBox1.Location = new System.Drawing.Point(53, 50); + this.uiLanguageComboBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.uiLanguageComboBox1.Name = "uiLanguageComboBox1"; this.uiLanguageComboBox1.ShowOnlyLanguagesHavingLocalizations = true; - this.uiLanguageComboBox1.Size = new System.Drawing.Size(121, 23); + this.uiLanguageComboBox1.Size = new System.Drawing.Size(160, 28); this.uiLanguageComboBox1.TabIndex = 3; this.uiLanguageComboBox1.SelectedIndexChanged += new System.EventHandler(this.uiLanguageComboBox1_SelectedIndexChanged); - // - // linkLabel1 - // - this.linkLabel1.AutoSize = true; - this.localizationExtender1.SetLocalizableToolTip(this.linkLabel1, null); - this.localizationExtender1.SetLocalizationComment(this.linkLabel1, null); - this.localizationExtender1.SetLocalizingId(this.linkLabel1, "TheSampleForm.linkLabel1"); - this.linkLabel1.Location = new System.Drawing.Point(40, 88); - this.linkLabel1.Name = "linkLabel1"; - this.linkLabel1.Size = new System.Drawing.Size(124, 13); - this.linkLabel1.TabIndex = 4; - this.linkLabel1.TabStop = true; - this.linkLabel1.Text = "Open Translation Dialog,"; - this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); - // + // // columnHeader1 - // + // this.localizationExtender1.SetLocalizableToolTip(this.columnHeader1, null); this.localizationExtender1.SetLocalizationComment(this.columnHeader1, null); this.localizationExtender1.SetLocalizingId(this.columnHeader1, "TheSampleForm.columnHeader1"); this.columnHeader1.Text = "One"; - // + // // columnHeader2 - // + // this.localizationExtender1.SetLocalizableToolTip(this.columnHeader2, null); this.localizationExtender1.SetLocalizationComment(this.columnHeader2, null); this.localizationExtender1.SetLocalizingId(this.columnHeader2, "TheSampleForm.columnHeader2"); this.columnHeader2.Text = "Two"; - // + // // dataGridView1 - // + // this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Column1}); this.localizationExtender1.SetLocalizableToolTip(this.dataGridView1, null); this.localizationExtender1.SetLocalizationComment(this.dataGridView1, null); this.localizationExtender1.SetLocalizingId(this.dataGridView1, "TheSampleForm.dataGridView1"); - this.dataGridView1.Location = new System.Drawing.Point(40, 377); + this.dataGridView1.Location = new System.Drawing.Point(53, 464); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.Size = new System.Drawing.Size(446, 73); + this.dataGridView1.RowHeadersWidth = 51; + this.dataGridView1.Size = new System.Drawing.Size(595, 90); this.dataGridView1.TabIndex = 6; - // + // + // Column1 + // + this.Column1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Column1.HeaderText = "_L10N_:TheSampleForm.SampleDataGridView.ColumnHeadings.FirstColumn!First"; + this.Column1.MinimumWidth = 6; + this.Column1.Name = "Column1"; + this.Column1.ToolTipText = "My tooltip"; + // // listView1 - // + // this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.columnHeader1, this.columnHeader2}); - this.listView1.Location = new System.Drawing.Point(40, 256); + this.listView1.HideSelection = false; + this.listView1.Location = new System.Drawing.Point(53, 315); + this.listView1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.listView1.Name = "listView1"; - this.listView1.Size = new System.Drawing.Size(338, 97); + this.listView1.Size = new System.Drawing.Size(449, 118); this.listView1.TabIndex = 5; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.View = System.Windows.Forms.View.Details; - // - // Column1 - // - this.Column1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.Column1.HeaderText = "_L10N_:TheSampleForm.SampleDataGridView.ColumnHeadings.FirstColumn!First"; - this.Column1.Name = "Column1"; - this.Column1.ToolTipText = "My tooltip"; - // + // // Form1 - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(559, 462); + this.ClientSize = new System.Drawing.Size(745, 569); this.Controls.Add(this.dataGridView1); this.Controls.Add(this.listView1); - this.Controls.Add(this.linkLabel1); this.Controls.Add(this.uiLanguageComboBox1); - this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this._getDynamicStringButton); this.localizationExtender1.SetLocalizableToolTip(this, null); this.localizationExtender1.SetLocalizationComment(this, null); this.localizationExtender1.SetLocalizingId(this, "Form1.WindowTitle"); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "Form1"; @@ -197,12 +176,10 @@ private void InitializeComponent() #endregion - private L10NSharp.UI.L10NSharpExtender localizationExtender1; + private L10NSharp.Windows.Forms.L10NSharpExtender localizationExtender1; private System.Windows.Forms.Button _getDynamicStringButton; private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; - private L10NSharp.UI.UILanguageComboBox uiLanguageComboBox1; - private System.Windows.Forms.LinkLabel linkLabel1; + private L10NSharp.Windows.Forms.UIComponents.UILanguageComboBox uiLanguageComboBox1; private System.Windows.Forms.ListView listView1; private System.Windows.Forms.ColumnHeader columnHeader1; private System.Windows.Forms.ColumnHeader columnHeader2; diff --git a/src/SampleApp/Form1.cs b/src/SampleApp/Form1.cs index c68aaca..312c71d 100644 --- a/src/SampleApp/Form1.cs +++ b/src/SampleApp/Form1.cs @@ -2,6 +2,7 @@ using System.Drawing; using System.Windows.Forms; using L10NSharp; +using L10NSharp.Windows.Forms; using SampleApp.Properties; namespace SampleApp @@ -24,14 +25,7 @@ private void UpdateDynamicLabel() private void uiLanguageComboBox1_SelectedIndexChanged(object sender, EventArgs e) { Settings.Default.UserInterfaceLanguage = uiLanguageComboBox1.SelectedLanguage; - LocalizationManager.SetUILanguage(uiLanguageComboBox1.SelectedLanguage, true); - UpdateDynamicLabel(); - } - - private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) - { - LocalizationManager.ShowLocalizationDialogBox(this); - uiLanguageComboBox1.RefreshList(); + LocalizationManagerWinforms.SetUILanguage(uiLanguageComboBox1.SelectedLanguage, true); UpdateDynamicLabel(); } diff --git a/src/SampleApp/Program.cs b/src/SampleApp/Program.cs index 05a9c0d..bc64640 100644 --- a/src/SampleApp/Program.cs +++ b/src/SampleApp/Program.cs @@ -6,6 +6,7 @@ using System.Reflection; using System.Windows.Forms; using L10NSharp; +using L10NSharp.Windows.Forms; using SampleApp.Properties; using static System.String; @@ -24,7 +25,7 @@ static void Main(string[] args) Application.SetCompatibleTextRenderingDefault(false); if (args.Any(a => a == "-i:permissive")) - LocalizationManager.StrictInitializationMode = false; + LocalizationManagerWinforms.StrictInitializationMode = false; try { @@ -32,7 +33,7 @@ static void Main(string[] args) // InvalidOperationException, which we will catch and (for the purposes // of this sample app) ignore. MessageBox.Show(Format( - LocalizationManager.GetString("accessed.before.setting.up.lm", + LocalizationManagerWinforms.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 " + @@ -42,7 +43,7 @@ static void Main(string[] args) } catch (InvalidOperationException ex) { - if (LocalizationManager.StrictInitializationMode) + if (LocalizationManagerWinforms.StrictInitializationMode) Trace.WriteLine($"Got expected {ex.GetType().FullName} exception: {ex.Message}"); else throw; @@ -50,7 +51,7 @@ static void Main(string[] args) SetUpLocalization(args.Any(a => a == "-m"), args.Any(a => a == "-tmx")); - LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false); + LocalizationManagerWinforms.SetUILanguage(Settings.Default.UserInterfaceLanguage, false); Application.Run(new Form1()); Settings.Default.Save(); @@ -82,7 +83,7 @@ private static void SetUpLocalization(bool useAdditionalMethodInfo, bool useTmx) "The generated localization file should contain this string and the window title.", "This is a comment"), MyOwnGetString("SampleApp.InformationalMessageBox.Title", "Cool Title")); - _localizationManager = LocalizationManager.Create(theLanguageYouRememberedFromLastTime, + _localizationManager = LocalizationManagerWinforms.Create(theLanguageYouRememberedFromLastTime, "SampleApp.exe", "SampleApp", Application.ProductVersion, directoryOfInstalledLocFiles, "MyCompany/L10NSharpSample", @@ -95,7 +96,7 @@ private static void SetUpLocalization(bool useAdditionalMethodInfo, bool useTmx) } else { - _localizationManager = LocalizationManager.Create(theLanguageYouRememberedFromLastTime, + _localizationManager = LocalizationManagerWinforms.Create(theLanguageYouRememberedFromLastTime, "SampleApp.exe", "SampleApp", Application.ProductVersion, directoryOfInstalledLocFiles, "MyCompany/L10NSharpSample", @@ -104,7 +105,7 @@ private static void SetUpLocalization(bool useAdditionalMethodInfo, bool useTmx) new[] { "SampleApp" }); } - Settings.Default.UserInterfaceLanguage = LocalizationManager.UILanguageId; + Settings.Default.UserInterfaceLanguage = LocalizationManagerWinforms.UILanguageId; } catch (Exception error) { diff --git a/src/SampleApp/SampleApp.csproj b/src/SampleApp/SampleApp.csproj index 23b2ab8..be693f9 100644 --- a/src/SampleApp/SampleApp.csproj +++ b/src/SampleApp/SampleApp.csproj @@ -11,6 +11,7 @@ +