私のXamarin Formsアプリケーションでは、電話言語に基づいていないユーザーの選択に基づいて、英語とアラビア語のような複数の言語をサポートしています。 次のコードは、言語をアラビア語または英語に変更する方法を示しています。ユーザーの選択に基づいてアプリケーション言語の設定を変更します。
次のコードは、Xamarin Forms SamplesからTranslateExtensionの一部です:
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Text == null)
return "";
ResourceManager resmgr = new ResourceManager(ResourceId, typeof(TranslateExtension).GetTypeInfo().Assembly);
var translation = resmgr.GetString(Text, ci);
if (translation == null)
{
#if DEBUG
throw new ArgumentException(
String.Format("Key '{0}' was not found in resources '{1}' for culture '{2}'.", Text, ResourceId, ci.Name),"Text");
#else
translation = Text; // HACK: returns the key, which GETS DISPLAYED TO THE USER
#endif
}
return translation;
}
誰も私を助け、どのようにデバイスの言語に基づいていないユーザーの選択に基づいて、この仕事をするために教えてもらえます。手伝ってくれてありがとう。