Neues Fehlerfenster
This commit is contained in:
78
Service/ServiceUtils/ServiceTranslator.cs
Normal file
78
Service/ServiceUtils/ServiceTranslator.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BeWo.Service.Plugins;
|
||||
using BS.Shared.Translation;
|
||||
|
||||
namespace BeWo.Service.ServiceUtils
|
||||
{
|
||||
public class ServiceTranslator : ITranslator
|
||||
{
|
||||
|
||||
private IDictionary<String, String> dict;
|
||||
private CultureInfo currentCulture;
|
||||
|
||||
public ServiceTranslator()
|
||||
{
|
||||
this.Refresh();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
this.currentCulture = CultureInfo.CurrentUICulture;
|
||||
var translationDictionary = PluginLoader.FindClass<TranslationDictionary>();
|
||||
|
||||
dict = translationDictionary?.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user