Language Localization in Android Application

April 4, 2013
By

In this article, we will develop an Android application which displays TextView content and Activity title in French language.



This application is developed in Eclipse (4.2.1) with ADT plugin (21.1.0) and Android SDK (21.1.0) .


1. Create a new Android application project namely “LngLocalAppSpecific”

New Android application project

Figure 1 : New Android application project


2. Configure application project

Configure Android application project

Figure 2 : Configure Android application project


3. Design application launcher icon

Design application launcher icon

Figure 3 : Design application launcher icon


4. Create a blank activity

Create a blank activity

Figure 4 : Create a blank activity


5. Enter MainActivity details

Enter MainActivity details

Figure 5 : Enter MainActivity details


6. Update the file res/values/strings.xml


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Application Specific Localization</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
</resources>


7. Create a folder namely values-fr in the folder “res


8. Create an xml file namely strings.xml in the folder res/values-fr


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Localisation d\'applications spécifiques</string>
    <string name="action_settings">réglages</string>
    <string name="hello_world">Bonjour tout le monde!</string>
</resources>


9. Update the file src/in/wptrafficanalyzer/lnglocalappspecific/MainActivity.java


package in.wptrafficanalyzer.lnglocalappspecific;

import java.util.Locale;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Creating an instance of Locale for French language
        Locale locale = new Locale("fr");

        // Creating an instance of Configuration
        Configuration config = new Configuration();

        // Setting locale of the configuration to french language
        config.locale = locale;

        // Updating the application configuration
        getBaseContext().getResources().updateConfiguration(
                    config,
                    getBaseContext().getResources().getDisplayMetrics()
                );

        // Setting the title for the activity, after configuration change
        setTitle(R.string.app_name);

        // Setting the layout for the activity
        setContentView(R.layout.activity_main);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}



10. Screenshot of the application in action

Language Localization in Action

Figure 6 : Language Localization in Action


11. Download source code


How to hire me?

I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to info@wptrafficanalyzer.in.

My other blogs
store4js.blogspot.com


Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :



Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner