How do I determine the language setting of an Android device. I am doing this to internationalize my app. Thanks!
You have to use different string.xml files
res/
values/
strings.xml
values-es/
strings.xml
values-fr/
strings.xml
Refer below link
Supporting Different Languages
And also Read Localization
The most common to do this is to keep a string file with the strings you want to localize in the res/values folder. You can then create additional values folders marked with resource qualifiers that will contain localized string files.
For example, if you want to translate to german, you create the res/values-de folder and put your localized string file in the folder. Android will load this folder automatically if the language is set to german. If the current system language has no values folder, it will use the default res/values folder.
There is a very simple method: right click on the strings.xml file and select Open translation editor or click on open editor.
You will see the different entries appear in the strings.xml file. By clicking on the icon representing the Earth (Add local), you can add a new language and enter the translation of the entries as desired.
When this is done, you should see a new strings.xml file appear in the tree window, accompanied by the flag of the chosen language and the extension of this language in parentheses.
You just have to compile and test the application on your emulator, by testing different language choices on it.
Create values folder for different language and put this language String.
example : values-ca and put Canada language String in this folder.
So, if user change the phone language then it is show this country language.
Thanks.
You have to use different string.xml files
res/
values/
strings.xml
values-hi/
strings.xml
<resources>
<string name="welcome">स्वागतम</string>
<string name="email">ईमेल पता</string>
<string name="password">पासवर्ड</string>
<string name="login">लॉगिन</string>
<string name="signup">खाता नहीं है? साइन अप करें</string>
values-gu/strings.xml
<resources>
<string name="welcome">પધારો </string>
<string name="email">ઈમૈલ નું નામ</string>
<string name="password">પાસવોર્ડ</string>
<string name="login">લોગીન</string>
<string name="signup">એકાઉન્ટ નથી ? સાઈન ઉપ કરો</string>
values-ja/strings.xml
<resources>
<string name="welcome">歓迎</string>
<string name="email">電子メールアドレス</string>
<string name="password">パスワード</string>
<string name="login">ログイン</string>
<string name="signup">アカウントをお持ちでない場合は?サインアップ</string>
values-ja/strings.xml
<string name="welcome">Willkommen!</string>
<string name="email">Email Addresse</string>
<string name="password">passowrd</string>
<string name="login">Login</string>
<string name="signup">müssen nicht angemeldet? Anmeldung</string>
Do you really need this to do manually? Actually in android are already built-in internationalization mechanizms - resource qualifiers.
All you need to do is add specific strings.xml for each locale.
http://developer.android.com/guide/topics/resources/localization.html
Related
I would like to provide my own translations for my new Android app without using the Translation Service in Google Play Console. I have already provided translations for the app descriptions but this would be for the buttons and strings in the app.
I started to upload the xml files into the Translation Service, but then decided I don't want to pay for something that I can already translate myself. What is the best way to do this?
For example, English:
<resources>
<string name="SaveSetting">Save setting</string>
<string name="ViewSettings">View settings</string>
<string name="SavedSettings">Saved settings</string>
<string name="settingHint">Enter the setting name</string>
</resources>
Portuguese:
<resources>
<string name="SaveSetting">Salvar configuração</string>
<string name="ViewSettings">Ver configurações</string>
<string name="SavedSettings">Configurações salvadas</string>
<string name="settingHint">Nome da configuração</string>
</resources>
You create multiple string files, one for each language and the phone will automatically use the one based on the OS settings
see here: https://developer.android.com/guide/topics/resources/localization
In your case you would put your default strings in the res/values/strings.xml and the Portuguese ones in a res/values-pt/strings.xml
If you are using Android Studio, you can Open the translations editor and then add the translations for your app's strings on any language.
For more details check: https://developer.android.com/studio/write/translations-editor
Try using this tree in your project with correct folders and strings.xml suffix:
MyProject/
res/
values/
strings.xml
values-b+es/
strings.xml
mipmap/
country_flag.png
mipmap-b+es+ES/
country_flag.p
"es" for Spain, "us" USA...
Take a look:
https://developer.android.com/training/basics/supporting-devices/languages
I use Lint to check for missing translations in strings.xml (in values-de, values-en, values-hu, etc.). However, I noticed that if there are no strings in another language in other strings.xml files, Lint does not find the missing translations.
Example:
values/strings.xml:
<string name="abc">test</string>
values-en/strings.xml:
<!--empty-->
-> not work
values/strings.xml:
<string name="dummy">dummy</string>
<string name="abc">test</string>
values-en/strings.xml:
<string name="dummy">dummy</string>
-> works
Is there any way to force Lint to control that translation for string called "abc" is missing without adding dummy string? Unfortunately, even empty strings.xml files are not enough.
If you want to have a string only in strings.xml try that.
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation">
<string translatable="false" name="abc">test</string>
</resources>
I am using takephoto_library for selecting multiple images.
https://github.com/crazycodeboy/TakePhoto
It is working properly but as you can see in the below screenshot, the caption is in Chinese.
I found that the view control is "com.darsh.multipleimageselect.activities" and Id of this caption is in the below
actionBar.setTitle(R.string.album_view);
Is there any way to change this string to English?
Is there any way to change this string to English?
Yes, you can change all the Strings in strings.xml
https://github.com/crazycodeboy/TakePhoto/blob/master/takephoto_library/src/main/res/values/strings.xml
Change these two chinese word to english
<string name="add">确定</string>
<string name="selected">已选</string>
In English
<string name="add">confirm</string>
<string name="selected">selected</string>
Try this .
find the strings.xml(values) and strings.xml(values-en) in the library of TakePhoto .
And change the string name to the English .
In the strings.xml(values)
string name="add">确定</string>
<string name="selected">已选</string>
<string name="limit_exceeded">最多能选 %d 张</string>
And add this to the strings.xml(values-en)
string name="add">confirm</string>
<string name="selected">selected</string>
<string name="limit_exceeded">You can choose%d at most</string>
And you can change this strings.xml(values-en) and strings.xml(values)
For internationalization, android looks in different directories for the appropriate local as determined by your selection for the phone. For instance, you should see something like this:
./explorer/src/main/res/values-uk/strings.xml
./explorer/src/main/res/values-tr/strings.xml
./explorer/src/main/res/values-ru/strings.xml
./explorer/src/main/res/values-pl/strings.xml
./explorer/src/main/res/values-de/strings.xml
./explorer/src/main/res/values-ko/strings.xml
./explorer/src/main/res/values-sv/strings.xml
...
Where the translated strings are in the values-../strings as determined by the res/values/strings.xml.
In my case, res/values/strings.xml has an entry:
<string name="createnewfolder">Create new folder</string>
which is translated in values-uk/strings.xml as
<string name="createnewfolder">Нова папка</string>
You might find Localizing with Resources useful.
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
I need a place where I can store basic application configuration(URIs, DB-name, external storage folder-names, etc) in XML or any other decent format.
Is it /assets folder ? If so - give a basic example of using it in conjunction with XML files.
Thanks.
Yes there is: Resources folder: res/values/strings.
There you can place all the strings you want.
To use locale specific strings create multiple value folders ending with the locale suffix.
values folder (default):
<string name="app_name">My android app name</string>
<string name="email">myemail#gmail.com</string>
<string name="contact_me">Contact me</string>
values-PT folder (portuguese strings):
<string name="app_name">My android app name in PT</string>
<string name="email">myemail#gmail.com</string>
<string name="contact_me">pt string for contact me</string>
then just use them as: yourPackage.R.string.email on your classes.