Reputation: 1002
I need to show Map in persian language.
I tried this code , But still map is loaded in English
Locale locale = new Locale("fa");
Locale.setDefault(locale);
android.content.res.Configuration config = new android.content.res.Configuration();
config.locale = locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLayoutDirection(config.locale);
}
DisplayMetrics dm = context.getResources().getDisplayMetrics();
context.getResources().updateConfiguration(config, dm);
Upvotes: 2
Views: 5131
Reputation: 13555
I use this code and works fine
String languageToLoad = "fa_IR";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
setContentView(R.layout.activity_map);
Upvotes: 0
Reputation: 13469
You can use a Locale object to change location for Google Maps API V2. The language needs to be supported on the device being used though.
To change the English language to Persian language, use this Locale code:
//[Persian]
String languageToLoad = "fa_";
Check this link for other supported languages.
Sample code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String languageToLoad = "fa_";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
setContentView(R.layout.activity_maps);
}
Hope this helps! :)
UPDATE:
Tried the code above in another language like Arabic - String languageToLoad = "ar_EG";
and it works fine. See picture below.
You can check this google example and select the language to load in the map. In your case, select Farsi language. I think google still loads the texts in maps in English Language. Persian language will only be loaded in other functions like this example:
Hope this helps! :)
Upvotes: 5