Android-localization
Android-ローカリゼーション
Androidアプリケーションは、さまざまな地域の多くのデバイスで実行できます。 アプリケーションをよりインタラクティブにするために、アプリケーションは、アプリケーションが使用されるロケールに適した方法でtext、numbers、files e.t.cを処理する必要があります。
'_文字列を異なる言語に変更する方法は、ローカライズと呼ばれます_
この章では、さまざまな地域などに応じてアプリケーションをローカライズする方法について説明します。 アプリケーションで使用される文字列をローカライズします。他のことも同様にローカライズできます。
文字列のローカライズ
アプリケーションで使用される文字列をローカライズするには、 res の下に values-local という名前の新しいフォルダーを作成します。ここで、localは地域に置き換えられます。
たとえば、イタリアの場合、 values-it フォルダーはresの下に作成されます。 それは以下の画像に示されています-
そのフォルダーが作成されたら、* strings.xml *をデフォルトのフォルダーから作成したフォルダーにコピーします。 そしてその内容を変更します。 たとえば、hello_world文字列の値を変更しました。
イタリア、res/values-it/strings.xml
<;?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello_world">Ciao mondo!</string>
</resources>
スペイン語、res/values-it/strings.xml
<;?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello_world">Hola Mundo!</string>
</resources>
フランス語、res/values-it/strings.xml
<;?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello_world">Bonjour le monde !</string>
</resources>
これらの言語とは別に、他の言語の地域コードは以下の表に記載されています-
Sr.No | Language & code |
---|---|
1 |
Afrikanns コード:af。 フォルダー名:values-af |
2 |
Arabic コード:ar。 フォルダー名:values-ar |
3 |
Bengali コード:bn。 フォルダー名:values-bn |
4 |
Czech コード:cs。 フォルダー名:values-cs |
5 |
Chinese コード:zh。 フォルダー名:values-zh |
6 |
German コード:de フォルダー名:values-de |
7 |
French コード:fr フォルダー名:values-fr |
8 |
Japanese コード:ja フォルダー名:values-ja |
例
この例を試すには、実際のデバイスまたはエミュレーターでこれを実行できます。
Steps | Description |
---|---|
1 | You will use Android studio to create an Android application under a package com.example.sairamkrishna.myapplication. |
2 | Modify the res/layout/activity_main to add respective XML components |
3 | Modify the res/values/string.xml to add necessary string components |
4 | Run the application and choose a running android device and install the application on it and verify the results |
以下は、xml res/layout/activity_main.xml の変更されたコンテンツです。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView android:text="Wifi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="@+id/textView"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hindi"
android:id="@+id/textView2"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:textColor="#ff59ff1a"
android:textSize="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/marathi"
android:id="@+id/textView3"
android:textSize="30dp"
android:textColor="#ff67ff1e"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/arabic"
android:id="@+id/textView4"
android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp"
android:textColor="#ff40ff08"
android:textSize="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chinese"
android:id="@+id/textView5"
android:layout_below="@+id/textView4"
android:layout_alignLeft="@+id/textView3"
android:layout_alignStart="@+id/textView3"
android:layout_marginTop="42dp"
android:textSize="30dp"
android:textColor="#ff56ff12"
android:layout_alignRight="@+id/textView3"
android:layout_alignEnd="@+id/textView3"/>
</RelativeLayout>
以下は res/values/string.xml の内容です。
<resources>
<string name="app_name">My Application</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="hindi">ట్యుటోరియల్స్ పాయింట్</string>
<string name="marathi">शिकवण्या बिंदू</string>
<string name="arabic">نقطة الدروس7</string>
<string name="chinese">教程点</string>
</resources>
変更したばかりのアプリケーションを実行してみましょう。 環境設定中に AVD を作成したと思います。 Androidスタジオからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[画像を実行:/android/images/eclipse_run.jpg [Eclipse Run Icon]アイコンをクリックします。 AndroidスタジオはAVDにアプリをインストールして起動し、セットアップとアプリケーションで問題がなければ、次のエミュレータウィンドウが表示されます-