【问题标题】:Xamarin Load Localization files dynamicallyXamarin 动态加载本地化文件
【发布时间】:2014-12-19 23:58:26
【问题描述】:
【问题讨论】:
标签:
c#
xamarin.ios
xamarin
xamarin.android
【解决方案1】:
我会看看这个例子:Xamarin Forms localization Xlf
这里有一个翻译类
public static string Localize(string key)
{
try
{
var netLanguage = Locale();
ResourceManager temp = new ResourceManager("MyApp.Strings.AppResources", typeof(Translator).GetTypeInfo().Assembly);
string result = temp.GetString(key, new CultureInfo(netLanguage));
return result;
}
catch (Exception ex)
{
return null;
}
}
但这里不是使用 ResourceManager 来获取您的字符串,而是从 Sqlite 数据库中获取它,您可以在应用程序启动时根据应用程序的语言环境下载相关翻译。
在 xaml 中,您可以像这样使用此类:
<ContentPage xmlns:local="clr-namespace:MyApp;assembly=MyApp">
<Label Text="{local:Translate MyFieldStrike}"/>
</ContentPage>
在回答您最初的问题时,我会说没有办法动态下载和加载您的资源文件,因为它们是嵌入式资源