mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Create localization helper classes
This commit is contained in:
parent
d204df2b18
commit
2e714a8d7b
3 changed files with 66 additions and 0 deletions
37
Wox.Core/Resource/LocalizationConverter.cs
Normal file
37
Wox.Core/Resource/LocalizationConverter.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Windows.Data;
|
||||||
|
|
||||||
|
namespace Wox.Core
|
||||||
|
{
|
||||||
|
public class LocalizationConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (targetType == typeof(string) && value != null)
|
||||||
|
{
|
||||||
|
FieldInfo fi = value.GetType().GetField(value.ToString());
|
||||||
|
if (fi != null)
|
||||||
|
{
|
||||||
|
string localizedDescription = string.Empty;
|
||||||
|
var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||||
|
if ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description)))
|
||||||
|
{
|
||||||
|
localizedDescription = attributes[0].Description;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (!String.IsNullOrEmpty(localizedDescription)) ? localizedDescription : value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
27
Wox.Core/Resource/LocalizedDescriptionAttribute.cs
Normal file
27
Wox.Core/Resource/LocalizedDescriptionAttribute.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
using System.ComponentModel;
|
||||||
|
using Wox.Core.Resource;
|
||||||
|
|
||||||
|
namespace Wox.Core
|
||||||
|
{
|
||||||
|
public class LocalizedDescriptionAttribute : DescriptionAttribute
|
||||||
|
{
|
||||||
|
private readonly Internationalization _translator;
|
||||||
|
private readonly string _resourceKey;
|
||||||
|
|
||||||
|
public LocalizedDescriptionAttribute(string resourceKey)
|
||||||
|
{
|
||||||
|
_translator = InternationalizationManager.Instance;
|
||||||
|
_resourceKey = resourceKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Description
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string description = _translator.GetTranslation(_resourceKey);
|
||||||
|
return string.IsNullOrWhiteSpace(description) ?
|
||||||
|
string.Format("[[{0}]]", _resourceKey) : description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -109,6 +109,8 @@
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Plugin\ExecutablePlugin.cs" />
|
<Compile Include="Plugin\ExecutablePlugin.cs" />
|
||||||
<Compile Include="Plugin\PluginsLoader.cs" />
|
<Compile Include="Plugin\PluginsLoader.cs" />
|
||||||
|
<Compile Include="Resource\LocalizationConverter.cs" />
|
||||||
|
<Compile Include="Resource\LocalizedDescriptionAttribute.cs" />
|
||||||
<Compile Include="Updater.cs" />
|
<Compile Include="Updater.cs" />
|
||||||
<Compile Include="Resource\AvailableLanguages.cs" />
|
<Compile Include="Resource\AvailableLanguages.cs" />
|
||||||
<Compile Include="Resource\Internationalization.cs" />
|
<Compile Include="Resource\Internationalization.cs" />
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue