Interface TextResources

All Known Implementing Classes:
SimpleTextResourcesImpl

public interface TextResources
provides access to all text resources
  • Method Details

    • formatTextMessage

      String formatTextMessage(TextMessage textMessage)
      Formats a text message object and returns the formatted string.
      Returns:
      The formatted string text.
    • getFormattedTextWithParameter

      String getFormattedTextWithParameter(String textResourceKey, String parameter)
      Replaces [param] in the text resource with the passed parameter and formats the text message
      Returns:
      The formatted string text.
    • formatTextMessage

      String formatTextMessage(TextMessage msg, @Nullable @Nullable Locale locale)
      Formats a text message object and returns the formatted string.
      Returns:
      The formatted string text.
    • get

      Get information for this key. The fallback behavior depends on the environment. If there is no message defined in a desired language then: + in production: any other language is chosen (preferably a close one, or a common one, no guarantee) the Boolean is set to false, and the Locale tells which language was finally chosen. in case there isn't a message in ANY language then the behavior is as in dev/test. + in development and test: a message containing the message key is used, clearly stating that such a message is missing. the string does not use placeholders where variables could be put in, thus any variables (message formatting) should be appended by the formatter.
      Returns:
      the elements are: String message, Boolean if succeeded (otherwise fallback message), Locale the chosen one (null if none)
    • get

      Tuple3<String,Boolean,Locale> get(String key, List<Locale> preferredLocales)
    • onReload

      void onReload()
    • get

      Tuple3<String,Boolean,Locale> get(String key, Locale locale)
    • getText

      String getText(String key)
      Get a text for this specific key. Same behaviour as getText(String, Locale) but uses the Locale provided by L10N.currentLocale() and the calling module as module. Reports (logs) in case the text is missing.
      Parameters:
      key - the key
      Returns:
      the text
    • getText

      String getText(String key, Locale locale)
      Get a text for this specific key and locale. Reports (logs) in case the text is missing.
      Parameters:
      key - the key
      locale - the locale
      Returns:
      the text
    • tryGetText

      @Nullable @Nullable String tryGetText(String key)
      Same as getText(String), but returns null if the resource doesn't exist, and logs no error.
      Parameters:
      key - the key
      Returns:
      the text, or null if not there
    • tryGetText

      @Nullable @Nullable String tryGetText(String key, Locale locale)
      Same as getText(String), but returns null if the resource doesn't exist, and logs no error.
      Parameters:
      key - the key
      Returns:
      the text, or null if not there
    • isTextMissingString

      boolean isTextMissingString(String message)
      Tells if the message returned by the getText(java.lang.String) methods is a constructed fallback message because a real translation was missing. Maybe we'll have to add more overloaded getText() methods with another param by ref that tells if the resource was missing, or which locale was chosen, null if failed. This method just checks if the message starts with the failing indicator "##". Works for now.
      Parameters:
      message - the result of a getText(java.lang.String) call
      Returns:
      if the message was missing
    • getAll

      Map<String,String> getAll(Pattern pattern)
      Same behaviour as getAll(Pattern, Locale) but the Locale of the current Thread will be used.
      Parameters:
      pattern - eg "^client\\..*"
      Returns:
      May be empty, may contain null values!
    • getAll

      Map<String,String> getAll(Pattern pattern, Locale preferredLocale)
      Returns all texts for the given locale which match a regex pattern. May contain null values. That is the case if there is no definition for a key in the desired locale.
      Parameters:
      pattern - eg "^client\\..*"
    • getAll

      Map<String,String> getAll(Pattern pattern, List<Locale> preferredLocales)
      Same behaviour as getAll(Pattern, Locale) but this method will determine the best Locale from the given List itself.
      Parameters:
      pattern - eg "^client\\..*"
      Returns:
      May be empty, may contain null values!