What about internationalization and localization? It is to create files of different national languages in the resource folder res. The naming rules of these national languages are stipulated. For details, see Table 6-1. When the user sets the language of the mobile phone, the program can load the corresponding language file based on the language selected by the user. The user feels that the program is localized, and for developers, the program is internationalized.
In this example, a registration interface is implemented, which can implement the localization process of Simplified Chinese and Traditional Chinese. The Written string. xml and folder names are shown in Table 6-1.
Table 6-1 file name comparison table
Values/strings. xml default
Values-ZH-RCN/strings. XML (simplified)
Values-ZH-RTW/strings. XML (Traditional Chinese)
The directory structure in the res folder is 6-26.
Figure 6-26 res directory structure
You need to create three strings. XML files, which are in English by default and are located in chapter6_10/RES/values/strings. xml. The implementation code is as follows. Go to "Settings"> "language and keyboard"> "Select language" and select English. Go back to the application page 6-27.
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "hello"> Hello world, button! </String>
<String name = "app_name"> chapter6_5 </string>
<String name = "registerinfo"> Registration Information </string>
<String name = "username"> Username: </string>
<String name = "password"> password: </string>
<String name = "sex"> sex: </string>
<String name = "radiobutton01"> male </string>
<String name = "radiobutton02"> female </string>
<String name = "holobby"> holobby: </string>
<String name = "checkbox01"> travel </string>
<String name = "checkbox02"> Read </string>
<String name = "checkbox03"> net </string>
<String name = "button01"> Save </string>
</Resources>
Figure 6-27 project run 5
The files in simplified Chinese are located in chapter6_10/RES/Values-ZH-RCN/strings. XML, for example, the code list is 6-19. Choose "Settings"> "language and keyboard"> "Select language", and return to the application interface 6-28.
[Code listing 6-19] chapter6_10/RES/Values-ZH-RCN/strings. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "hello"> Hello world, button! </String>
<String name = "app_name"> chapter6_5 </string>
<String name = "registerinfo"> Registration Information </string>
<String name = "username"> User name: </string>
<String name = "password"> password: </string>
<String name = "sex"> Gender: </string>
<String name = "radiobutton01"> male </string>
<String name = "radiobutton02"> female </string>
<String name = "holobby"> Hobbies: </string>
<String name = "checkbox01"> tourism </string>
<String name = "checkbox02"> reading </string>
<String name = "checkbox03"> surfing the Internet </string>
<String name = "button01"> Save </string>
</Resources>
Figure 6-28 project run 6
Files in Traditional Chinese are stored in chapter6_10/RES/Values-ZH-RTW/strings. XML, for example, the code list is 6-20. Choose "Settings"> "language and keyboard"> "Select language", and return to the application interface 6-29.
[Code list 6-20] chapter6_10/RES/Values-ZH-RTW/strings. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "hello"> Hello world, button! </String>
<String name = "app_name"> chapter6_5 </string>
<String name = "registerinfo"> collect metadata </string>
<String name = "username"> Use region name: </string>
<String name = "password"> password: </string>
<String name = "sex"> sex: </string>
<String name = "radiobutton01"> male </string>
<String name = "radiobutton02"> female </string>
<String name = "holobby"> loose: </string>
<String name = "checkbox01"> travel expenses </string>
<String name = "checkbox02"> View checkpoints </string>
<String name = "checkbox03"> online </string>
<String name = "button01"> Save </string>
</Resources>
Figure 6-29 project run 7