Change to fix most of the translation and configuration loading.

This commit is contained in:
Robin 2018-11-05 13:53:16 +01:00
commit a5ccc0c30b
13 changed files with 124 additions and 128 deletions

View file

@ -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<IEditorConfiguration>()
.As<IIniSection>()
.SingleInstance();
builder
.Register(context => new EditorLanguageImpl())
.As<IEditorLanguage>()
.As<ILanguage>()
.SingleInstance();
builder

View file

@ -38,41 +38,20 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Greenshot.Addons\Greenshot.Addons.csproj">
<Project>{5b924697-4dcd-4f98-85f1-105cb84b7341}</Project>
<Name>Greenshot.Addons</Name>
</ProjectReference>
<ProjectReference Include="..\Greenshot.Core\Greenshot.Core.csproj">
<Project>{bf35190d-b2a7-4cfa-b397-51cb384cf0d7}</Project>
<Name>Greenshot.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Greenshot.Gfx\Greenshot.Gfx.csproj">
<Project>{f041c685-eb96-4ed1-9ace-0f5bd836610f}</Project>
<Name>Greenshot.Gfx</Name>
</ProjectReference>
<ProjectReference Include="..\Greenshot.Addons\Greenshot.Addons.csproj" />
<ProjectReference Include="..\Greenshot.Core\Greenshot.Core.csproj" />
<ProjectReference Include="..\Greenshot.Gfx\Greenshot.Gfx.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoProperties.Fody" Version="1.17.0" />
<PackageReference Include="CommonServiceLocator">
<Version>2.0.4</Version>
</PackageReference>
<PackageReference Include="Dapplo.CaliburnMicro.Configuration">
<Version>1.1.10-ge2d1078449</Version>
</PackageReference>
<PackageReference Include="Dapplo.CaliburnMicro.Translations">
<Version>1.1.10-ge2d1078449</Version>
</PackageReference>
<PackageReference Include="Dapplo.HttpExtensions">
<Version>0.9.6</Version>
</PackageReference>
<PackageReference Include="Dapplo.Windows.Clipboard">
<Version>0.7.19</Version>
</PackageReference>
<PackageReference Include="Dapplo.Windows.Icons">
<Version>0.7.19</Version>
</PackageReference>
<PackageReference Include="Fody" Version="3.2.13">
<PackageReference Include="AutoProperties.Fody" Version="1.19.0" />
<PackageReference Include="CommonServiceLocator" Version="2.0.4" />
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="1.1.11-gd26115c7d3" />
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.1.11-gd26115c7d3" />
<PackageReference Include="Dapplo.HttpExtensions" Version="0.9.6" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.7.19" />
<PackageReference Include="Dapplo.Windows.Icons" Version="0.7.19" />
<PackageReference Include="Fody" Version="3.2.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -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<ICoreConfiguration>()
.As<IUiConfiguration>()
.As<IIniSection>()
.SingleInstance();
builder
.Register(context => new GreenshotLanguageImpl())
.As<IGreenshotLanguage>()
.As<ILanguage>()
.SingleInstance();
builder
.Register(context => new HttpConfigurationImpl())
.As<IHttpConfiguration>()
.As<IIniSection>()
.SingleInstance();
builder

View file

@ -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);

View file

@ -33,18 +33,18 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoProperties.Fody" Version="1.17.0" />
<PackageReference Include="AutoProperties.Fody" Version="1.19.0" />
<PackageReference Include="CommonServiceLocator">
<Version>2.0.4</Version>
</PackageReference>
<PackageReference Include="Dapplo.CaliburnMicro.Configuration">
<Version>1.1.10-ge2d1078449</Version>
<Version>1.1.11-gd26115c7d3</Version>
</PackageReference>
<PackageReference Include="Dapplo.CaliburnMicro.Toasts">
<Version>1.1.10-ge2d1078449</Version>
<Version>1.1.11-gd26115c7d3</Version>
</PackageReference>
<PackageReference Include="Dapplo.CaliburnMicro.Translations">
<Version>1.1.10-ge2d1078449</Version>
<Version>1.1.11-gd26115c7d3</Version>
</PackageReference>
<PackageReference Include="Dapplo.HttpExtensions">
<Version>0.9.6</Version>
@ -61,7 +61,7 @@
<PackageReference Include="Dapplo.Windows.Icons">
<Version>0.7.19</Version>
</PackageReference>
<PackageReference Include="Fody" Version="3.2.13">
<PackageReference Include="Fody" Version="3.2.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -36,7 +36,7 @@
<Version>2.0.4</Version>
</PackageReference>
<PackageReference Include="Dapplo.CaliburnMicro.Translations">
<Version>1.1.10-ge2d1078449</Version>
<Version>1.1.11-gd26115c7d3</Version>
</PackageReference>
<PackageReference Include="Svg">
<Version>2.3.0</Version>

