Android Support different language
Its have two type string-
1.
Hardcore
string - When string directly written in xml or code. It doesn't support multiple language.
2.
Referring
String -
Fetching string from string.xml file.
To define multiple languages use -
Syntax - [values-<language-code>] folder.
To define multiple languages use -
Syntax - [values-<language-code>] folder.
Here, Some folder type -
1. values - Default folder for android ( default in English)
2. values-en - Directory for English language.
3. value -es - Directory for Spanish language.
4. values-fr - Directory for French language.
5. values-ja - Directory for Japanese language.
6. values-hi - Directory for Hindi language.
Defining string in string.xml
<string
name="note_email">Enter your email address</string>
When
referring it in xml, use @strings notation.
<TextView
...
android:text="@string/note_email" />
When
defining the string through java code, use R.string
emailNote.setText(R.string.note_email);
Note : English (default locale),
Default Language - English
(/values/strings.xml)
<?xml
version="1.0" encoding="utf-8"?>
<resources>
<string name="title">My
Application</string>
<string
name="hello_world">Hello World!</string>
</resources>
Spanish, /values-es/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name="title">Mi Aplicación</string>
<string
name="hello_world">Hola Mundo!</string>
</resources>
French, /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>
Note : When user changes the
device language through Settings ⇒ Language & Input, android OS itself checks for
appropriate language resources in the app. (Let’s say user is selecting French)
No comments:
Post a Comment