Files
BeWoPlaner/BeWo/MultiLanguage/ServiceTranslator.cs
2017-11-06 10:30:25 +01:00

59 lines
1.4 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);
}
}
}