View file

@ -102,7 +102,7 @@
<Version>2.0.4</Version>
</PackageReference>
<PackageReference Include="Dapplo.CaliburnMicro.Translations">
<Version>1.1.10-ge2d1078449</Version>
<Version>1.1.11-gd26115c7d3</Version>
</PackageReference>
<PackageReference Include="Dapplo.HttpExtensions.OAuth">
<Version>0.9.6</Version>

View file

@ -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 <http://www.gnu.org/licenses/>.
#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
}
}

View file

@ -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
/// <param name="windows">IList of IInteropWindow</param>
public CaptureForm(ICoreConfiguration coreConfiguration, ICapture capture, IList<IInteropWindow> windows) : base(coreConfiguration, null)
{
_coreConfiguration = coreConfiguration;
_isZoomerTransparent = _coreConfiguration.ZoomerOpacity < 1;
ManualLanguageApply = true;
ManualStoreFields = true;

View file

@ -57,14 +57,14 @@
<ItemGroup>
<PackageReference Include="Autofac.Extras.CommonServiceLocator" Version="5.0.0" />
<PackageReference Include="AutoProperties.Fody" Version="1.17.0" />
<PackageReference Include="AutoProperties.Fody" Version="1.19.0" />
<PackageReference Include="CommandLineParser" Version="2.3.0" />
<PackageReference Include="CommonServiceLocator" Version="2.0.4" />
<PackageReference Include="Dapplo.CaliburnMicro.Dapp" Version="1.1.10-ge2d1078449" />
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="1.1.10-ge2d1078449" />
<PackageReference Include="Dapplo.CaliburnMicro.Metro" Version="1.1.10-ge2d1078449" />
<PackageReference Include="Dapplo.CaliburnMicro.Toasts" Version="1.1.10-ge2d1078449" />
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.1.10-ge2d1078449" />
<PackageReference Include="Dapplo.CaliburnMicro.Dapp" Version="1.1.11-gd26115c7d3" />
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="1.1.11-gd26115c7d3" />
<PackageReference Include="Dapplo.CaliburnMicro.Metro" Version="1.1.11-gd26115c7d3" />
<PackageReference Include="Dapplo.CaliburnMicro.Toasts" Version="1.1.11-gd26115c7d3" />
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.1.11-gd26115c7d3" />
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="0.9.6" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.6" />
<PackageReference Include="Dapplo.Log.LogFile" Version="1.3.11" />
@ -72,7 +72,7 @@
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.7.19" />
<PackageReference Include="Dapplo.Windows.Icons" Version="0.7.19" />
<PackageReference Include="Dapplo.Windows.Multimedia" Version="0.7.19" />
<PackageReference Include="Fody" Version="3.2.13">
<PackageReference Include="Fody" Version="3.2.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -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<LanguageConfig>()
.SingleInstance();
builder
.Register(context => new MetroConfigurationImpl())
.As<IMetroConfiguration>()
.As<IIniSection>()
.SingleInstance();
builder
.Register(context => new ConfigTranslationsImpl())
.As<IConfigTranslations>()
.As<ILanguage>()
.SingleInstance();
builder
@ -129,5 +151,28 @@ namespace Greenshot
base.Load(builder);
}
/// <summary>
/// Helper method to create a list of paths where the files can be located
/// </summary>
/// <param name="platform">string with the platform</param>
/// <param name="addons"></param>
/// <returns>IEnumerable with paths</returns>
private IEnumerable<string> 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
);
}
}
}
}

View file

@ -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

View file

@ -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