Package ch.autumo.beetroot
Class LanguageManager
java.lang.Object
ch.autumo.beetroot.LanguageManager
Language manager.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiongetBlockResource(String configResource, Session userSession) Get blocks resource / blocks template based on language.String[]Get configured languages.static LanguageManagerAccess language manager.getLanguage(Session userSession) Get language.getLanguageFromDb(Session userSession) Get language from DB.Get language from the header of the HTTP session and use it if available in beetRoot, otherwise return default language.getResource(String configResource, Session userSession) Get web config resource / template based on language.getResource(String configResource, String uri) Get web config resource / template based on language.getResourceByLang(String configResource, String lang) Get web config resource / template based on language code Used when user is not logged in.getResourceWithoutLang(String configResource) Get web config resource / template based on no language :) Used for general templates usually.static booleanIs the language manager initialized?booleanisLangConfigured(String lang) Checks if the given language is configured.Load translations for password checks.Get language from URI (e.g.removeLang(String uri) Remove language from URI.retrieveLanguage(BeetRootHTTPSession session) Retrieve language when user is not or possibly not logged in.translate(String key, BeetRootHTTPSession session, Object... arguments) Translate method.Translate method for the template engine and for users of this framework.Translate method for the template engine and for users of this framework.translateFullEscape(String key, BeetRootHTTPSession session, Object... arguments) Translate method for the template engine and for users of this framework.translateFullEscape(String key, Session userSession, Object... arguments) Translate method for the template engine and for users of this framework.translateOrDefVal(String key, String defaultValue, Session userSession, Object... arguments) Translate method for the template engine and for users of this framework that returns the default value if no translation is found at all.translateOrDefVal(String key, String defaultValue, String lang, Object... arguments) Translate method for the template engine and for users of this framework that returns the defaukt value if no translation is found at all.translateTemplate(String key, BeetRootHTTPSession session, String[] values, boolean escape) Translate method for the template engine.translateTemplate(String key, Session userSession) Translate method for the template engine.translateTemplate(String key, Session userSession, String[] values) Translate method for the template engine.translateTemplate(String key, Session userSession, String[] values, boolean escape) Translate method for the template engine.translateTemplate(String key, String lang, String[] values) Translate method for the template engine.translateTemplate(String key, String lang, String[] values, boolean escape) Translate method for the template engine.translateTemplateFullEscape(String key, BeetRootHTTPSession session, String[] values) Translate method for the template engine.translateTemplateFullEscape(String key, String lang, String[] values) Translate method for the template engine.voidupdateLanguage(String newLanguage, Session userSession) Update user language.
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
DEFAULT_LANG
- See Also:
-
LANG_GRP_APP
- See Also:
-
LANG_GRP_TMPL
- See Also:
-
LANG_GRP_PW
- See Also:
-
-
Method Details
-
isInitialized
public static boolean isInitialized()Is the language manager initialized?- Returns:
- true if so
-
getInstance
Access language manager.- Returns:
- DB manager
-
translateTemplate
Translate method for the template engine. Translations will be HTML escaped with the following characters "<>&\'". It is internally used only. Template language files are place in the directory: 'web/lang/tmpl'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourcesuserSession- the user session- Returns:
- translated text
-
translateTemplate
Translate method for the template engine. Translations will be HTML escaped with the following characters "<>&\'". It is internally used only. Template language files are place in the directory: 'web/lang/tmpl'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourcesuserSession- the user sessionvalues- place-holder values- Returns:
- translated text
-
translateTemplate
Translate method for the template engine. Translations will be HTML escaped with the following characters "<>&\'". It is internally used only. Template language files are place in the directory: 'web/lang/tmpl'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourceslang- languagevalues- placeholder values- Returns:
- translated text
-
translateTemplate
public String translateTemplate(String key, BeetRootHTTPSession session, String[] values, boolean escape) Translate method for the template engine. If escape is true, Translations will be HTML escaped with the following characters "<>&\'". It is internally used only. Template language files are place in the directory: 'web/lang/tmpl'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourcessession- HTTP session or null (default language is used)values- place-holder valuesescape- if true, basic HTML escaping is applied- Returns:
- translated text
-
translateTemplateFullEscape
Translate method for the template engine. If escape is true, Translations will be fully HTML. It is internally used only. Template language files are place in the directory: 'web/lang/tmpl'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourcessession- HTTP session or null (default language is used)values- place-holder values- Returns:
- translated text
-
translateTemplate
Translate method for the template engine. If escape is true, Translations will be HTML escaped with the following characters "<>&\'". It is internally used only. Template language files are place in the directory: 'web/lang/tmpl'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourcesuserSession- the user sessionvalues- place-holder valuesescape- if true, basic HTML escaping is applied- Returns:
- translated text
-
translateTemplate
Translate method for the template engine. If escape is true, Translations will be HTML escaped with the following characters "<>&\'". It is internally used only. Template language files are place in the directory: 'web/lang/tmpl'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourceslang- languagevalues- placeholder valuesescape- if true, basic HTML escaping is applied- Returns:
- translated text
-
translateTemplateFullEscape
Translate method for the template engine. If escape is true, Translations will be fully HTML escaped. It is internally used only. Template language files are place in the directory: 'web/lang/tmpl'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourceslang- languagevalues- placeholder values- Returns:
- translated text
-
translate
Translate method for the template engine and for users of this framework. General language files are place in the directory: 'web/lang/app'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourcesuserSession- the user sessionarguments- the arguments to replace in the text with variables- Returns:
- translated text
-
translateFullEscape
Translate method for the template engine and for users of this framework. It HTML escapes special characters and 'Umlaute' fully. Useful for mails. General language files are place in the directory: 'web/lang/app'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourcesuserSession- the user sessionarguments- the arguments to replace in the text with variables- Returns:
- translated text
-
translateFullEscape
Translate method for the template engine and for users of this framework. It HTML escapes special characters and 'Umlaute' fully. General language files are place in the directory: 'web/lang/app'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourcessession- HTTP session or null (default language is used)arguments- the arguments to replace in the text with variables- Returns:
- translated text
-
translate
Translate method. It doesn't HTML escapes anything. Useful for mail. General language files are place in the directory: 'web/lang/app'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourcessession- HTTP session or null (default language is used)arguments- the arguments to replace in the text with variables- Returns:
- translated text
-
translate
Translate method for the template engine and for users of this framework. General language files are place in the directory: 'web/lang/app'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourceslang- language codearguments- the arguments to replace in the text with variables- Returns:
- translated text
-
translateOrDefVal
public String translateOrDefVal(String key, String defaultValue, Session userSession, Object... arguments) Translate method for the template engine and for users of this framework that returns the default value if no translation is found at all. Should only be used for special cases. General language files are place in the directory: 'web/lang/app'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourcesdefaultValue- default valueuserSession- the user sessionarguments- the arguments to replace in the text with variables- Returns:
- translated text
-
translateOrDefVal
Translate method for the template engine and for users of this framework that returns the defaukt value if no translation is found at all. Should only be used for special cases. General language files are place in the directory: 'web/lang/app'; e.g. 'lang_en.properties'.- Parameters:
key- key associated to text in translation resourcesdefaultValue- default valuelang- language codearguments- the arguments to replace in the text with variables- Returns:
- translated text
-
isLangConfigured
Checks if the given language is configured.- Parameters:
lang- language code- Returns:
- true if so
-
removeLang
Remove language from URI.- Parameters:
uri- URI- Returns:
- laguage code
-
parseLang
Get language from URI (e.g. 'en', 'de').- Parameters:
uri- URI- Returns:
- language code as configured
-
getResource
Get web config resource / template based on language. Used when user is not logged in.- Parameters:
configResource- language template/resourceuri- URI- Returns:
- web resource
-
getResourceByLang
Get web config resource / template based on language code Used when user is not logged in.- Parameters:
configResource- language template/resourcelang- language code- Returns:
- web resource
-
getResourceWithoutLang
Get web config resource / template based on no language :) Used for general templates usually.- Parameters:
configResource- language template/resource- Returns:
- web resource
-
getResource
Get web config resource / template based on language. Used when user is logged in.- Parameters:
configResource- language template/resourceuserSession- user session- Returns:
- web resource
-
getBlockResource
Get blocks resource / blocks template based on language. Blocks are the different basic sections of the HTML page. Return block template based on language, and if not existing try to get a general block from the 'web/html/blocks' directory instead 'web/html/<lang>/blocks' Used when user is logged in.- Parameters:
configResource- language template/resourceuserSession- user session- Returns:
- web resource
-
getConfiguredLanguages
Get configured languages.- Returns:
- languages codes
-
retrieveLanguage
Retrieve language when user is not or possibly not logged in.- Parameters:
session- HTTP session or null (default language is used)- Returns:
- found language
-
getLanguageFromHttpSession
Get language from the header of the HTTP session and use it if available in beetRoot, otherwise return default language.- Parameters:
session- beetRoot HTTP session- Returns:
- found language
-
getLanguage
Get language. First from session, then DB, then use default language if not found earlier.- Parameters:
userSession- user session- Returns:
- language code
-
getLanguageFromDb
Get language from DB. First from DB, then use default language if not found earlier.- Parameters:
userSession- user session- Returns:
- language code
-
updateLanguage
Update user language.- Parameters:
newLanguage- new language codeuserSession- user session
-
loadPWValidationMessages
Load translations for password checks.- Parameters:
session- HTTP session- Returns:
- properties with validation messages
-