I have created a folder values-fr for French localization and placed String.xml with french strings in it. When I change the language in my testing device to french it's not changing. PS: Xamarin Android.
Just to post the answer from the comments.
Try this to get the Locale language (just to check), put it in to OnCreate() method:
Android.Content.Res.Configuration conf = res.Configuration;
var languageCodeValue = conf.Locale;
if the language it's ok, then check the folder name, you can see more information here https://learn.microsoft.com/es-es/xamarin/android/app-fundamentals/localization
Then check the name of the file, Xaml can't recognize the UpperCase, so you need to define all in minus, check if you have named the file strings.xml
Related
I want to make application, that will support languages with resources depending of actual localization and country code. According to Documentation I need to change resources to format i.e. values-en-rUS, and in that configuration app sucessful compile and proper flag image in resources is set it up but I dont know what format should be write in Locale variable to change resources. I try en_US , en-rUS , en-US but does doesnt work correctly. In my previous version with resources like values-en changing Locale of the app language to en the resources are updating correctly.
Locale for values-en-rUS can be obtained by new Locale("en", "US"), this will get instance of "en_US" locale (matching values-en-rUS).
Don't use new Locale("en_US") this will produce "en_us". That doesn't match values-en-rUS. Also new Locale("en-US") will not work.
From API level 21, there's handy Locale.forLanguageTag(String) method. It returns a locale for the specified IETF BCP 47 language tag string, which is "en-US" in this case. So you can use Locale.forLanguageTag("en-US).
Not totaly sure of what you asking but if you want to add languages you need to create indeed to create the write folder but in that format : <resource type>-b+<language code>[+<country code>]
example : value-b+en+US
Then you can add the strings.xml file in each folder to what you want to display. You can find all the documentation here.
I read this google doc.
It says we must use this format:
<resource type>-b+<language code>[+<country code>]
for example: value-b+es/string.xml
But somewhere it use value-es/string.xml
Is it true?
also how system can understand which language must choose?
for example I call string by this:
String hello = getResources().getString(R.string.hello_world);
Do I have to use a condition? (if yes how?) ...I couldn't undesrtand the doc well.
Yes. Android OS can choose the best language for user from your app by searching res folder.
For example,you can define the Spanish string values in the res/values-es/strings.xml.
So, if user set up their primary language as a Spanish in the phone, Android OS will read strings from your res/values-es/strings.xml folder first instead of res/values/strings.xml.
If some strings missing in the res/values-es/strings.xml then it will be referenced from res/values/strings.xml
Android loads text and media resources from the project’s ‘res’ directory. based on the current device configuration and locale.
For example, if the code loads a string called ‘R.string.title’, Android will choose the correct value for that string at runtime by loading the appropriate strings.xml file from a matching ‘res/values’ directory.
AndroidAppProject/
res/
values/
strings.xml
values-es/
strings.xml
values-fr/
strings.xml
At runtime, the Android system uses the appropriate set of string resources based on the locale currently set for the user's device.
Now u can load specific locale strings from res folder using:
getResources().getString(R.string.hello_world);
For ex:
Configuration conf = getResources().getConfiguration();
conf.locale = new Locale("fr"); //french language locale
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Resources resources = new Resources(getAssets(), metrics, conf);
/* get localized string */
String str = resources.getString(R.string.hello_world);
this will load R.string.hello_world from values-fr/ directory.
See the Doc
I want to change the language of a my application according to the default language of the device in which the app is installed.
For example: if the default language of the device is French, the user will use the app in French.
I've tried to search for a solution, but probably I don't understand how to do that. Anyone can help me? Every help will be gretly appreciated.
To add support for more languages, create additional values directories inside res/ that include a hyphen and the ISO country code at the end of the directory name. For example, values-es/ is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time.
Create the resource subdirectories and string resource files. For example:
MyProject/
res/
values/
strings.xml
values-es/
strings.xml
values-fr/
strings.xml
Where fr = french
And in /values-fr/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">Mon Application</string>
<string name="hello_world">Bonjour le monde !</string>
</resources>
Source = Multi language
use qualifiers on your strings i believe fr is for france. So if you have a resource folder called values-fr, then anyone with french on their phone will get the french string file located in that folder and everyone else will get the string file in the values folder (without the -fr qualififer)
You can use qualifiers in all kind of resources of your app. You can for example, have a different layout depending on user language (it's useful on japanese or arabic language).
http://developer.android.com/guide/topics/resources/localization.html
How would I store some language independent values like website address in an Android project. I am currently storing it inside my strings.xml. This does not look good as if I add another language and translations, this entry will still have the same value and will be duplicated.
I would also like to get some tips on creating Android projects with I18N in mind.
You don't need to create the same keys in the translated xml file again. If Android does not find link in the German/Spanish/Whatever language file, it will fall back to the original key stored in the default string.xml.
I suggest to implement the English version first and after that let someone translate it.
for i18n-format, you can create some resources folder for one local :
/res/values <- default locale
/res/values-fr <- values for french locale
...
For more examples, read documentation : http://developer.android.com/guide/topics/resources/localization.html
For language independent Strings just create a class with constants :
public class MyIndependentStrings {
public static final String SOME_STRING = "Value";
}
Usage :
tvMyTextView.setText(MyIndependentStrings.SOME_STRING);
In this case you will use constants and not i18n Strings from ../values/strings.xml
Try putting language independent strings in:
\res\values-nodpi\strings.xml
how can i write different language (Bangla) on textview or edittext in Android and for this What version of API i have to need
If you use strings.xml to add a level of indirection for string values, then you can easily localize your strings as in:
android:text="#string/main_text_view_hello"
So I have a strings.xml in folders:
res/values
res/values-en-rCa
res/values-en-rGB
Any time I want to change a value for Canada or United Kingdom, I just add it to the appropriate folder. All other values are obtained by default from res/values.
You can set text with TextView.setText(String-ID) . String-IDs are managed in strings.xml files which are under res/values folder. If you want another language for example german you need another strings.xml file with the same String-IDs in res/values-de. In android layout files you can reference such string ids with #string/stringid.