|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.olat.core.logging.LogDelegator
org.olat.core.manager.BasicManager
org.olat.core.util.i18n.I18nManager
public class I18nManager
Description:
I18nManager is responsible for internationalization issues, to store and load
properties files in the available languages. see olat_config.xml for the
languages offered. Log in as olat Administrator -> go to "test" tab, choose
Language translation tool to have a web based translation tool available
Initial Date: 10.11.2004
| Field Summary | |
|---|---|
static int |
DEFAULT_BUNDLE_PRIORITY
|
static int |
DEFAULT_KEY_PRIORITY
|
static java.lang.String |
FILE_NOT_FOUND_ERROR_PREFIX
|
static java.lang.String |
I18N_DIRNAME
|
static java.lang.String |
IDENT_END_POSTFIX
|
static java.lang.String |
IDENT_PREFIX
|
static java.lang.String |
IDENT_START_POSTFIX
|
static java.io.FilenameFilter |
jarFileFilter
|
static java.lang.String |
METADATA_ANNOTATION_POSTFIX
|
static java.lang.String |
METADATA_BUNDLE_PRIORITY_KEY
|
static java.lang.String |
METADATA_KEY_PRIORITY_POSTFIX
|
static java.lang.String |
USESS_KEY_I18N_MARK_LOCALIZED_STRINGS
|
| Method Summary | |
|---|---|
static void |
attachI18nInfoToThread(javax.servlet.http.HttpServletRequest hreq)
Attache some data to thread local variables needed by the i18nManager. |
java.lang.String |
buildI18nFilename(java.util.Locale locale)
Helper method to build i18n filenames from a given locale. |
java.lang.String |
buildI18nItemIdentifyer(java.lang.String bundleName,
java.lang.String key)
Helper method to build a unique identifyer for an i18n item from the given bundle name and key |
void |
copyLanguagesFromJar(java.io.File jarFile,
java.util.Set<java.lang.String> toCopyI18nKeys)
Copy the given set of languages from the given jar to the configured i18n source directories. |
int |
countBundles(java.lang.String limitToBundleName,
boolean includeBundlesChildren)
Count the number of available bundles |
int |
countI18nItems(java.util.Locale locale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
Count the i18n items in a bundle |
java.lang.String[] |
createLanguageFlagsCssClasses(java.lang.String[] languageKeys,
java.lang.String additionalCssClass)
Create a string array that contains the css markup for country flags |
java.io.File |
createLanguageJarFile(java.util.Set<java.lang.String> languageKeys,
java.lang.String fileName)
Create a jar file that contains the translations for the given languages. |
boolean |
createNewLanguage(java.lang.String localeKey,
java.lang.String languageInEnglish,
java.lang.String languageTranslated,
java.lang.String authors)
|
java.lang.String |
createOrigianlLocaleKeyForOverlay(java.util.Locale overlay)
Calculate the language key from the given overlay locale without the locale (the original language before adding the overlay postfix) |
void |
deleteLanguage(java.lang.String deleteLangKey,
boolean reallyDeleteIt)
Method to delete an entire language. |
void |
deleteProperties(java.util.Locale locale,
java.lang.String bundleName)
Delete the given property file from disk |
java.util.List<I18nItem> |
findExistingAndMissingI18nItems(java.util.Locale referenceLocale,
java.util.Locale targetLocale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
Find all i18n items that exist in the source locale and the target locale |
java.util.List<I18nItem> |
findExistingI18nItems(java.util.Locale targetLocale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
Find all i18n items that exist in the target locale |
java.util.List<I18nItem> |
findI18nItemsByKeySearch(java.lang.String searchString,
java.util.Locale searchLocale,
java.util.Locale targetLocale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
Find all i18n items that contain the given search string in their key. |
java.util.List<I18nItem> |
findI18nItemsByValueSearch(java.lang.String searchString,
java.util.Locale searchLocale,
java.util.Locale targetLocale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
Find all i18n items that contain a given search string in their value. |
java.util.List<I18nItem> |
findMissingI18nItems(java.util.Locale referenceLocale,
java.util.Locale targetLocale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
Find all i18n items that exist in the source locale but not in the target locale |
java.lang.String |
getAnnotation(I18nItem i18nItem)
Get the annotation for this i18n item. |
java.util.Locale |
getCurrentThreadLocale()
Get the locale used in the current thread or the default locale if no locale is set. |
java.util.Map<java.lang.String,java.lang.String> |
getEnabledLanguagesTranslated()
Get a map of the enabled language keys as keys with their translated name as values. |
I18nItem |
getI18nItem(java.lang.String bundleName,
java.lang.String key,
java.util.Locale locale)
Factory method to create a single i18n item |
static I18nManager |
getInstance()
|
java.lang.String |
getJSTranslatorData(java.util.Locale locale,
java.lang.String bundleName)
Get the javascript translator data for this locale. |
java.lang.String |
getLanguageAuthor(java.lang.String languageKey)
Get the authors of the language as they entered themselfes in the translation tool. |
java.lang.String |
getLanguageInEnglish(java.lang.String languageKey,
boolean overlayEnabled)
Translate the given language key to english (for administrative interface). |
java.lang.String |
getLanguageTranslated(java.lang.String languageKey,
boolean overlayEnabled)
Translate the given language key to the language itself. |
java.lang.Long |
getLastModifiedDate(java.util.Locale locale,
java.lang.String bundleName)
Get the last modified date of this bundle and locale |
java.lang.String |
getLocaleKey(java.util.Locale locale)
Calculate the locale key that identifies the given locale. |
java.util.Locale |
getLocaleOrDefault(java.lang.String localeKey)
|
java.util.Locale |
getLocaleOrNull(java.lang.String localeKey)
|
java.lang.String |
getLocalizedString(I18nItem i18nItem,
java.lang.Object[] args)
Get the translated value for a given i18n item. |
java.lang.String |
getLocalizedString(java.lang.String bundleName,
java.lang.String key,
java.lang.Object[] args,
java.util.Locale locale,
boolean overlayEnabled,
boolean fallBackToDefaultLocale)
Get a localized string. |
java.lang.String |
getLocalizedString(java.lang.String bundleName,
java.lang.String key,
java.lang.Object[] args,
java.util.Locale locale,
boolean overlayEnabled,
boolean fallBackToDefaultLocale,
boolean fallBackToFallbackLocale,
boolean resolveRecursively,
int recursionLevel)
|
java.io.File |
getPropertiesFile(java.util.Locale locale,
java.lang.String bundleName,
java.io.File sourceDir)
Get the property file for a given locale and bundle. |
java.util.Properties |
getPropertiesWithoutResolvingRecursively(java.util.Locale locale,
java.lang.String bundleName)
|
java.util.Properties |
getResolvedProperties(java.util.Locale locale,
java.lang.String bundleName)
|
boolean |
isCachingEnabled()
|
boolean |
isCurrentThreadMarkLocalizedStringsEnabled()
Check if this thread should be rendered using markup arround the localized strings |
static void |
remove18nInfoFromThread()
Remove any thread local data that was set using the attachI18nInfoToThread() method |
java.util.Set<java.lang.String> |
sarchForAvailableLanguagesInJarFile(java.io.File jarFile,
boolean checkForExecutables)
Searches within a jar file for available languages. |
void |
saveOrUpdateI18nItem(I18nItem i18nItem,
java.lang.String value)
Save the given value for the given i18nItem |
void |
saveOrUpdateProperties(java.util.Properties properties,
java.util.Locale locale,
java.lang.String bundleName)
Create a new property file or update an existing property file form the given propeties object |
void |
setAnnotation(I18nItem i18nItem,
java.lang.String annotation)
|
void |
setBundlePriority(java.lang.String bundleName,
int priority)
Set the bundle priority for a specific bundle. |
void |
setCachingEnabled(boolean useCache)
Method to enable / disable caching of loaded and resolved bundles |
void |
setKeyPriority(java.lang.String bundleName,
java.lang.String key,
int priority)
Set the key priority within the bundle. |
void |
setMarkLocalizedStringsEnabled(UserSession usess,
boolean isMarkLocalizedStringsEnabled)
Set the |
void |
sortBundles(java.util.List<java.lang.String> bundleNames,
boolean afterBundlePriorities)
Sort the bundle names alphabetically or by using the bundle priorities. |
void |
sortI18nItems(java.util.List<I18nItem> i18nItems,
boolean afterBundlePriorities,
boolean afterKeyPriorities)
Sort a list of i18n items. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String FILE_NOT_FOUND_ERROR_PREFIX
public static final java.lang.String USESS_KEY_I18N_MARK_LOCALIZED_STRINGS
public static final java.lang.String IDENT_END_POSTFIX
public static final java.lang.String IDENT_START_POSTFIX
public static final java.lang.String IDENT_PREFIX
public static final java.lang.String METADATA_ANNOTATION_POSTFIX
public static final java.lang.String METADATA_BUNDLE_PRIORITY_KEY
public static final java.lang.String METADATA_KEY_PRIORITY_POSTFIX
public static final java.lang.String I18N_DIRNAME
public static final int DEFAULT_BUNDLE_PRIORITY
public static final int DEFAULT_KEY_PRIORITY
public static java.io.FilenameFilter jarFileFilter
| Method Detail |
|---|
public static I18nManager getInstance()
public java.lang.String getLocalizedString(I18nItem i18nItem,
java.lang.Object[] args)
i18nItem - args - the arguments used in this item or NULL if no such arguments
needed
public java.lang.String getLocalizedString(java.lang.String bundleName,
java.lang.String key,
java.lang.Object[] args,
java.util.Locale locale,
boolean overlayEnabled,
boolean fallBackToDefaultLocale)
bundlePath - The bundle pathkey - The key too lookupargs - The arguments used while formatting or NULL if no argumentslocale - The locale to useoverlayEnabled - true: lookup first in overlay; false: don't lookup in overlayfallBackToDefaultLocale - true: fallback to default enabled; false: no
fallback
public java.lang.String getLocalizedString(java.lang.String bundleName,
java.lang.String key,
java.lang.Object[] args,
java.util.Locale locale,
boolean overlayEnabled,
boolean fallBackToDefaultLocale,
boolean fallBackToFallbackLocale,
boolean resolveRecursively,
int recursionLevel)
public java.lang.String getAnnotation(I18nItem i18nItem)
i18nItem -
public void setAnnotation(I18nItem i18nItem,
java.lang.String annotation)
public java.util.List<I18nItem> findExistingI18nItems(java.util.Locale targetLocale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
targetLocale - The locale that must be translatedlimitToBundleName - includeBundlesChildren - true: also find the keys in the bundles
children; false: find only the keys in the exact bundle name. When
limitToBundeName is set to NULL the includeBundlesChildren will
always be set to true
public java.util.List<I18nItem> findMissingI18nItems(java.util.Locale referenceLocale,
java.util.Locale targetLocale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
referenceLocale - The locale that serves as the prototypetargetLocale - The locale that must be translatedlimitToBundleName - includeBundlesChildren - true: also find the keys in the bundles
children; false: find only the keys in the exact bundle name. When
limitToBundeName is set to NULL the includeBundlesChildren will
always be set to true
public java.util.List<I18nItem> findExistingAndMissingI18nItems(java.util.Locale referenceLocale,
java.util.Locale targetLocale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
referenceLocale - The locale that serves as the prototypetargetLocale - The locale that must be translatedlimitToBundleName - includeBundlesChildren - true: also find the keys in the bundles
children; false: find only the keys in the exact bundle name. When
limitToBundeName is set to NULL the includeBundlesChildren will
always be set to true
public java.util.List<I18nItem> findI18nItemsByValueSearch(java.lang.String searchString,
java.util.Locale searchLocale,
java.util.Locale targetLocale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
searchString - The search string, case-insensitive. * are treated as
wild-cardssearchLocale - The locale where to searchtargetLocale - The locale that should be used as result targetlimitToBundleName - The name of a bundle in which the keys should be
searched or NULL to search in all bundlesincludeBundlesChildren - true: also find the keys in the bundles
children; false: find only the keys in the exact bundle name. When
limitToBundeName is set to NULL the includeBundlesChildren will
always be set to true
public java.util.List<I18nItem> findI18nItemsByKeySearch(java.lang.String searchString,
java.util.Locale searchLocale,
java.util.Locale targetLocale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
searchString - The search string, case-insensitivesearchLocale - The language to search in fortargetLocale - The locale that should be used as result targetlimitToBundleName - The name of a bundle in which the keys should be
searched or NULL to search in all bundlesincludeBundlesChildren - true: also find the keys in the bundles
children; false: find only the keys in the exact bundle name. When
limitToBundeName is set to NULL the includeBundlesChildren will
always be set to true
public I18nItem getI18nItem(java.lang.String bundleName,
java.lang.String key,
java.util.Locale locale)
bundleName - key - locale -
public void sortI18nItems(java.util.List<I18nItem> i18nItems,
boolean afterBundlePriorities,
boolean afterKeyPriorities)
i18nItems - afterBundlePriorities - afterKeyPriorities -
public void sortBundles(java.util.List<java.lang.String> bundleNames,
boolean afterBundlePriorities)
bundleNames - afterBundlePriorities -
public void saveOrUpdateI18nItem(I18nItem i18nItem,
java.lang.String value)
i18nItem - value -
public int countI18nItems(java.util.Locale locale,
java.lang.String limitToBundleName,
boolean includeBundlesChildren)
locale - limitToBundleName - The name of a bundle for which the keys should be
counted or NULL to count keys in every available bundleincludeBundlesChildren - true: also count the keys of the bundles
children; false: count only the keys of the exact bundle name.
When limitToBundeName is set to NULL the includeBundlesChildren
will always be set to true
public int countBundles(java.lang.String limitToBundleName,
boolean includeBundlesChildren)
limitToBundleName - The name of a bundle or NULL to count every
available bundleincludeBundlesChildren - true: also count the bundles children; false:
count only the exact bundle name which will always be 1. When
limitToBundeName is set to NULL the includeBundlesChildren will
always be set to true
public java.util.Properties getPropertiesWithoutResolvingRecursively(java.util.Locale locale,
java.lang.String bundleName)
locale - bundleName -
public java.util.Properties getResolvedProperties(java.util.Locale locale,
java.lang.String bundleName)
public void saveOrUpdateProperties(java.util.Properties properties,
java.util.Locale locale,
java.lang.String bundleName)
properties - The properties to persislocale - The locale of the propertiesbundleName - The properties bundle
public void deleteProperties(java.util.Locale locale,
java.lang.String bundleName)
locale - bundleName -
public java.lang.String getJSTranslatorData(java.util.Locale locale,
java.lang.String bundleName)
;
<script type='text/javascript'>
var translator = b_jsTranslatorFactory.getTranslator('de', 'org.olat.core');
alert(translator.translate('warn.beta.feature'));
</script>
locale - bundleName -
public java.lang.Long getLastModifiedDate(java.util.Locale locale,
java.lang.String bundleName)
locale - bundleName -
public java.util.Locale getLocaleOrDefault(java.lang.String localeKey)
localeKey - the locale in String form. For the moment we only accept
locales with either a language ("de"), a language and a country
("de_CH"), or a language and a country and a variant
("de_CH_bern").
Overlay locales are not not accepted
If localeKey is null, the default locale is used.
public java.util.Locale getLocaleOrNull(java.lang.String localeKey)
localeKey - the locale in String form. For the moment we only accept
locales with either a language ("de"), a language and a country
("de_CH"), or a language and a country and a variant
("de_CH_bern").
In addition, all overlay locales are also accepted
If localeKey is null, null is returned
public java.lang.String getLanguageTranslated(java.lang.String languageKey,
boolean overlayEnabled)
languageKey -
public java.util.Map<java.lang.String,java.lang.String> getEnabledLanguagesTranslated()
public java.lang.String getLanguageInEnglish(java.lang.String languageKey,
boolean overlayEnabled)
languageKey -
public java.lang.String getLanguageAuthor(java.lang.String languageKey)
languageKey -
public java.lang.String[] createLanguageFlagsCssClasses(java.lang.String[] languageKeys,
java.lang.String additionalCssClass)
languageKeys - The source array of language keysadditionalCssClass - additional CSS classes that should be added or
NULL. E.g. you could use 'b_with_small_icon_left'
public static void attachI18nInfoToThread(javax.servlet.http.HttpServletRequest hreq)
hreq - The http servlet requestpublic static void remove18nInfoFromThread()
public java.util.Locale getCurrentThreadLocale()
public void setMarkLocalizedStringsEnabled(UserSession usess,
boolean isMarkLocalizedStringsEnabled)
usess - isMarkLocalizedStringsEnabled - public boolean isCurrentThreadMarkLocalizedStringsEnabled()
public void setBundlePriority(java.lang.String bundleName,
int priority)
Use priorities as follows:
bundleName - priority -
public void setKeyPriority(java.lang.String bundleName,
java.lang.String key,
int priority)
Priorities should be between 000 (hight prio, begin of list) and 999 (low prio, end of list)
If no priority is used, the standard priority of 500 is used
bundleName - key - priority - public void setCachingEnabled(boolean useCache)
useCache - public boolean isCachingEnabled()
public java.lang.String buildI18nFilename(java.util.Locale locale)
This method will check if the locale is an overlay locale and remove unnecessary white space
locale -
public java.lang.String getLocaleKey(java.util.Locale locale)
locale -
public java.lang.String createOrigianlLocaleKeyForOverlay(java.util.Locale overlay)
overlay -
public java.lang.String buildI18nItemIdentifyer(java.lang.String bundleName,
java.lang.String key)
bundleName - key -
public java.util.Set<java.lang.String> sarchForAvailableLanguagesInJarFile(java.io.File jarFile,
boolean checkForExecutables)
jarFile - checkForExecutables - true: check if jar contains java or class files
and return an empty set if such executable files are found; false
don't check or care
public void copyLanguagesFromJar(java.io.File jarFile,
java.util.Set<java.lang.String> toCopyI18nKeys)
jarFile - toCopyI18nKeys -
public java.io.File getPropertiesFile(java.util.Locale locale,
java.lang.String bundleName,
java.io.File sourceDir)
locale - the locale or NULL to get the bundle metadata filebundleName - sourceDir - the source directory where to search for the properties
file
public boolean createNewLanguage(java.lang.String localeKey,
java.lang.String languageInEnglish,
java.lang.String languageTranslated,
java.lang.String authors)
public void deleteLanguage(java.lang.String deleteLangKey,
boolean reallyDeleteIt)
deleteLangKey - true: - really delete the language; false: dry run with console
logging
public java.io.File createLanguageJarFile(java.util.Set<java.lang.String> languageKeys,
java.lang.String fileName)
Note that this file is created in a temporary place in olatdata/tmp. It is in the responsibility of the caller of this method to remove the file when not needed anymore.
languageKeys - fileName - the name of the file.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||