Android learning ---- adaptive internationalization language, android ----

Source: Internet
Author: User

Android learning ---- adaptive internationalization language, android ----




Adaptive knowledge has nothing to do with programming. The key is to modify the configuration file. Adaptive content includes: language, screen, and platform. Let's talk about how to adapt to internationalization today.

Internationalization (international) Abbreviation:I18nBecause there are 18 characters between I and n, localization (localization), L10n for short.

GenerallyLanguage _ RegionIndicates a language. For example, zh_CN indicates Simplified Chinese.


Operation Method:

To support international languages, we only needRes/Directory to re-create a folder:Values-country ID,For exampleValues-zh-rCNIndicatesSimplified Chinese, Values-zh-rTW indicates traditional Chinese, values-jp indicates Japanese, etc.

Note: configuration options includeLanguage codeAndRegion Code. The configuration options for Chinese and Chinese are zh-rCN; the options for English and American are en-rUS. En and en indicate Chinese and English; CN and US indicate China and the United States;The preceding r is required..


Example: supports internationalization of simplified Chinese characters

The procedure is as follows:

Create an Android project Android_i18n. The default code in res/values/strings. xml is as follows:

1 <?xml version="1.0" encoding="utf-8"?>2 <resources>3 4     <string name="app_name">" Android_i18n"</string>5     <string name="hello_world">Hello world!</string>6     <string name="action_settings">Settings</string>7 8 </resources>

Run the program directly on your phone without any modification. The default effect is as follows:

Statement: the default language of my mobile phone is set to Chinese:

In fact, no matter what language the mobile phone is set to, the running effect is the same, because we have not made any international settings yet.Let's start setting it now.

Now add a simplified Chinese Language internationalization: Create a folder under the res/directory to represent the Simplified Chinese:Values-zh-rCN,Shows the directory structure:

Note: If you want to add an International English Language, the new folder isValues-enYou can.

Modify the res/values-zh-rCN/strings. xml Code as follows:

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <resources> 3 4 <string name = "app_name"> "android Internationalization" </string> 5 <string name = "hello_world"> hello, world </string> 6 <string name = "action_settings"> Settings </string> 7 8 </resources>

Run the program as follows:

Because the mobile phone is set to a Chinese language, the loaded string is the resource in the res/values-zh-rCN/directory.



Question 1:

Now I have not added resources corresponding to traditional Chinese. If I set the language of my mobile phone to traditional Chinese, what will happen when I run the program?

Answer: Now,If the resource of Traditional Chinese is not defined, resources under the res/values/directory are loaded by default.

Question 2:

Now defineString, defined only under res/values-zh-rCN/, not res/values/What will happen when running the program?


Now we add a button in activity_main.xml:

1     <Button 2         android:layout_width="match_parent"3         android:layout_height="wrap_content"4         android:text="@string/login_button"/>

Line 1 code: the name displayed by the button references the string login_button.

In this case, the code of res/values/strings. xml remains unchanged:

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="app_name">" Android_i18n"</string>    <string name="hello_world">Hello world!</string>    <string name="action_settings">Settings</string></resources>

Add a line of login_button declaration in res/values-zh-rCN/strings. xml: (07th lines of code)

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <resources> 3 4 <string name = "app_name"> "android Internationalization" </string> 5 <string name = "hello_world"> hello, world </string> 6 <string name = "action_settings"> Settings </string>7 <string name = "login_button"> login button </string>8 9 </resources>


The activity_main.xml view is as follows:

Run the program. If the language of the mobile phone is set to English, the effect is as follows: (abnormal display)

If the phone language is set to Chinese, the result is as follows: (displayed normally)


In fact, internationalization is not difficult, but if you want to support languages in more countries, the workload will be huge.

The following is a list of things that are usually used for reference:

Country abbreviation code:(Query backup)


Attach a common link to international resources:

Country Abbreviation:

Country and region Abbreviation:

Country-specific language lookup table:


My public account

Is my public account (Life team id:vitateam), Welcome to your attention.Blog sharing technology, public account sharing mind.

I would be very grateful to the first people who followed me.At this time, the young me and you have nothing; then, the rich you and me are all loaded.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.