2017-11-06 10:30:25 +01:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2022-04-06 11:49:20 +02:00
|
|
|
|
|
2022-04-29 20:37:37 +02:00
|
|
|
|
public String TranslateKey(String key, String defaultText)
|
2022-04-06 11:49:20 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (key != null && this.dict != null && this.dict.TryGetValue(key, out var translation))
|
|
|
|
|
|
{
|
|
|
|
|
|
return translation;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return defaultText;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-29 20:37:37 +02:00
|
|
|
|
public String TranslateKey(String key, String defaultText, params Object[] args)
|
2022-04-06 11:49:20 +02:00
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
2017-11-06 10:30:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|