Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 7    Views: 115

Don
Aspiring developer
Profile
Posts: 40
Reg: Aug 10, 2012
moving within e...
2,550
10/22/12 01:22 PM (13 years ago)

Easy guide to localize the BT_config.txt of your app in any language

Hey all, For once, I though it would cool to post here something for the community instead of asking :) I hope this will work for you and there is no mistake, I am not an expert coder. It's a quick tweak for android to automatically get the user's device language and to have your app chose accordingly the correct BT_config.txt this way you can have in the same app 1 BT_config.txt per language, and your user will get the language version relevant for him (it will be invisible for him, nothing to choose) There are tons of tutorial out there to localize your strings, I am not covering that. The idea is very simple but requires you to add some java code in Eclipse 1) in src/<your app name>appDelegate.java, find the line public static String configurationFileName = "BT_config.txt"; (should be around 86) This is where we tell the app to use this particular filename as the config file with all your screen content. 2) Comment out this line, and paste the following: static String loc = Locale.getDefault().getLanguage(); static String currentBTconfig = loc+"BT_config.txt"; public static String configurationFileName = currentBTconfig; What we have done here is to detect the default language of the device, (en for english, fr for french, es for spanish etc). Then we add these 2 letters at the beginning of the filename so that the app will use: "enBT_config.txt" for a device in English "frBT_config.txt" for a device in Franch "esBT_config.txt" for a device in Spanish etc. 3) In the folder "assets", add a corresponding <language code>BT_Config.txt file for each language you target. Obviously you need to localize and translate the content of each file. 4) I'd suggest to think in terms of language rather than territory, unless your app is heavily about text nuances. For most of the apps of the app, nobody cares if it is British English or American English, Quebec French or French French etc Well at least I don't :) That's it, without having to download several versions of the same app, or choosing a language within the app, your users will have your app in their language with no friction :) Hope this helps and hope this doesn't crash :)
 
theGreek
Aspiring developer
Profile
Posts: 648
Reg: May 25, 2011
Schaumburg, IL
7,830
like
10/22/12 02:06 PM (13 years ago)
Great job.... Will be very useful for many people..... Now people can go global ....
 
MadRod
Aspiring developer
Profile
Posts: 1853
Reg: Apr 12, 2012
Lisbon
27,930
like
10/22/12 02:27 PM (13 years ago)
Great post. I just need it for IOS. Thanks for posting. Miguel
 
MacApple
Apple Fan
Profile
Posts: 4675
Reg: Oct 25, 2010
USA
61,150
like
10/22/12 03:07 PM (13 years ago)
Nicely done, great info.
 
Sandeep
Android Fan
Profile
Posts: 1260
Reg: Feb 01, 2012
Miraj, India
25,250
like
10/22/12 07:45 PM (13 years ago)
This post is really very informative. Thanks for sharing it with us.
 
Don
Aspiring developer
Profile
Posts: 40
Reg: Aug 10, 2012
moving within e...
2,550
like
10/23/12 05:46 AM (13 years ago)
Thanks guys! I am now trying to improve this code to avoid bad surprises. Inedde, if somebody has a language setting I don't have a BT_config.txt file for (for example "ru"), the app won't load because it won't find a ruBT_config.txt Hence the importance to always keep a default config file for this kind of cases. I am trying to code the following (only testing with 2 languages, but obviously the list can go on) static String loc = Locale.getDefault().getLanguage(); private static String currentBTconfig; { if (loc == "en"||loc == "fr") //it means the user's device is in one language i can provide a config file for { currentBTconfig = loc+"BT_config.txt"; } else { // my default file currentBTconfig = "enBT_config.txt"; } } public static String configurationFileName = currentBTconfig; Unfortunately, that doesn't work at all! When I load the app, it doesn't open because it doesn't find the config file. I do have these 2 files in my assets folder: enBT_config.txt frBT_config.txt Damn it sucks not to be able to make a simple "if else" work :( Anybody see why this doesn't work? Thanks
 
Don
Aspiring developer
Profile
Posts: 40
Reg: Aug 10, 2012
moving within e...
2,550
like
10/23/12 07:12 AM (13 years ago)
Nevermind, just found it, you can't add logic code if it's not in a method. So now I'm using: public static String testLoc() { String loc = Locale.getDefault().getLanguage(); String currentBTconfig; currentBTconfig = "enBT_config.txt"; if (loc.contains("en")||loc.contains("fr")) { currentBTconfig = loc+"BT_config.txt"; } return currentBTconfig; } public static String configurationFileName = testLoc(); Hope this helps
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
04/12/13 03:49 AM (12 years ago)
Wow, never new this post existed. Comes right on time! I'll ask Susan to add it to the localization project! Thanks @Don.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.