48 _ internationalization of software
-----------------------
1. internationalization means that when the software runs in different language environments, the corresponding language is automatically displayed.
-------------------------------------
2. The following example is used to adapt to Chinese and English characters.
-----------------------------------------
3. Create an android project: i18n
A. Create the following folder for internationalization:
/I18n/RES/drawable-en
/I18n/RES/drawable-ZH
The above two are used to internationalize the image.
---------------------------
B./i18n/RES/Values-en
/I18n/RES/Values-en/strings. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "app_name"> i18n </string>
<String name = "name"> name </string>
<String name = "button"> Add </string>
</Resources>
----------------------------------
/I18n/RES/Values-en-Rus
/I18n/RES/Values-en-rus/strings. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "app_name"> i18n (US) </string>
<String name = "name"> name (US) </string>
<String name = "button"> Add (US) </string>
</Resources>
----------------------------------------
/I18n/RES/Values-ZH
/I18n/RES/Values-zh/strings. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "app_name"> internationalization </string>
<String name = "name"> name </string>
<String name = "button"> Add </string>
</Resources>
These three are used to internationalize the text.
----------------------------
C./i18n/RES/layout/Main. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: Orientation = "vertical">
<Textview
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/name"
/>
<! -- Android: text = "@ string/Name" is automatically obtained in the string. xml file of values.
Then, the system automatically calls the corresponding content of the key value in the string. xml file in the values-en folder according to the current language environment.
Or the content corresponding to the key value in the string. xml file of the values-ZH folder. Note that when creating a folder in the corresponding language: values is used at the beginning.
For example, in Chinese: Values-ZH, the XML file in the corresponding language folder may not be in string. XML, but the key and value values must correspond
For example, the China. xml file in the values-ZH folder must be:
The string. XML in values is:
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "app_name"> i18n </string>
<String name = "name"> name </string>
<String name = "button"> Add </string>
</Resources>
The China. xml file in the values-ZH folder is:
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "app_name"> internationalization </string>
<String name = "name"> name </string>
<String name = "button"> Add </string>
</Resources>
That is to say, the content of other files in the values-XXXX folder must be the same as the key of the string. XML content in the values folder.
For example: app_name, app_name
This will allow matching.
When you need to match the languages of different countries: for example, the United States, American English: here you need to create the: Values-en-rus folder under the res folder, where
R represents the country, and us represents the United States in Java.
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "app_name"> i18n (US) </string>
<String name = "name"> name (US) </string>
<String name = "button"> Add (US) </string>
</Resources>
Language recognition rules: for example, when the system language is set to British English, the system cannot find the English language, it will use the files in the "values-en" folder.
If it is set to a language without a folder, files in the values folder are automatically matched.
-->
<Edittext
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
/>
<Button
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/button"
/>
<Imagebutton
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/exit"
/>
</Linearlayout>
----------------------------------------
4. provide the appropriate text for a specific country:
5. The image is internationalized.
Some images have text on them, for example, button pictures: Display (exit), (exit) on a button image ),.. .
Drawable-hdpi
Drawable-ldpi
Drawable-mdpi
These three folders are used to store images of different resolutions.
------------------------------------------
6. Create a new image When internationalizing the image:
Drawable-en: English Image
Drawable-Zh: Chinese Image
Folder. The system automatically calls images in different files according to the language environment.
Bytes ------------------------------------------------------------------------------------