Class LanguageManager

java.lang.Object
ch.autumo.beetroot.LanguageManager

public class LanguageManager extends Object
Language manager.
  • Field Details

  • Method Details

    • isInitialized

      public static boolean isInitialized()
      Is the language manager initialized?
      Returns:
      true if so
    • getInstance

      public static LanguageManager getInstance()
      Access language manager.
      Returns:
      DB manager
    • translateTemplate

      public String translateTemplate(String key, Session userSession)
      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 resources
      userSession - the user session
      Returns:
      translated text
    • translateTemplate

      public String translateTemplate(String key, Session userSession, String[] values)
      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 resources
      userSession - the user session
      values - place-holder values
      Returns:
      translated text
    • translateTemplate

      public String translateTemplate(String key, String lang, String[] values)
      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 resources
      lang - language
      values - 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 resources
      session - HTTP session or null (default language is used)
      values - place-holder values
      escape - if true, basic HTML escaping is applied
      Returns:
      translated text
    • translateTemplateFullEscape

      public String translateTemplateFullEscape(String key, BeetRootHTTPSession session, String[] values)
      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 resources
      session - HTTP session or null (default language is used)
      values - place-holder values
      Returns:
      translated text
    • translateTemplate

      public String translateTemplate(String key, Session userSession, 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 resources
      userSession - the user session
      values - place-holder values
      escape - if true, basic HTML escaping is applied
      Returns:
      translated text
    • translateTemplate

      public String translateTemplate(String key, String lang, 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 resources
      lang - language
      values - placeholder values
      escape - if true, basic HTML escaping is applied
      Returns:
      translated text
    • translateTemplateFullEscape

      public String translateTemplateFullEscape(String key, String lang, String[] values)
      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 resources
      lang - language
      values - placeholder values
      Returns:
      translated text
    • translate

      public String translate(String key, Session userSession, Object... arguments)
      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 resources
      userSession - the user session
      arguments - the arguments to replace in the text with variables
      Returns:
      translated text
    • translateFullEscape

      public String translateFullEscape(String key, Session userSession, Object... arguments)
      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 resources
      userSession - the user session
      arguments - the arguments to replace in the text with variables
      Returns:
      translated text
    • translateFullEscape

      public String translateFullEscape(String key, BeetRootHTTPSession session, Object... arguments)
      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 resources
      session - HTTP session or null (default language is used)
      arguments - the arguments to replace in the text with variables
      Returns:
      translated text
    • translate

      public String translate(String key, BeetRootHTTPSession session, Object... arguments)
      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 resources
      session - HTTP session or null (default language is used)
      arguments - the arguments to replace in the text with variables
      Returns:
      translated text
    • translate

      public String translate(String key, String lang, Object... arguments)
      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 resources
      lang - language code
      arguments - 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 resources
      defaultValue - default value
      userSession - the user session
      arguments - the arguments to replace in the text with variables
      Returns:
      translated text
    • translateOrDefVal

      public String 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. 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 resources
      defaultValue - default value
      lang - language code
      arguments - the arguments to replace in the text with variables
      Returns:
      translated text
    • isLangConfigured

      public boolean isLangConfigured(String lang)
      Checks if the given language is configured.
      Parameters:
      lang - language code
      Returns:
      true if so
    • removeLang

      public String removeLang(String uri)
      Remove language from URI.
      Parameters:
      uri - URI
      Returns:
      laguage code
    • parseLang

      public String parseLang(String uri)
      Get language from URI (e.g. 'en', 'de').
      Parameters:
      uri - URI
      Returns:
      language code as configured
    • getResource

      public String getResource(String configResource, String uri)
      Get web config resource / template based on language. Used when user is not logged in.
      Parameters:
      configResource - language template/resource
      uri - URI
      Returns:
      web resource
    • getResourceByLang

      public String getResourceByLang(String configResource, String lang)
      Get web config resource / template based on language code Used when user is not logged in.
      Parameters:
      configResource - language template/resource
      lang - language code
      Returns:
      web resource
    • getResourceWithoutLang

      public String getResourceWithoutLang(String configResource)
      Get web config resource / template based on no language :) Used for general templates usually.
      Parameters:
      configResource - language template/resource
      Returns:
      web resource
    • getResource

      public String getResource(String configResource, Session userSession)
      Get web config resource / template based on language. Used when user is logged in.
      Parameters:
      configResource - language template/resource
      userSession - user session
      Returns:
      web resource
    • getBlockResource

      public String getBlockResource(String configResource, Session userSession)
      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/resource
      userSession - user session
      Returns:
      web resource
    • getConfiguredLanguages

      public String[] getConfiguredLanguages()
      Get configured languages.
      Returns:
      languages codes
    • retrieveLanguage

      public String retrieveLanguage(BeetRootHTTPSession session)
      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

      public String getLanguageFromHttpSession(BeetRootHTTPSession session)
      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

      public String getLanguage(Session userSession)
      Get language. First from session, then DB, then use default language if not found earlier.
      Parameters:
      userSession - user session
      Returns:
      language code
    • getLanguageFromDb

      public String getLanguageFromDb(Session userSession)
      Get language from DB. First from DB, then use default language if not found earlier.
      Parameters:
      userSession - user session
      Returns:
      language code
    • updateLanguage

      public void updateLanguage(String newLanguage, Session userSession)
      Update user language.
      Parameters:
      newLanguage - new language code
      userSession - user session
    • loadPWValidationMessages

      public Properties loadPWValidationMessages(BeetRootHTTPSession session)
      Load translations for password checks.
      Parameters:
      session - HTTP session
      Returns:
      properties with validation messages