Change Language For Xamarin Android App Using Resources
I have a requirement to change language of App on selection of radio buttons. App already has localization implemented using Android Resources. I have tried below solutions in diff
Solution 1:
I found the solution after a bit of hit and trial - Found that I was using a wrong constructor of Locale, and simply changing it started reflecting the updated language. Below is the working code:
var locale = new Java.Util.Locale(lang, region); // lang => nl; region => BE
Java.Util.Locale.Default = locale;
var context = Application.Context;
context.Resources.Configuration.Locale = locale;
context.Resources.UpdateConfiguration(context.Resources.Configuration, context.Resources.DisplayMetrics);
string title = Application.Context.GetString(Resource.String.title_settings); // Reflects text in updated language
Solution 2:
Have a look at the Xamarin docs: Android Localization and especially the section "GetText Method".
To retrieve translated strings in code, use the GetText method and pass the resource ID:
var cancelText = Resources.GetText (Resource.String.taskcancel);
Post a Comment for "Change Language For Xamarin Android App Using Resources"