I only want set only default English language of application in android.
After Supporting Different Languages, I also use values/strings.xml to store characters in that file.
If in English language mode of System Settings, I can show correct words.
If in Chinese language mode of System Settings, The English words was translated to Chinese.
I don't want it translate automatically.
People who know how to set only default English language,
Please help me.
Thanks,
I can get correct answer now via the codes in below :
public static void setDefaultLanguage(Context context, String lang) {
Locale locale = new Locale(lang);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
}
In that, what is lang value? You should get correct Language System to pass this value to lang parameter.
Thanks,
Are you storing all the strings for both languages in one .xml? If so that is probably your issue…
res/values/strings.xml
Contains English text for all the strings that the application uses,
res/values-ja/strings.xml - for japanese, but I am sure you can find one for the language you are looking for! Android looks for the "values-ja" tag.
Related
I have an application with only russian locale. If I am not mistaken, the string.xml in the res/values is the english locale by default. But english and russian have different plurals. For example:
In russian:
1,21,31..x1 книга
2-4, 2(2-4), 3(2-4), .., x(2-4) книги
in other cases - книг
In english:
1 book
n books
Problems begin when the user changes system language from russian to other language.
How can I change default language for my application? Or maybe it is possible to force the application to use the russian plurals?
I finally found the answer:
https://developer.android.com/studio/write/tool-attributes#toolslocale
<resources xmlns:tools="http://schemas.android.com/tools"
tools:locale="es">
From the doc:
This tells the tools what the default language/locale is for the resources in the given element (because the tools otherwise assume English) in order to avoid warnings from the spell checker. The value must be a valid locale qualifier.
you can create different String.xml files
like this
values/
strings.xml
values-es/
strings.xml
values-fr/
strings.xml
Check google official document https://developer.android.com/training/basics/supporting-devices/languages.html
& https://developer.android.com/guide/topics/resources/localization.html
create new value folder values-ru and place string.xml in that.
in java change your app language programatically with this code. for change to rushion call method with ru parameter like this changeLanguage("ru").
public void changeLanguage(String languageToLoad) {
//for language change
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
}
Which language does android treats default strings.xml as?
Specifically, when there are <plurals> tags inside default strings.xml, rules for which language will Android pick? Is there a way to specify that?
It doesn't treat default values folder as a language dependant. It's basically a fallback if it doesn't find a better match. You can read more here.
Android will pick plurals rules for language that is currently selected in the phone(e.g. if users has german language then android will pick german rules).
Use this to change the language by programmatically--
Locale locale = new Locale("en_US");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);
Write the countrycode of language in place of "en_US" whatever language you want...like for japanese--"ja_JP" For Arabic--"ar" or check this link for code of country--
http://code.google.com/apis/igoogle/docs/i18n.htmlenter code here
I want to provide three different langauges. The default language is english so all my string values in the values folder are in enlish. I created two other folders
values-de for the german language
values-cn for the chinese language
each folder contains a strings.xml file where i defined the values in german for the de folder and in chinese for the cn folder.
My question now is: How can i load a different language programmatically because i want to provide buttons in my app interface where the user can switch the language. The settings of the device wont be editable for our users. Our users can just see the app itself and nothing else so i have to provide the language switching from within my application.
You can change the configuration at runtime
Do this in onCreate of the activity
String languageToUse = "de"; // The language you want to change
Locale locale = new Locale(languageToUse);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
My problem is that i have a Diary application in which i am adding notes by selecting a particular date from Custom Calendar View.
The problem starts when user changes his phone language from English to any other, If user has selected Japanese as his phone's new language, Month's name would be converted in Japanese language.
Now i want that if user selects any other language other than English than also Month's name should be shown in English only.
I searches a lot but could not find anything helpful.
Any positive response will be highly appreciated.
Thanks.
You should use custom calender and when you display your calendar change Locale(Language) to English programatically.
How to change Locale programatically in android.
Hope it helps you.
Edit :
You can change Language using following code :
public void changeLang(String lang)
{
if (lang.equalsIgnoreCase(""))
return;
myLocale = new Locale(lang);
saveLocale(lang);
Locale.setDefault(myLocale);
android.content.res.Configuration config = new android.content.res.Configuration();
config.locale = myLocale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
updateTexts();
}
Call this method by passing your language Like :
changeLang("en");
Note : You must define your string in res/string.xml file for english language. And you should set your string from String.xml not static.
For example for your concern Your calendar Names are set like...
yourtextview.getResources().getString(R.string.january);
I wanna develop android application for different types of languages. So I have used localization for it. For that I have created different values folder like values-fr, values-ja , values-de. N also created strings.xml with static value according to that values folder. So All is good. But now my question is that I wanna change UI text according to user's selection of language. So How can I manually get particular string values from values->string.xml for particular language???
I think it may be easy, But I have no idea.
Thanks,
Locale locale = new Locale("cn");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
http://developer.android.com/guide/topics/resources/localization.html
You just need to get the String from the file like this way
String string = getString(R.string.hello);
Android will choose the folder based on the mobile locale. See this link for further information about Android localization.
http://developer.android.com/guide/topics/resources/localization.html
And this one for String resources if you still have some doubts on how to acces the strings.
http://developer.android.com/guide/topics/resources/string-resource.html
Hope it helps, good luck! :)