Fix for Issue #2052 (Languages independent options appears twice when activated)

git-svn-id: https://svn.libreccm.org/ccm/trunk@2622 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2014-04-25 07:05:11 +00:00
parent 0faee19986
commit 12391d31f1
1 changed files with 43 additions and 34 deletions

View File

@ -42,14 +42,18 @@ import java.util.StringTokenizer;
*/ */
public class LanguageUtil { public class LanguageUtil {
private static org.apache.log4j.Logger s_log = private static org.apache.log4j.Logger s_log = org.apache.log4j.Logger.getLogger(
org.apache.log4j.Logger.getLogger(LanguageUtil.class); LanguageUtil.class);
private static String s_languages = null; private static String s_languages = null;
private static String[] s_languagesArray = null; private static String[] s_languagesArray = null;
/** Mapping from the ISO639-1 2-letter codes to the ISO639-2 3-letter codes */ /**
* Mapping from the ISO639-1 2-letter codes to the ISO639-2 3-letter codes
*/
private static final String ISO639_2LA_3LA = "com.arsdigita.cms.util.iso639rev"; private static final String ISO639_2LA_3LA = "com.arsdigita.cms.util.iso639rev";
private static ResourceBundle s_lang3LA = ResourceBundle.getBundle(ISO639_2LA_3LA); private static ResourceBundle s_lang3LA = ResourceBundle.getBundle(ISO639_2LA_3LA);
/** Mapping from the ISO639-1 2-letter codes to the full descriptive name */ /**
* Mapping from the ISO639-1 2-letter codes to the full descriptive name
*/
private static final String ISO639_2LA_FULL = "com.arsdigita.cms.util.iso639full"; private static final String ISO639_2LA_FULL = "com.arsdigita.cms.util.iso639full";
private static ResourceBundle s_langFull = ResourceBundle.getBundle(ISO639_2LA_FULL); private static ResourceBundle s_langFull = ResourceBundle.getBundle(ISO639_2LA_FULL);
@ -60,24 +64,23 @@ public class LanguageUtil {
/** /**
* Sets the supported languages, eliminates all spaces and trims * Sets the supported languages, eliminates all spaces and trims
* *
* @param comma separated list of langages initialized from initializer * @param comma separated list of langages initialized from initializer at the server startup
* at the server startup
*/ */
public static void setSupportedLanguages(String languages) { public static void setSupportedLanguages(String languages) {
if (Kernel.getConfig().languageIndependentItems() && languages.indexOf(GlobalizationHelper.LANG_INDEPENDENT) >= 0) {
s_languages = languages.replace(" ", "").trim() + "," + GlobalizationHelper.LANG_INDEPENDENT;
} else {
s_languages = languages.replace(" ", "").trim(); s_languages = languages.replace(" ", "").trim();
} }
}
/** Get the comma separated list of all supported languages */ /**
* Get the comma separated list of all supported languages
*/
public static String getSupportedLanguages() { public static String getSupportedLanguages() {
Assert.exists(s_languages, "supported languages not set"); Assert.exists(s_languages, "supported languages not set");
return s_languages; return s_languages;
} }
/** Returns the collection of all supported languages. /**
* Returns the collection of all supported languages.
*
* @return all supported languages * @return all supported languages
*/ */
public static Collection getSupportedLanguages2LA() { public static Collection getSupportedLanguages2LA() {
@ -91,8 +94,10 @@ public class LanguageUtil {
return langList; return langList;
} }
/** Returns the collection of all supported languages. /**
* Each entry is a pair of 2 letter code as key and three letter code as value. * Returns the collection of all supported languages. Each entry is a pair of 2 letter code as
* key and three letter code as value.
*
* @return all supported languages * @return all supported languages
*/ */
public static Collection getSupportedLanguages3LA() { public static Collection getSupportedLanguages3LA() {
@ -106,8 +111,10 @@ public class LanguageUtil {
return langList; return langList;
} }
/** Returns the collection of all supported languages. /**
* Each entry is a pair of 2 letter code as key and full language name as a value. * Returns the collection of all supported languages. Each entry is a pair of 2 letter code as
* key and full language name as a value.
*
* @return all supported languages * @return all supported languages
*/ */
public static Collection getSupportedLanguagesFull() { public static Collection getSupportedLanguagesFull() {
@ -122,9 +129,8 @@ public class LanguageUtil {
} }
/** /**
* Get the List of languages in which this item can be created. * Get the List of languages in which this item can be created. Usefull on UI where we need to
* Usefull on UI where we need to display the list of languages in which this Item can * display the list of languages in which this Item can be created.
* be created.
*/ */
public static Collection getCreatableLanguages(ContentPage item) { public static Collection getCreatableLanguages(ContentPage item) {
ContentBundle bundle = item.getContentBundle(); ContentBundle bundle = item.getContentBundle();
@ -134,11 +140,10 @@ public class LanguageUtil {
} }
/** /**
* Returns three letter acronym for language code * Returns three letter acronym for language code mapped from two letter code.
* mapped from two letter code.
* *
* @return three letter code for the two letter code. * @return three letter code for the two letter code. If the resource is not found then the key
* If the resource is not found then the key itself is returned. * itself is returned.
*/ */
public static String getLang3LA(String lang) { public static String getLang3LA(String lang) {
String threeLA; String threeLA;
@ -163,12 +168,14 @@ public class LanguageUtil {
* Returns the full language name mapped from the two letter acronym. * Returns the full language name mapped from the two letter acronym.
* *
* @param lang 2 letter language code * @param lang 2 letter language code
* @return full language name for the given two letter code *
* If the resource is not found then the key itself is returned. * @return full language name for the given two letter code If the resource is not found then
* the key itself is returned.
*/ */
public static String getLangFull(String lang) { public static String getLangFull(String lang) {
// Lookup language name via java.util.Locale // Lookup language name via java.util.Locale
String fullName = (new Locale(lang)).getDisplayLanguage(GlobalizationHelper.getNegotiatedLocale()); String fullName = (new Locale(lang)).getDisplayLanguage(GlobalizationHelper.
getNegotiatedLocale());
if (lang.equals(fullName)) { if (lang.equals(fullName)) {
// If that fails // If that fails
@ -184,8 +191,9 @@ public class LanguageUtil {
return fullName; return fullName;
} }
/** Takes in a list of 2 letter codes and converts into 3 letter codes. /**
* Each entry is pair of 2 letter code as key and 3 letter code as value. * Takes in a list of 2 letter codes and converts into 3 letter codes. Each entry is pair of 2
* letter code as key and 3 letter code as value.
*/ */
public static Collection convertTo3LA(Collection list) { public static Collection convertTo3LA(Collection list) {
Collection conList = new LinkedList(); Collection conList = new LinkedList();
@ -225,5 +233,6 @@ public class LanguageUtil {
public Object localize(Locale locale) { public Object localize(Locale locale) {
return LanguageUtil.getLangFull(this.getKey()); return LanguageUtil.getLangFull(this.getKey());
} }
} }
} }