How to get Chinese locale to display in chinese as specifically simplified or traditional
Asked Answered
P

1

9

I'm generating a list of locales and printing out their local display languages (i.e. printing out ja_JP as 日本語) using java.util.Locale. I noticed that both zh_CN (chinese simplified) and zh_TW (chinese traditional) localize as 中文 rather than 简体中文 and 繁体中文. Is there a way to get these locales to include the prefix characters for simplified and traditional without hard-coding that zh_CN should be 简体中文 and zh_TW should be 繁体中文? I know I could print out language + country (i.e. 中文 (中国), but that's not quite the same.

Here's a java snippet demonstrating that they're the same:

import java.util.Locale;

public final class test {
  public static void main(String[] args) {
    Locale locale1 = new Locale("zh", "cn");
    System.out.println( locale1.getDisplayLanguage(locale1));
    System.out.println( locale1.getDisplayLanguage(Locale.TRADITIONAL_CHINESE));
    System.out.println( locale1.getDisplayLanguage(Locale.SIMPLIFIED_CHINESE));
    System.out.println( locale1.getDisplayCountry(locale1));

    System.out.println( "");

    Locale locale2 = new Locale("zh", "tw");
    System.out.println( locale2.getDisplayLanguage(locale2));
    System.out.println( locale2.getDisplayLanguage(Locale.TRADITIONAL_CHINESE));
    System.out.println( locale2.getDisplayLanguage(Locale.SIMPLIFIED_CHINESE));
    System.out.println( locale2.getDisplayCountry(locale2));
  }
}
Pestalozzi answered 2/12, 2014 at 20:13 Comment(0)
P
1

Instantiating the Locale Objects in the following way should resolve your issue:

Locale locale1 = new Locale("zh", "CN");

Locale locale2 = new Locale("zh", "TW");
Pera answered 7/4, 2017 at 9:57 Comment(1)
They don't appear case sensitive, at least not with Java 8.Marche

© 2022 - 2024 — McMap. All rights reserved.