NL (Dutch) locale in Swing does not seem to work - java

I have a java application with multi-language support. When I change the language (in a preferences dialog), the language of the entire application changes, including the language of Swing components like JFileChooser. That is working perfect for English, Spanish and French. But when I choose Dutch, the language of Swing components (JFileChooser, confirm dialogs, etc.) changes to English.
Below is the code that changes the language to Dutch. Remark: for the other languages I use the same code (except for the "NL" string, of course) and it works fine.
Locale locale = new Locale("nl");
Locale.setDefault(locale);
JComponent.setDefaultLocale(locale);
I also tried creating the locale using new Locale("nl", "BE"); and new Locale("nl", "NL"); but none of them worked. Is there a problem with the Dutch locale? Or am I doing something wrong here?

As stated here Dutch is not supported for User Interface Translations:
User Interface Translation
Java SE Runtime Environment
The user interface elements provided by the Java SE Runtime Environment 6, include Swing dialogs, messages written by the runtime environment to the standard output and standard error streams, as well as messages produced by the tools provided with the JRE. These user interface elements are localized into the following languages:
Language Locale ID
Chinese (Simplified) zh_CN
Chinese (Traditional) zh_TW
English en
French fr
German de
Italian it
Japanese ja
Korean ko
Portuguese (Brazilian) pt_BR
Spanish es
Swedish sv

Some years to late... But you can also create a wrapper class like this
public class DutchLocale {
static public final Locale NL = new Locale("nl", "NL");
}

Related

What locale does DecimalFormat and DateFormat use by default? (why is it different to Locale.getDefault()?)

When debugging my application, if found that DecimalFormat and DateFormat are set to use nl_NL by default, but the system locale seems to be en_US.
I found the first by evaluating:
new DecimalFormat().symbols.locale
new SimpleDateFormat().locale
And the second:
Locale.getDefault()
System.getProperty("user.country")
System.getProperty("user.language")
What is happening there?
How can I set those formatters to use a certain locale by default? (I'm writing unit tests and would like to set a specific locale without touching the application code)
As of Java 7, the default locale comes in two categories: "DISPLAY" and "FORMAT".
Both are initially set according to the environment. They can be found by calling Locale.getDefault(Category).
Besides the system properties mentioned in the question:
"user.country"
"user.language"
The following can also be present when running the JVM:
"user.country.format"
"user.language.format"
"user.country.display"
"user.language.display"
The reason for that seems to be that some OS's allow independent localization settings for displaying text and for formatting dates, numbers and currency.
Answering my last question, by calling Locale.setDefault(Locale) the default locale will be set for all categories.

Best way to automatically determinate user language

I'm developing a project where I need to automatically determinate which is the user language used to created the content.
We're actually using Locale.getDefault().getLanguage() but this can not be the right choice because, for istance, I live in Italy, I write content in Italian but my default Locale on my phone is en_US.
So I tought that maybe I could determinate it from the SIM Country (and fallback to user Locale when the device does not have one) but there's no one-to-one relation from a Country to a Language. For istance, US has en_US and es_US.
Do you have any suggestion? Should I ask the user for their current content's Locale?
What's the reason you need the user language?
I too have my locale set to en_US, and I have that because I prefer to have menus etc in English. (The translation of menus and settings etc feels strained in my native language.)
Chances are that your users will be annoyed (I know I would) if you use anything other than Locale.getDefault().getLanguage() for whatever you're using the language for.
That being said, if you really want to use a local language, I suggest you figure out the country code by some heuristics based on
Default locale
SIM country
Current network country
and use a hard coded lookup table from country code to (one of) the official language code(s). There are open databases with this information, see for example these resources:
List of language codes by country
Country codes / language codes on the OpenStreetMap wiki

Changing The Font Of A JTextArea When Language Changes

I am coding a simple java chat app. Is there any possibility of knowing the language user types in order to choose appropriate font?
Something like
Locale locale = InputContext.getLocale();
String language = locale.getLanguage();
But you must rely on the locale setting. I'm here on a German locale, but I'm happily typing English.

How To Set Default Language for Android app?

I've created an app in two languages. The second one (english), is used when user's default system language is english. If it's not, then the first one is used.
I want to set the second language (that's english) as a DEFAULT language,
which means that when user opens my app and his system language is not the first one, nor English, the English language will appear as a default one.
I tried:
Locale locale = new Locale("en_US");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext.getResources().updateConfiguration(config, null);
But got "context cannot be resolved" error everytime.. Is this piece of code right or..?
Okay,
to make everything clear,
I realized res/values is a DEFAULT directory and the others are just "in case of language". So everything I had to do was to switch the english to /res/values and the other language goes to res/values-es
You should define all languages you support using res folders, i.e res/values, res/values-en, res/values-fr. The system will take care of everything else, you don't need any code.
If you are in an activity you can do:
this.getApplicationContext().getResources().updateConfiguration(config, null);
...to fix your error.
Otherwise you need to pass in the context.
Make sure you add the parenthesis at the end of getApplicationContext(). You didn't do so in your code.
I've been in the same situation, my app was first created in portuguese (BR) so we went global and I had as second language En-Us, so my solution was creating a new language ( clicking in translation Editor + Brazil )... so I have my default language (Portuguese) second (English) third (Portuguese)
then I replaced the resource/ values to the english strings setting as default...

How to determine if the user prefers simplified or traditional Chinese characters

In an Android app, is there a standard way to determine whether a user prefers simplified or traditional Chinese characters?
I know next to nothing about Chinese, but I do know from Wikipedia that simplified Chinese is used in mainland China (locale zh_CN) and Singapore whereas traditional Chinese is used in Taiwan (locale zh_TW), Hong Kong, and Macau. Differentiating on the country code might be acceptable for the initial choice, but it would be problematic for someone in mainland China who prefers traditional characters, or someone in Hong Kong who prefers simplified characters. Is there a global setting for this preference?
If I must resort to an app-specific setting, is there an ad hoc standard way of sharing this information with other apps?
Just treat it as how you'd treat any other two languages. Don't rely on region. Just go with what the user has set in their default locale.
To check for the default locale:
Locale myPhoneLocale = Locale.getDefault();
If you want to translate your strings.xml file for both traditional and simplified, just make a values-zh-rCN folder and throw simplified in there, and another values-zh folder for traditional.
Most Chinese users are able to read both simplified and traditional. (Some might be annoyed at having to read the one they are less used to, but it's not the end of the world.) I personally only localize my apps to simplified Chinese, since mainland China has the most android users.

Categories

Resources