標籤:wrap over cloud version 根據 content standards 參考 屬性
Android-語言國際化參考
http://www.loc.gov/standards/iso639-2/php/code_list.php 各國語言表
Overview
Internationalization(國際化),又名I18n(因為這個單詞的開頭 I
和結尾 n
只有有18個字母),與國際化相對的還有Localization(本地化),又名L10n(命名緣由相同)。
Android 語言國際化,就是根據不同的地區(由系統設定)顯示不同的語言.
Android國際化
這裡我們以中文
和English
之間的國際化。
建立不同國家的values檔案夾
因為我們這裡要做的是中文和英文之間的國際化,所以我們這裡僅僅就建立了values-en
這個目錄,而values下的額strings.xml
則是我們的預設的語言(當系統的語言在程式的資源中沒有被定義的話就載入此資源)。
開始進行布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp" tools:context="little_david.internationalizationdemo.MainActivity"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="使用者名稱"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="密碼"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="登入" android:textAllCaps="false"/></LinearLayout>
游標選中 hint
屬性後按ALT+Entry
快速鍵,依次的將所有的字串都進行提取。
修改漢語為英語
編輯vlaues-en/strings.xml
檔案
<!-- 這是編輯之前的檔案 --><?xml version="1.0" encoding="utf-8"?><resources> <!--這是我們的應用程式名稱,不會自動產生我們需要手動添加一下--> <string name="app_name">國際化 Demo</string> <string name="login_username">使用者名稱</string> <string name="login_password">密碼</string> <string name="login_login_btn">登入</string></resources><!-- 這是修改後的檔案 --><resources> <!--這是我們的應用程式名稱,不會自動產生我們需要手動添加一下--> <string name="app_name">Internationalization Demo</string> <string name="login_username">Username</string> <string name="login_password">Password</string> <string name="login_login_btn">Login</string></resources>
測試效果
在設定中修改當前語言版本為中文
修改當前系統語言為英文
總結
手動進行國際化太累了啊,我們要藉助AndroidStudio的外掛程式來協助我們進行國際化操作。該外掛程式的名稱是AndroidLocalizationer
。 如何使用請百度。
Android-語言國際化