From a25b730c4d6679dae2a2a9b0489b70b0fc75d992 Mon Sep 17 00:00:00 2001 From: Marko Živković Date: Wed, 25 Feb 2015 22:56:55 +0000 Subject: Introduce Enum LogoLanguage to handle programming language and Gui language separately git-svn-id: https://svn.code.sf.net/p/xlogo4schools/svn/trunk@27 3b0d7934-f7ef-4143-9606-b51f2e2281fd --- logo/src/xlogo/storage/workspace/LogoLanguage.java | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 logo/src/xlogo/storage/workspace/LogoLanguage.java diff --git a/logo/src/xlogo/storage/workspace/LogoLanguage.java b/logo/src/xlogo/storage/workspace/LogoLanguage.java new file mode 100644 index 0000000..342aa52 --- /dev/null +++ b/logo/src/xlogo/storage/workspace/LogoLanguage.java @@ -0,0 +1,76 @@ +package xlogo.storage.workspace; + +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +public enum LogoLanguage { + LANGUAGE_FRENCH(0, "French", "fr", "FR"), + LANGUAGE_ENGLISH(1, "English", "en", "US"), + LANGUAGE_ARABIC(2, "Arabic", "ar", "MA"), + LANGUAGE_SPANISH(3, "Spanish", "es", "ES"), + LANGUAGE_PORTUGAL(4, "Portuguese", "pt", "BR"), + LANGUAGE_ESPERANTO(5, "Esperanto", "eo", "EO"), + LANGUAGE_GERMAN(6, "German", "de", "DE"), + LANGUAGE_GALICIAN(7, "Galician","gl", "ES"), + LANGUAGE_ASTURIAN(8, "Asturian", "al", "ES"), + LANGUAGE_GREEK(9, "Greek", "el", "GR"), + LANGUAGE_ITALIAN(10, "Italian", "it", "IT"), + LANGUAGE_CATALAN(11, "Catalan", "ca", "ES"), + LANGUAGE_HUNGARIAN(12,"Hungarian", "hu", "HU"); + + private int value; + private String englishName; + private String languageCode; + private String countryCode; + + private static Map valueToLanguage; + + private LogoLanguage(int value, String englishName, String languageCode, String countryCode) { + this.value = value; + this.englishName = englishName; + this.languageCode = languageCode; + this.countryCode = countryCode; + } + + public static LogoLanguage getLanguage(int i) { + if (valueToLanguage == null) + initMapping(); + return valueToLanguage.get(i); + } + + public static void initMapping() { + valueToLanguage = new HashMap(); + for (LogoLanguage lang : values()) { + valueToLanguage.put(lang.value, lang); + } + } + + public int getValue() { + return value; + } + + public String getEnglishName() { + return englishName; + } + + /** + * return English name + */ + @Override + public String toString() { + return getEnglishName(); + } + + public Locale getLocale() { + return new Locale(languageCode, countryCode); + } + + public String getLanguageCode() { + return languageCode; + } + + public String getCountryCode() { + return countryCode; + } +} -- cgit v1.2.3