From a5ccc0c30ba24c5afafd6a0de92c0d441119366a Mon Sep 17 00:00:00 2001 From: Robin Date: Mon, 5 Nov 2018 13:53:16 +0100 Subject: [PATCH] Change to fix most of the translation and configuration loading. --- .../EditorAddonModule.cs | 4 ++ .../Greenshot.Addon.LegacyEditor.csproj | 43 ++++-------- src/Greenshot.Addons/AddonsModule.cs | 5 ++ .../Controls/GreenshotForm.cs | 58 +++++++++++++---- src/Greenshot.Addons/Greenshot.Addons.csproj | 10 +-- src/Greenshot.Gfx/Greenshot.Gfx.csproj | 2 +- src/Greenshot.Tests/Greenshot.Tests.csproj | 2 +- src/Greenshot/Configuration/LanguageKeys.cs | 65 ------------------- src/Greenshot/Forms/CaptureForm.cs | 2 - src/Greenshot/Greenshot.csproj | 14 ++-- src/Greenshot/GreenshotAutofacModule.cs | 45 +++++++++++++ src/Greenshot/Helpers/CaptureHelper.cs | 1 - src/Greenshot/Helpers/PrintHelper.cs | 1 - 13 files changed, 124 insertions(+), 128 deletions(-) delete mode 100644 src/Greenshot/Configuration/LanguageKeys.cs diff --git a/src/Greenshot.Addon.LegacyEditor/EditorAddonModule.cs b/src/Greenshot.Addon.LegacyEditor/EditorAddonModule.cs index 31f46d7fd..ad915c3b6 100644 --- a/src/Greenshot.Addon.LegacyEditor/EditorAddonModule.cs +++ b/src/Greenshot.Addon.LegacyEditor/EditorAddonModule.cs @@ -24,6 +24,8 @@ using Autofac; using Dapplo.Addons; using Dapplo.CaliburnMicro.Configuration; +using Dapplo.Config.Ini; +using Dapplo.Config.Language; using Greenshot.Addon.LegacyEditor.Configuration.Impl; using Greenshot.Addon.LegacyEditor.Controls; using Greenshot.Addon.LegacyEditor.Drawing; @@ -42,11 +44,13 @@ namespace Greenshot.Addon.LegacyEditor builder .Register(context => new EditorConfigurationImpl()) .As() + .As() .SingleInstance(); builder .Register(context => new EditorLanguageImpl()) .As() + .As() .SingleInstance(); builder diff --git a/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj b/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj index bfc4b3527..425536fcd 100644 --- a/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj +++ b/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj @@ -38,41 +38,20 @@ - - {5b924697-4dcd-4f98-85f1-105cb84b7341} - Greenshot.Addons - - - {bf35190d-b2a7-4cfa-b397-51cb384cf0d7} - Greenshot.Core - - - {f041c685-eb96-4ed1-9ace-0f5bd836610f} - Greenshot.Gfx - + + + - - - 2.0.4 - - - 1.1.10-ge2d1078449 - - - 1.1.10-ge2d1078449 - - - 0.9.6 - - - 0.7.19 - - - 0.7.19 - - + + + + + + + + all runtime; build; native; contentfiles; analyzers diff --git a/src/Greenshot.Addons/AddonsModule.cs b/src/Greenshot.Addons/AddonsModule.cs index 5faa5419c..d28d6388b 100644 --- a/src/Greenshot.Addons/AddonsModule.cs +++ b/src/Greenshot.Addons/AddonsModule.cs @@ -24,6 +24,8 @@ using Autofac; using Dapplo.Addons; using Dapplo.CaliburnMicro.Configuration; +using Dapplo.Config.Ini; +using Dapplo.Config.Language; using Greenshot.Addons.Components; using Greenshot.Addons.Config.Impl; using Greenshot.Addons.Controls; @@ -41,16 +43,19 @@ namespace Greenshot.Addons .Register(context => new CoreConfigurationImpl()) .As() .As() + .As() .SingleInstance(); builder .Register(context => new GreenshotLanguageImpl()) .As() + .As() .SingleInstance(); builder .Register(context => new HttpConfigurationImpl()) .As() + .As() .SingleInstance(); builder diff --git a/src/Greenshot.Addons/Controls/GreenshotForm.cs b/src/Greenshot.Addons/Controls/GreenshotForm.cs index eebef46c6..891b22768 100644 --- a/src/Greenshot.Addons/Controls/GreenshotForm.cs +++ b/src/Greenshot.Addons/Controls/GreenshotForm.cs @@ -33,6 +33,7 @@ using Dapplo.Config.Ini; using Dapplo.Config.Interfaces; using Dapplo.Config.Language; using Dapplo.Log; +using Dapplo.Utils; using Dapplo.Windows.Desktop; using Dapplo.Windows.Dpi; using Dapplo.Windows.Dpi.Forms; @@ -143,17 +144,33 @@ namespace Greenshot.Addons.Controls return; } - if (!string.IsNullOrEmpty(languageKey) && _language.Keys().Contains(languageKey)) + string translation; + if (!string.IsNullOrEmpty(languageKey)) { - applyTo.Text = _language[languageKey]; + if (_language.TryGetTranslation(languageKey, out translation)) + { + applyTo.Text = translation; + return; + } + + var dotIndex = languageKey.IndexOf('.'); + if (dotIndex >= 0) + { + var alternativeKey = languageKey.Substring(dotIndex + 1); + if (_language.TryGetTranslation(alternativeKey, out translation)) + { + applyTo.Text = translation; + return; + } + } + } + + if (_language.TryGetTranslation(applyTo.Name, out translation)) + { + applyTo.Text = translation; return; } - if (_language.Keys().Contains(applyTo.Name)) - { - applyTo.Text = _language[applyTo.Name]; - return; - } Log.Warn().WriteLine("Unknown language key '{0}' configured for control '{1}'", languageKey, applyTo.Name); } @@ -236,7 +253,7 @@ namespace Greenshot.Addons.Controls try { // Set title of the form - if (!string.IsNullOrEmpty(LanguageKey) && _language.Keys().Contains(LanguageKey)) + if (!string.IsNullOrEmpty(LanguageKey) && _language.Keys().Contains(LanguageKey, AbcComparer.Instance)) { Text = _language[LanguageKey]; } @@ -282,15 +299,30 @@ namespace Greenshot.Addons.Controls return; } - if (!string.IsNullOrEmpty(languageKey) && _language.Keys().Contains(languageKey)) + string translation; + if (!string.IsNullOrEmpty(languageKey)) { - applyTo.Text = _language[languageKey]; - return; + if (_language.TryGetTranslation(languageKey, out translation)) + { + applyTo.Text = translation; + return; + } + + var dotIndex = languageKey.IndexOf('.'); + if (dotIndex >= 0) + { + var alternativeKey = languageKey.Substring(dotIndex + 1); + if (_language.TryGetTranslation(alternativeKey, out translation)) + { + applyTo.Text = translation; + return; + } + } } - if (_language.Keys().Contains(applyTo.Name)) + if (_language.TryGetTranslation(applyTo.Name, out translation)) { - applyTo.Text = _language[applyTo.Name]; + applyTo.Text = translation; return; } Log.Warn().WriteLine("Wrong language key '{0}' configured for control '{1}'", languageKey, applyTo.Name); diff --git a/src/Greenshot.Addons/Greenshot.Addons.csproj b/src/Greenshot.Addons/Greenshot.Addons.csproj index 124c4683c..6e73530af 100644 --- a/src/Greenshot.Addons/Greenshot.Addons.csproj +++ b/src/Greenshot.Addons/Greenshot.Addons.csproj @@ -33,18 +33,18 @@ - + 2.0.4 - 1.1.10-ge2d1078449 + 1.1.11-gd26115c7d3 - 1.1.10-ge2d1078449 + 1.1.11-gd26115c7d3 - 1.1.10-ge2d1078449 + 1.1.11-gd26115c7d3 0.9.6 @@ -61,7 +61,7 @@ 0.7.19 - + all runtime; build; native; contentfiles; analyzers diff --git a/src/Greenshot.Gfx/Greenshot.Gfx.csproj b/src/Greenshot.Gfx/Greenshot.Gfx.csproj index b789de94c..dbb209fa0 100644 --- a/src/Greenshot.Gfx/Greenshot.Gfx.csproj +++ b/src/Greenshot.Gfx/Greenshot.Gfx.csproj @@ -36,7 +36,7 @@ 2.0.4 - 1.1.10-ge2d1078449 + 1.1.11-gd26115c7d3 2.3.0 diff --git a/src/Greenshot.Tests/Greenshot.Tests.csproj b/src/Greenshot.Tests/Greenshot.Tests.csproj index 6034dec95..55b63b781 100644 --- a/src/Greenshot.Tests/Greenshot.Tests.csproj +++ b/src/Greenshot.Tests/Greenshot.Tests.csproj @@ -102,7 +102,7 @@ 2.0.4 - 1.1.10-ge2d1078449 + 1.1.11-gd26115c7d3 0.9.6 diff --git a/src/Greenshot/Configuration/LanguageKeys.cs b/src/Greenshot/Configuration/LanguageKeys.cs deleted file mode 100644 index f39f51d8e..000000000 --- a/src/Greenshot/Configuration/LanguageKeys.cs +++ /dev/null @@ -1,65 +0,0 @@ -#region Greenshot GNU General Public License - -// Greenshot - a free and open source screenshot tool -// Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom -// -// For more information see: http://getgreenshot.org/ -// The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 1 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#endregion - -#region Usings - -using System.Diagnostics.CodeAnalysis; - -#endregion - -namespace Greenshot.Configuration -{ - [SuppressMessage("ReSharper", "InconsistentNaming")] - public enum LangKey - { - contextmenu_capturefullscreen_all, - contextmenu_capturefullscreen_left, - contextmenu_capturefullscreen_top, - contextmenu_capturefullscreen_right, - contextmenu_capturefullscreen_bottom, - contextmenu_captureie, - editor_clipboardfailed, - editor_email, - error, - error_openfile, - error_openlink, - print_error, - settings_destination, - settings_destination_fileas, - settings_destination_printer, - settings_filenamepattern, - settings_message_filenamepattern, - settings_printoptions, - settings_tooltip_filenamepattern, - settings_tooltip_language, - settings_tooltip_primaryimageformat, - settings_tooltip_storagelocation, - settings_visualization, - settings_window_capture_mode, - tooltip_firststart, - warning, - warning_hotkeys, - wait_ie_capture, - update_found - } -} \ No newline at end of file diff --git a/src/Greenshot/Forms/CaptureForm.cs b/src/Greenshot/Forms/CaptureForm.cs index 8a0a2929a..c3eb447d8 100644 --- a/src/Greenshot/Forms/CaptureForm.cs +++ b/src/Greenshot/Forms/CaptureForm.cs @@ -60,7 +60,6 @@ namespace Greenshot.Forms private static readonly Brush ScrollingOverlayBrush = new SolidBrush(Color.FromArgb(50, Color.GreenYellow)); private static readonly Pen OverlayPen = new Pen(Color.FromArgb(50, Color.Black)); - private readonly ICoreConfiguration _coreConfiguration; private static readonly Brush BackgroundBrush; private readonly ICapture _capture; private readonly bool _isZoomerTransparent; @@ -97,7 +96,6 @@ namespace Greenshot.Forms /// IList of IInteropWindow public CaptureForm(ICoreConfiguration coreConfiguration, ICapture capture, IList windows) : base(coreConfiguration, null) { - _coreConfiguration = coreConfiguration; _isZoomerTransparent = _coreConfiguration.ZoomerOpacity < 1; ManualLanguageApply = true; ManualStoreFields = true; diff --git a/src/Greenshot/Greenshot.csproj b/src/Greenshot/Greenshot.csproj index daededc72..d3dc9ad98 100644 --- a/src/Greenshot/Greenshot.csproj +++ b/src/Greenshot/Greenshot.csproj @@ -57,14 +57,14 @@ - + - - - - - + + + + + @@ -72,7 +72,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/src/Greenshot/GreenshotAutofacModule.cs b/src/Greenshot/GreenshotAutofacModule.cs index ff960d917..11d0b511e 100644 --- a/src/Greenshot/GreenshotAutofacModule.cs +++ b/src/Greenshot/GreenshotAutofacModule.cs @@ -21,11 +21,16 @@ #endregion +using System.Collections.Generic; +using System.IO; +using System.Linq; using Autofac; using Autofac.Features.AttributeFilters; using Dapplo.Addons; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Security; +using Dapplo.Config.Ini; +using Dapplo.Config.Language; using Greenshot.Addons.Components; using Greenshot.Components; using Greenshot.Configuration; @@ -44,14 +49,31 @@ namespace Greenshot { protected override void Load(ContainerBuilder builder) { + // Specify the directories for the translations manually, this is a workaround + builder.Register(context => LanguageConfigBuilder.Create() + .WithSpecificDirectories(GenerateScanDirectories( +#if NET471 + "net471", +#else + "netcoreapp3.0", +#endif + "Greenshot.Addon.LegacyEditor", + "Greenshot").ToArray() + ) + .BuildLanguageConfig()) + .As() + .SingleInstance(); + builder .Register(context => new MetroConfigurationImpl()) .As() + .As() .SingleInstance(); builder .Register(context => new ConfigTranslationsImpl()) .As() + .As() .SingleInstance(); builder @@ -129,5 +151,28 @@ namespace Greenshot base.Load(builder); } + + + /// + /// Helper method to create a list of paths where the files can be located + /// + /// string with the platform + /// + /// IEnumerable with paths + private IEnumerable GenerateScanDirectories(string platform, params string[] addons) + { + var location = GetType().Assembly.Location; + foreach (var addon in addons) + { + yield return Path.Combine(location, @"..\..\..\..\..\", addon, "bin", +#if DEBUG + "Debug", +#else + "Release", +#endif + platform + ); + } + } } } diff --git a/src/Greenshot/Helpers/CaptureHelper.cs b/src/Greenshot/Helpers/CaptureHelper.cs index 6f7dfa673..690d423cf 100644 --- a/src/Greenshot/Helpers/CaptureHelper.cs +++ b/src/Greenshot/Helpers/CaptureHelper.cs @@ -49,7 +49,6 @@ using Greenshot.Addons.Interfaces; using Greenshot.Components; using Greenshot.Core.Enums; using Greenshot.Gfx; -using LangKey = Greenshot.Configuration.LangKey; using Greenshot.Addons.Config.Impl; #endregion diff --git a/src/Greenshot/Helpers/PrintHelper.cs b/src/Greenshot/Helpers/PrintHelper.cs index ce7c6209b..fc14725f6 100644 --- a/src/Greenshot/Helpers/PrintHelper.cs +++ b/src/Greenshot/Helpers/PrintHelper.cs @@ -39,7 +39,6 @@ using Greenshot.Addons.Interfaces.Plugin; using Greenshot.Core.Enums; using Greenshot.Gfx.Effects; using Greenshot.Gfx.Legacy; -using LangKey = Greenshot.Configuration.LangKey; #endregion