Friday, December 26, 2014

Multiple Language App in android

Hello friends This is multiple language app in detail:-


Multiple Language Selection Application:-
Layout:-




<LinearLayout 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:orientation="vertical">

    
   
    <TextView
        android:id="@+id/tvinamea"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/greet"
        />
   
   
       <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/langselection"
        android:textAppearance="?android:attr/textAppearanceMedium"
         android:gravity="center" android:paddingTop="25sp"/>
      
     <Spinner
        android:id="@+id/spndata"
        android:layout_width="fill_parent"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_height="wrap_content"
        android:entries="@array/languages" 
        />
   
    <TextView
        android:id="@+id/descreption"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/descreption"
        android:textSize="25sp"
        android:gravity="center"
         android:paddingTop="25sp" />
    
    
</LinearLayout>

.class:-

package com.example.multiplecountry;

import java.util.Locale;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends Activity {
                Locale myLocale;
                Spinner spndata;
                TextView tviname,tviDescript;

                @Override
                protected void onCreate(Bundle savedInstanceState) {
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.activity_main);

                                spndata = (Spinner) findViewById(R.id.spndata);
                                 
                               

                                spndata.setOnItemSelectedListener(new OnItemSelectedListener() {

                                                @Override
                                                public void onItemSelected(AdapterView<?> parent, View v,
                                                                                int pos, long id) {
                                                                // TODO Auto-generated method stub
                                                                String country = parent.getItemAtPosition(pos).toString();
                                                                /* System.out.println("Country=="+country); */
                                                               
                                                                   if (pos == 1) {
                                                                                  
                                   
                                    setLocale("ta");
                                } else if (pos == 2) {
                 
                                   
                                    setLocale("hi");
                                } else if (pos == 3) {
                 
                                    
                                    setLocale("en");
                                }
                                else if (pos == 4) {
                 
                                   
                                    setLocale("fr");
                                }
                                                                 
                                else if (pos == 5) {
                 
   
                                                setLocale("ru");
                                }
                                else if (pos == 6) {
                 
   
                                                setLocale("it");
                                }
                                else if (pos == 7) {
                 
                                   
                                    setLocale("ja");
                                }
                                else if (pos == 8) {
                 
                                   
                                    setLocale("ta");
                                }
                                                                 

                                                }

                                                @Override
                                                public void onNothingSelected(AdapterView<?> arg0) {
                                                                // TODO Auto-generated method stub

                                                }
                                });

                }
                 
                private void setLocale(String lang) {
                                // TODO Auto-generated method stub
                                myLocale = new Locale(lang);
                                Resources res = getResources();
                                DisplayMetrics dm = res.getDisplayMetrics();
                                Configuration conf = res.getConfiguration();
                                conf.locale = myLocale;
                                res.updateConfiguration(conf, dm);
                                Intent refresh = new Intent(this, MainActivity.class);
                                startActivity(refresh);
                }

}








Values-en:-

<resources>

    <string name="app_name">Androidlocalization</string>
    <string name="hello_world">Hello world!</string>
    <string name="title_activity_android_localize">AndroidLocalize</string>
    <string name="greet">Welldone Amit sharma!!</string>
    <string name="descreption">Welldone Amit sharma!!</string>
    <string name="langselection">Select the language in which you want to greet Amit sharma!!!!</string>
    <string name="chooselang">Choose the language</string>
      <string-array name="languages">
        <item>Select language</item>
        <item>தமிழ்</item>
        <item>हिंदी</item>
        <item>English</item>
        <item>Franch</item>
         <item>ぐるたび</item>
         <item>italiano</item>
         <item>Россия</item>
    </string-array>

</resources>


Values-fr:-

<resources>

     <string name="app_name">Androidlocalization</string>
    <string name="hello_world">Hello world!</string>
    <string name="title_activity_android_localize">AndroidLocalize</string>
    <string name="greet">Welldone Amit sharma!!</string>
    <string name="descreption">Welldone Amit sharma!!</string>
    <string name="langselection">Select the language in which you want to greet Amit sharma!!!!</string>
    <string name="chooselang">Choose the language</string>
      <string-array name="languages">
        <item>Select language</item>
        <item>தமிழ்</item>
        <item>हिंदी</item>
        <item>English</item>
        <item>Franch</item>
         <item>ぐるたび</item>
         <item>italiano</item>
         <item>Россия</item>
    </string-array>

</resources>


Values-hi:-

<resources>

    <string name="app_name">Androidlocalization</string>
    <string name="hello_world">Hello world!</string>
    <string name="title_activity_android_localize">AndroidLocalize</string>
    <string name="greet">बधाई अमित शर्मा!!</string>
    <string name="descreption">बधाई अमित शर्मा !!</string>
    <string name="langselection">जिस भाषा में आप अमित शर्मा  को नमस्कार करना चाहते हैं का चयन करें!!!!</string>
   
   
    <string name="chooselang">Choose the language</string>
      <string-array name="languages">
        <item>Select language</item>
        <item>தமிழ்</item>
        <item>हिंदी</item>
        <item>English</item>
              <item>Franch</item>
               <item>ぐるたび</item>
               <item>italiano</item>
<item>Россия</item>


</string-array>

</resources>
Values-it

<resources>

    <string name="app_name">Androidlocalization</string>
  
    <string name="hello_world">Ciao mondo!</string>
    <string name="title_activity_android_localize">AndroidLocalize</string>
    <string name="greet">Welldone Amit Sharma !!</string>
    <string name="descreption">Welldone Amit Sharma !!</string>
    <string name="langselection">Selezionare la lingua in cui si desidera salutare Amit Sharma !!!!</string>
     <string name="chooselang">Choose the language</string>
    
   
    <string-array name="languages">
        <item>Select language</item>
        <item>தமிழ்</item>
        <item>हिंदी</item>
        <item>English</item>
        <item>Franch</item>
         <item>ぐるたび</item>
         <item>italiano</item>
         <item>Россия</item>
    </string-array>

</resources>

Values-ja:-

<resources>

    <string name="app_name">Androidlocalization</string>
    <string name="hello_world">Hello world!</string>
    <string name="title_activity_android_localize">AndroidLocalize</string>
    <string name="greet">Welldoneアミットのシャルマ!!</string>
    <string name="descreption">Welldoneアミットのシャルマ!!</string>
    <string name="langselection">あなたはアミットのシャルマに挨拶したい言語を選択します!!!!</string>
    <string name="chooselang">言語を選択</string>
      <string-array name="languages">
        <item>Select language</item>
        <item>தமிழ்</item>
        <item>हिंदी</item>
        <item>English</item>
        <item>Franch</item>
        <item>ぐるたび</item>
        <item>italiano</item>
        <item>Россия</item>
    </string-array>

</resources>

Values-ru:-

<resources>

    <string name="app_name">Androidlocalization</string>
    <string name="hello_world">Привет, мир!</string>
    <string name="title_activity_android_localize">AndroidLocalize</string>
    <string name="greet">Welldone Амит Шарма !!</string>
    <string name="descreption">Welldone Амит Шарма !!</string>
    <string name="langselection">Выберите язык, на котором вы хотите, чтобы приветствовать Амит Шарма !!!!</string>
    <string name="chooselang">Choose the language</string>
      <string-array name="languages">
        <item>Select language</item>
        <item>தமிழ்</item>
        <item>हिंदी</item>
        <item>English</item>
        <item>Franch</item>
         <item>ぐるたび</item>
       <item>Россия</item>
    </string-array>

</resources>

Values-ta:-


<resources>

    <string name="app_name">Androidlocalization</string>
    <string name="title_activity_android_localize">AndroidLocalize</string>
    <string name="greet">பாராட்டுக்கள் அமித் சர்மா!!</string>
    <string name="descreption">பாராட்டுக்கள் அமித் சர்மா!!</string>
    <string name="langselection">நீங்கள் சச்சினை வாழ்த்த விரும்பும் மொழியினை தேர்ந்தெடுக்கவும்!!!!</string>
    <string name="chooselang">மொழியை தேர்ந்தெடு</string>

    <string-array name="languages">
        <item>Select language</item>
        <item>தமிழ்</item>
        <item>हिंदी</item>
        <item>English</item>
              <item>Franch</item>
               <item>ぐるたび</item>
               <item>italiano</item>
               <item>Россия</item>
    </string-array>

</resources>






No comments:

Post a Comment