Knowing device's current language

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Knowing device's current language

Postby andreleitao » Tue May 12, 2009 9:33 pm

Hi,

I've searched for something about to know how to have access to the phone's current language, but I haven't found anything.
I would like to know how to get device's current language. I need to do it to make an multilanguage app that is based on phone's current language.

E.g.: if device's current language is English, my app will automatically changed to english language. The same for Russian, Portuguese, etc. (Yes, I know I have to implement code to make my app language, but the first step is to know get device's current language :D ).

Thanks!!

Regards,
André Leitão
andreleitao
Experienced Developer
Experienced Developer
 
Posts: 70
Joined: Tue Mar 10, 2009 9:56 pm
Location: Recife - Brazil

Top

Postby Emmanuel7 » Tue May 12, 2009 11:59 pm

You don't have to do this by yourself !

Just put all of your texts for a language in a strings.xml file, and have one strings.xml file for each language, in a specific directory :
value-en for an english text,
value-fr for a french text,
...


See the documentation here :
http://developer.android.com/guide/topi ... -i18n.html

Hope it helps,
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby andreleitao » Wed May 13, 2009 1:32 pm

Thanks for answering, Emmanuel. Your answer helps a lot, but currently I need to do a manual verification because I must to change not only texts, but images too. You see? :) Can you help me anyway? :D


Thanks
andreleitao
Experienced Developer
Experienced Developer
 
Posts: 70
Joined: Tue Mar 10, 2009 9:56 pm
Location: Recife - Brazil

Postby Emmanuel7 » Wed May 13, 2009 4:58 pm

Two things :

Once again, if all the differences you have are just resources, you can stick with my solution in my previous answer : I talked about the value-en/stringx.xml, but you can do the same thing for any resources, including drawable.
So in your case you can have some drawable-en, drawable-fr directories.

Now if you really want different codes for different languages, I imagine you can get the language from the locale object :
http://developer.android.com/reference/ ... ocale.html
( I let you investigate to find how to get the locale object :) )

But I really think the first option is the preferred one !

Hope it helps,
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby padde » Wed May 13, 2009 5:24 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. String locale = context.getResources().getConfiguration().locale.getDisplayName();
  3.  
  4. String locale = java.util.Locale.getDefault().getDisplayName();
  5.  
  6.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


But you could simply use seperate folders..

Good tutorial -> http://groups.google.com/group/android-developers/web/localizing-android-apps-draft

--- Edit ---
Emmanuel7 was faster :D
But the tutorial should be helpfull anyway
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby Emmanuel7 » Wed May 13, 2009 6:21 pm

Emmanuel7 was faster
:)

By the way I didn't know this tutorial, and it is really interesting, covering the whole process !!

Thanks for that !
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Top

Postby andreleitao » Wed May 13, 2009 8:23 pm

Perfect! Thank you guys. :)
andreleitao
Experienced Developer
Experienced Developer
 
Posts: 70
Joined: Tue Mar 10, 2009 9:56 pm
Location: Recife - Brazil

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests