CB: Translation eingebaut
This commit is contained in:
24
BeWo/MultiLanguage/Markup/TranslateExtension.cs
Normal file
24
BeWo/MultiLanguage/Markup/TranslateExtension.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Windows.Markup;
|
||||
using BS.Shared.Translation;
|
||||
|
||||
namespace BeWo.MultiLanguage.Markup
|
||||
{
|
||||
[MarkupExtensionReturnType]
|
||||
public class TranslateExtension : MarkupExtension
|
||||
{
|
||||
private readonly String key;
|
||||
|
||||
public TranslateExtension() { }
|
||||
|
||||
public TranslateExtension(String key)
|
||||
{
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public override Object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
return Translator.Translate(this.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
58
BeWo/MultiLanguage/ServiceTranslator.cs
Normal file
58
BeWo/MultiLanguage/ServiceTranslator.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BeWo.ServiceProxy;
|
||||
using BS.Shared.Translation;
|
||||
using DevExpress.Xpo.Logger;
|
||||
|
||||
namespace BeWo.MultiLanguage
|
||||
{
|
||||
public class ServiceTranslator : ITranslator
|
||||
{
|
||||
|
||||
private IDictionary<String, String> dict;
|
||||
private CultureInfo currentCulture;
|
||||
|
||||
public ServiceTranslator()
|
||||
{
|
||||
this.Refresh();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
this.currentCulture = CultureInfo.CurrentUICulture;
|
||||
|
||||
dict = ServiceFacade.DoOperationsServiceSync(s => s.GetTranslationDictionary());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String Translate(String input)
|
||||
{
|
||||
if (input == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (this.dict != null && this.dict.TryGetValue(input, out var translation))
|
||||
{
|
||||
return translation;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public String Translate(String input, params Object[] args)
|
||||
{
|
||||
String translation;
|
||||
if (this.dict.TryGetValue(input, out translation))
|
||||
{
|
||||
return String.Format(this.currentCulture, translation, args);
|
||||
}
|
||||
return String.Format(this.currentCulture, input, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user