Android-語言國際化

來源:互聯網
上載者:User

標籤: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-語言國際化

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.