I am working on an android program that is in Turkish. When I am compiling, emulator cannot encode the Turkish letters.
For example, on the menu, "Liman Giriş Çıkış Bilgisi" should be written. However there are irrelevant characters in place of the "ş", "ç", "ı" letters :
I am working in Windows 7. There was no problem on Ubuntu.
What can be the problem and how could it be solved ?
Two solutions to change the language of the emulator:
Open Menu -> Settings -> Language & Keyboard -> Select Locale -> set any locale here
or programmatically as the following:
Locale locale = null;
Configuration config=null;
config = getBaseContext().getResources().getConfiguration();
locale = new Locale("tr");
Locale.setDefault(locale);
config.locale = locale;
Related
Is there a way to force using english as the locale for my android app even if the phone's locale is something other that english? The reason I want to do this is that I don't want my UI to change orientatoin from ltr to rtl.
this line
mStrLocale = Locale.getDefault().getLanguage();
will return your current language, lets say EN-US
and with this you can hardcode your locale
Locale locale = new Locale("ru");
Locale.setDefault(locale);
Configuration config = getBaseContext().getResources().getConfiguration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
and we use Configuration because of this
This class describes all device configuration information that can
impact the resources the application retrieves. This includes both
user-specified configuration options (locale list and scaling) as well
as device configurations (such as input modes, screen size and screen
orientation).
is stated at this doc https://developer.android.com/reference/android/content/res/Configuration.html
I have a localized string resource A. I noticed that after I clear app data/cache (under setting), and open my activity (which belongs to that app), I always see resource A in en locale regardless of the current device language. If I go to setting again, change device language manually to whatever, and go back to my activity, then resource A is localized properly again.
I wondering why locale is set to default after app data/cache is cleared and is there a way to fix this? Thanks.
This is a hacky solution but you could set the locale in the launcher activity like this:
Configuration config = res.getConfiguration();
Configuration configuration = new Configuration();
config.locale = config.locale;
getBaseContext().getResources().updateConfiguration(configuration,
getBaseContext().getResources().getDisplayMetrics());
You can also check the device locale to be absolutely sure that the device locale has changed.
I'm not sure what do do about this one. My app needs to have Loation support (Laos) - the locale is not in Android and not available in any locale packs. Although I did find a Laos Language Pack, but installing it didn't seem to change anything.
I am just trying to get a simple textview to display the correct text. When I use the Loation word like "ສະບາຍດີ", I get just boxes.
In the following - the setting of the locale works, and I have the strings.xml file in values-lo, values-en, etc. I tried this with chinese and english, and it seems to work fine for both languages - but this Laos thing is not cooperating.
Locale locale = new Locale("lo");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.editText);
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "TAW107.TTF");
textView.setTextSize(40);
textView.setTypeface(myTypeface);
textView.setText(getString(R.string.hello_world)); /this gives boxes for "ສະບາຍດີ"
I figured this one out. The Font set I was using did not have Laos character support. Even the font set was a "Laotion Font" set. Go figure. There are a few font families with broad support - like DejaVuSans. I used that one in the above code and it worked fine.
problem solved. - always check your fonts in things like font-manager and check the character map.
the above code works now including the localization
I've created a values-zh_CN directory in my res folder for Simplified Chinese localization. Eclipse does not accept that folder name, it marks it as an error, the directory itself.
The problem is definitely with the directory name, if I change the directory name to values-nl for example the error comes off.
The only name Eclipse accepts is values-zh-rCN which compiles fine but the actual locale is not loaded (Default en is loaded instead).
If you named dir for example values-zh it will be loaded only when Chinese is chosen in system language settings. You should know about that.
Value zh-rCN is correct and everything should work correctly. Read my notice above.
Use following code its working for me for traditional and simplified chinese.
if(selectedLanguage.equals("zh_CN"))
locale = Locale.SIMPLIFIED_CHINESE;
else if(selectedLanguage.equals("zh_TW"))
locale = Locale.TRADITIONAL_CHINESE;
else
locale = new Locale(selectedLanguage);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
baseContext.getResources().updateConfiguration(config, baseContext.getResources().getDisplayMetrics());
The correct locales are zh-rCN and zh-rTW,so then whatever Android software your using isn't correctly setting locale values.
Look into settings -> Language & Input to double check that Language is on Chinese, and if that fails look in the market for an application called MoreLocales2, it allows you to get around some of those stock Samsung softwares that prevent locale changing from working.
I want to convert my android project to multiple language. I have created a list view where different languages are going to be shown. I want to change the device language when I select any item from this list. How can I do this?
You can change the the Language like this
Locale locale = new Locale("en_US");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);