Chinese locale values-zh_CN gives an error on Eclipse - android

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.

Related

device locale is set to en_us after clearing app data

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.

Android : unsupported language questions - Laos

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

How to include 2 variants of Serbian Language? with Latin letters and with Cyrillic letters

I have an android app and I want to translate to Serbian and I want both variants of the language: with Latin letters and with Cyrillic letters.
I tried this variants: value-sr-rRS-Latn , value-sr-Latn , value-sr-rRS-Cyrl , value-sr-Cyrl
but not of that is working.
I get this error: android-apt-compiler: [NAMEOFAPP] invalid resource directory name: [path]\res/value-sr-rRS-Latn
On Android documentation about res dirs and Locale I can't find this option.
Can I make 2 dirs with 2 variants of the language? And how?
Thank you
Since Android 7.0, Serbian with Latin script has officially been included. values-sr is still used for the Cyrillic script, and values-b+sr+Latn is used for the Latin script.
values-sr for Cyrillic
values-b+sr+Latn for Latin
I just tested Android localization and I found out that you can use any arbitrary region and it will work.
Add a folder to the project with name like values-sr-rZZ where ZZ is a fictitious region which never existed.
Then add the following code to the Application class, I got it from here and slightly changed:
public class MainApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Resources res = this.getResources();
Configuration conf = res.getConfiguration();
boolean isLatinAlphabet = PreferenceManager.getDefaultSharedPreferences(this)... // get a value from the application settings
if(conf.locale.getLanguage().equals("sr") && isLatinAlphabet) {
conf.locale = new Locale("sr", "ZZ");
res.updateConfiguration(conf, res.getDisplayMetrics());
}
}
}
In this code the locale will be changed only if the user has chosen the serbian language as the default (conf.locale.getLanguage().equals("sr")) and also checked some checkbox in the app preferences (isLatinAlphabet).
You can use a different condition and change it as you like.
Also such dynamic way of changing language can have bugs with menu items on older devices, but it isn't reproduced on newer devices.

Foreign Language support on Android Emulator

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;

Android localization question

I'm in the process of translating an app. Looking at this, I can see that a lot of countries have several codes for language.
I tried making a folder named values-nb, for Norwegian Bokmål. I changed the locale on my phones to Norway. This worked on my Sony Ericson Xperia 8, but not on the Samsung Galaxy Tab.
I then tried renaming the folder to values-no. It now works on the galaxy tab, but not on the xperia. I create both folders, and it works. But then I have to put the same file in each folder!
What if someone chose Norwegian Nynorsk, would I have to create yet another folder so that they don't default to English but get the Norwegian text? values-nn?
I guess my question is this:
How do I get this to work? Can I make all these folders and then make them reference the values-no? Please help :)
There's no way under the current search rules to just have a localization for a specific country and be able to search all languages. At least that's my understanding from reading the pages at http://developer.android.com/guide/topics/resources/localization.html You would need to create values-nn-rNO, values-nb-rNO, and values-no-rNO and have duplicate strings.xml entries.
I haven't tried this, but look into string aliases at http://developer.android.com/guide/topics/resources/providing-resources.html#AliasResources
I know this is an old one, but heres a trick to combine no, nb and nn as no:
Locale locale = getResources().getConfiguration().locale;
if (locale.getLanguage().equals("no") || locale.getLanguage().equals("nb") || locale.getLanguage().equals("nn")){
locale = new Locale("no","NO");
Configuration config = new Configuration();
config.locale = locale;
Resources res = getBaseContext().getResources();
res.updateConfiguration(config, res.getDisplayMetrics());
}
Not an answer for the original question, but a solution for a related issue and this is a likely destination if you search for a solution for that issue (it was for me).
In our project, we had our resource directories created but for some reason localized strings were ignored.
The issue was with Androids support for generating Pseudolocalized resources. In older versions of Android you did it with this magic in the build.gradle file:
android.applicationVariants.all { variant ->
// see http://blog.danlew.net/2014/04/16/android-localization-tips/
if (variant.buildType.isDebuggable()) {
variant.mergedFlavor.addResourceConfiguration("zz_ZZ")
}
}
This has changed in later versions of Android and if you use that then you will not get any localization. The new way is just:
buildTypes {
debug {
pseudoLocalesEnabled true
}
}

Categories

Resources