79 lines
2.1 KiB
C#
79 lines
2.1 KiB
C#
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);
|
|
}
|
|
|
|
public String TranslateKey(String key, String defaultText)
|
|
{
|
|
if (key != null && this.dict != null && this.dict.TryGetValue(key, out var translation))
|
|
{
|
|
return translation;
|
|
}
|
|
|
|
return defaultText;
|
|
}
|
|
|
|
public String TranslateKey(String key, String defaultText, params Object[] args)
|
|
{
|
|
String translation;
|
|
if (!String.IsNullOrEmpty(key) && this.dict.TryGetValue(key, out translation))
|
|
{
|
|
return String.Format(this.currentCulture, translation, args);
|
|
}
|
|
return String.Format(this.currentCulture, defaultText, args);
|
|
}
|
|
}
|
|
}
|