Open up localization for custom implementations

This commit is contained in:
Martijn van Dijk 2018-02-02 16:37:21 +01:00
Родитель 7e6ddd9b97
Коммит 3b7404a76f
4 изменённых файлов: 17 добавлений и 21 удалений

Просмотреть файл

@ -25,9 +25,7 @@ namespace MvvmCross.Plugins.JsonLocalization
var key = MakeLookupKey(namespaceKey, typeKey, name);
_entries[key] = value;
}
#region Implementation of IMvxTextProvider
public override string GetText(string namespaceKey, string typeKey, string name)
{
var key = MakeLookupKey(namespaceKey, typeKey, name);
@ -54,7 +52,5 @@ namespace MvvmCross.Plugins.JsonLocalization
textValue = key;
return false;
}
#endregion Implementation of IMvxTextProvider
}
}

Просмотреть файл

@ -16,14 +16,20 @@ namespace MvvmCross.Plugins.JsonLocalization
: base(maskErrors)
{
}
private IMvxJsonConverter JsonConvert => Mvx.Resolve<IMvxJsonConverter>();
#region IMvxJsonDictionaryTextLoader Members
private IMvxJsonConverter _jsonConvert;
protected IMvxJsonConverter JsonConvert
{
get
{
_jsonConvert = _jsonConvert ?? Mvx.Resolve<IMvxJsonConverter>();
return _jsonConvert;
}
}
public abstract void LoadJsonFromResource(string namespaceKey, string typeKey, string resourcePath);
public void LoadJsonFromText(string namespaceKey, string typeKey, string rawJson)
public virtual void LoadJsonFromText(string namespaceKey, string typeKey, string rawJson)
{
var entries = JsonConvert.DeserializeObject<Dictionary<string, string>>(rawJson);
foreach (var kvp in entries)
@ -31,7 +37,5 @@ namespace MvvmCross.Plugins.JsonLocalization
AddOrReplace(namespaceKey, typeKey, kvp.Key, kvp.Value);
}
}
#endregion IMvxJsonDictionaryTextLoader Members
}
}

Просмотреть файл

@ -10,11 +10,9 @@ namespace MvvmCross.Plugins.JsonLocalization
public abstract class MvxTextProvider :
MvxResourceProvider, IMvxTextProvider
{
#region Implementation of IMvxTextProvider
public abstract string GetText(string namespaceKey, string typeKey, string name);
public string GetText(string namespaceKey, string typeKey, string name, params object[] formatArgs)
public virtual string GetText(string namespaceKey, string typeKey, string name, params object[] formatArgs)
{
var baseText = GetText(namespaceKey, typeKey, name);
if (string.IsNullOrEmpty(baseText))
@ -28,7 +26,7 @@ namespace MvvmCross.Plugins.JsonLocalization
public abstract bool TryGetText(out string textValue, string namespaceKey, string typeKey, string name);
public bool TryGetText(out string textValue, string namespaceKey, string typeKey, string name, params object[] formatArgs)
public virtual bool TryGetText(out string textValue, string namespaceKey, string typeKey, string name, params object[] formatArgs)
{
if (!TryGetText(out textValue, namespaceKey, typeKey, name)) return false;
@ -43,7 +41,5 @@ namespace MvvmCross.Plugins.JsonLocalization
textValue = string.Format(textValue, formatArgs);
return true;
}
#endregion Implementation of IMvxTextProvider
}
}

Просмотреть файл

@ -51,7 +51,7 @@ namespace MvvmCross.Plugins.ResxLocalization
return null;
}
public string GetText(string namespaceKey, string typeKey, string name, params object[] formatArgs)
public virtual string GetText(string namespaceKey, string typeKey, string name, params object[] formatArgs)
{
var baseText = GetText(namespaceKey, typeKey, name);
@ -69,7 +69,7 @@ namespace MvvmCross.Plugins.ResxLocalization
return textValue != null;
}
public bool TryGetText(out string textValue, string namespaceKey, string typeKey, string name, params object[] formatArgs)
public virtual bool TryGetText(out string textValue, string namespaceKey, string typeKey, string name, params object[] formatArgs)
{
if(!TryGetText(out textValue, namespaceKey, typeKey, name))
return false;