/** * Replace any text in mlText having the same language (but any variant) as contentLocale * with updatedText keyed by the language of contentLocale. This ensures that the mlText * will have no more than one entry for the particular language. * * @param contentLocale Locale * @param updatedText String * @param mlText MLText */ private void replaceTextForLanguage(Locale contentLocale, String updatedText, MLText mlText) { String language = contentLocale.getLanguage(); // Remove all text entries having the same language as the chosen contentLocale // (e.g. if contentLocale is en_GB, then remove text for en, en_GB, en_US etc. Iterator<Locale> locales = mlText.getLocales().iterator(); while (locales.hasNext()) { Locale locale = locales.next(); if (locale.getLanguage().equals(language)) { locales.remove(); } } // Add the new value for the specific language mlText.addValue(new Locale(language), updatedText); } }
/** * Replace any text in mlText having the same language (but any variant) as contentLocale * with updatedText keyed by the language of contentLocale. This ensures that the mlText * will have no more than one entry for the particular language. * * @param contentLocale Locale * @param updatedText String * @param mlText MLText */ private void replaceTextForLanguage(Locale contentLocale, String updatedText, MLText mlText) { String language = contentLocale.getLanguage(); // Remove all text entries having the same language as the chosen contentLocale // (e.g. if contentLocale is en_GB, then remove text for en, en_GB, en_US etc. Iterator<Locale> locales = mlText.getLocales().iterator(); while (locales.hasNext()) { Locale locale = locales.next(); if (locale.getLanguage().equals(language)) { locales.remove(); } } // Add the new value for the specific language mlText.addValue(new Locale(language), updatedText); } }
private Serializable getClosestValue(MLText mlText) { Set<Locale> locales = mlText.getLocales(); Locale contentLocale = I18NUtil.getContentLocale(); Locale locale = I18NUtil.getNearestLocale(contentLocale, locales); if (locale != null) { return mlText.getValue(locale); } // If the content locale is too specific, try relaxing it to just language Locale contentLocaleLang = I18NUtil.getContentLocaleLang(); // We do not expect contentLocaleLang to be null if (contentLocaleLang != null) { locale = I18NUtil.getNearestLocale(contentLocaleLang, locales); if (locale != null) { return mlText.getValue(locale); } } else { logger.warn("contentLocaleLang is null in getClosestValue. This is not expected."); } // Just return the default translation return mlText.getDefaultValue(); }
private Serializable getClosestValue(MLText mlText) { Set<Locale> locales = mlText.getLocales(); Locale contentLocale = I18NUtil.getContentLocale(); Locale locale = I18NUtil.getNearestLocale(contentLocale, locales); if (locale != null) { return mlText.getValue(locale); } // If the content locale is too specific, try relaxing it to just language Locale contentLocaleLang = I18NUtil.getContentLocaleLang(); // We do not expect contentLocaleLang to be null if (contentLocaleLang != null) { locale = I18NUtil.getNearestLocale(contentLocaleLang, locales); if (locale != null) { return mlText.getValue(locale); } } else { logger.warn("contentLocaleLang is null in getClosestValue. This is not expected."); } // Just return the default translation return mlText.getDefaultValue(); }
Set<Locale> locales = mltext.getLocales(); for (Locale locale : locales)
Set<Locale> locales = mltext.getLocales(); for (Locale locale : locales)
Set<Locale> locales = valueMLT.getLocales(); for (Locale locale : locales)
Set<Locale> locales = valueMLT.getLocales(); for (Locale locale : locales)