Basic localization
By default in Android all of your static text is in a separate file called strings.xml. This lends itself very neatly to localization. I will just look at localization of strings here. Images, currency, time etc. are more complex but also well supported.
First create your application as you normally would with your strings in their own xml file. Next using eclipse right click on your project and select New/Android XML file. In the dialog enter strings.xml as the file name (it won't clash with your existing strings it is going in a separate folder). Select 'language' as the resource configuration and enter the 2 letter code that corresponds to the language you are after. de for German in my case.
Click finish. Next you need to translate that text. I just took the whole xml file and pasted it into the input box on Google Translate. It does not mess with your ids as they have underscores in them. It translated most of my text into German. The rest I just manually pasted in there to get the values and edited the file. Also note that Google Translate tries to format your output nicely and so it capitalizes some stuff and inserts some unhelpful spaces in xml tags. Just edit these by hand. If you are translating a big file a bit of search and replace might be in order.
Now paste this fixed up German language version of the strings into the strings.xml file that the wizard created for you.
Run the app on your emulator. It will be in your base language whatever that is. Hit home on your emulator. Then open the drawer (this will vary by emulator, but I am using the latest one so probably best for examples) and click on Custom Locale. Select the locale you want to check here. Then run your program (I ran it again from Eclipse, but if you have configured your app to have the appropriate intent filter in your manifest you can restart from the launcher).
First create your application as you normally would with your strings in their own xml file. Next using eclipse right click on your project and select New/Android XML file. In the dialog enter strings.xml as the file name (it won't clash with your existing strings it is going in a separate folder). Select 'language' as the resource configuration and enter the 2 letter code that corresponds to the language you are after. de for German in my case.
Click finish. Next you need to translate that text. I just took the whole xml file and pasted it into the input box on Google Translate. It does not mess with your ids as they have underscores in them. It translated most of my text into German. The rest I just manually pasted in there to get the values and edited the file. Also note that Google Translate tries to format your output nicely and so it capitalizes some stuff and inserts some unhelpful spaces in xml tags. Just edit these by hand. If you are translating a big file a bit of search and replace might be in order.
Now paste this fixed up German language version of the strings into the strings.xml file that the wizard created for you.
Run the app on your emulator. It will be in your base language whatever that is. Hit home on your emulator. Then open the drawer (this will vary by emulator, but I am using the latest one so probably best for examples) and click on Custom Locale. Select the locale you want to check here. Then run your program (I ran it again from Eclipse, but if you have configured your app to have the appropriate intent filter in your manifest you can restart from the launcher).
Comments
Post a Comment