Pages

Friday, August 3, 2012

Localization

Localization

Pros

1) When the application are localized then it will become more user friendly. 

2) You can launch your application onto the market more rapidly.

3) You use resources more efficiently.

4) Your application is easier to maintain.

Process For Localization

1) Create Folder for Each Language With Naming Convention.

2) Each folder Having Same Name String & Style .xml file.

3) Each .xml File Contain Resources For Each Language.

4) You Can See As Follows.  

Note:- Hindi is available only in 4.1 and above

String.xml (For Hindi) 

Folder Name is in res "values-hi"

<resources>

    <string name="app_name">Localization</string>
    <string name="hello_world">नमस्ते हार्दिक!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
    <string name="Dialog_Message">लोड हो रहा है ...</string>
    <string name="title">In hindi</string>
</resources>

String.xml (For Franch) 

Folder Name is in res "values-fr-rFR"

<resources>

    <string name="app_name">Localization</string>
    <string name="hello_world">This is fr-rFR!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
    <string name="Dialog_Message">Chargement en cours ...</string>
    <string name="title">In French</string>
</resources>

String.xml (For English US) 

Folder Name is in res "values-en-rUS"

 <resources>

    <string name="app_name">Localization</string>
    <string name="hello_world">This is en-rUS!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
    <string name="Dialog_Message">Loading...</string>
    <string name="title">In English US</string>
   
</resources> 

MainActivity.java

package com.example.localization;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    Button b;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b = (Button) findViewById(R.id.btnDialog);
      
        b.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle(R.string.title);
                builder.setMessage(R.string.Dialog_Message);
                builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                   
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Note: Now Change Language of Device from Setting Menu.

Output:-




Localized Dialog:-

Note:- You Can Also Localize Image Also This Is only String Example.







No comments:

Post a Comment

Must Comment