Class XWikiMessageTool


  • @Deprecated
    public class XWikiMessageTool
    extends Object
    Deprecated.
    since 4.3M2 use the LocalizationManager component instead
    Internationalization service based on key/property values. The key is the id of the message being looked for and the returned value is the message in the language requested. There are 3 sources where properties are looked for (in the specified order):
    1. If there's a "documentBundles" property in the XWiki Preferences page then the XWiki documents listed there (separated by commas) are considered the source for properties
    2. If there's a "xwiki.documentBundles" property in the XWiki configuration file (xwiki.cfg) then the XWiki documents listed there (separated by commas) are considered for source for properties
    3. The Resource Bundle passed in the constructor
    If the property is not found in any of these 3 sources then the key is returned in place of the value. In addition the property values are cached for better performance but if one of the XWiki documents containing the properties is modified, its content is cached again next time a key is asked.
    Version:
    $Id: 30b72482859df5e179031ab5c7dacf865f35cca8 $
    • Field Detail

      • bundle

        protected ResourceBundle bundle
        Deprecated.
        The default Resource Bundle to fall back to if no document bundle is found when trying to get a key.
    • Constructor Detail

      • XWikiMessageTool

        public XWikiMessageTool​(ContextualLocalizationManager localization)
        Deprecated.
        Parameters:
        localization - the localization manager
      • XWikiMessageTool

        public XWikiMessageTool​(ResourceBundle bundle,
                                XWikiContext context)
        Deprecated.
        Parameters:
        bundle - the default Resource Bundle to fall back to if no document bundle is found when trying to get a key
        context - the XWikiContext object, used to get access to XWiki primitives for loading documents
    • Method Detail

      • getXWikiContext

        protected XWikiContext getXWikiContext()
        Deprecated.
      • get

        public String get​(String key,
                          List<?> params)
        Deprecated.
        Find a translation and then replace any parameters found in the translation by the passed params parameters. The format is the one used by MessageFormat.

        Note: The reason we're using a List instead of an Object array is because we haven't found how to easily create an Array in Velocity whereas a List is easily created. For example: $msg.get("key", ["1", "2", "3"]) .

        Parameters:
        key - the key of the string to find
        params - the list of parameters to use for replacing "{N}" elements in the string. See MessageFormat for the full syntax
        Returns:
        the translated string with parameters resolved
      • get

        public String get​(String key,
                          Object... params)
        Deprecated.
        Find a translation and then replace any parameters found in the translation by the passed parameters. The format is the one used by MessageFormat.
        Parameters:
        key - the key of the string to find
        params - the list of parameters to use for replacing "{N}" elements in the string. See MessageFormat for the full syntax
        Returns:
        the translated string with parameters resolved
      • getDocumentBundle

        public XWikiDocument getDocumentBundle​(String documentName)
        Deprecated.
        Helper method to help get a translated version of a document. It handles any exception raised to make it easy to use.
        Parameters:
        documentName - the document's name (eg Space.Document)
        Returns:
        the document object corresponding to the passed document's name. A translated version of the document for the current Locale is looked for.
      • getDocumentBundles

        public List<XWikiDocument> getDocumentBundles​(String documentName,
                                                      String defaultLanguage)
        Deprecated.
        Helper method to help get a translated version of a document. It handles any exception raised to make it easy to use.
        Parameters:
        documentName - the document's name (eg Space.Document)
        defaultLanguage - default language
        Returns:
        the document object corresponding to the passed document's name. A translated version of the document for the current Locale is looked for.
      • getDocumentBundleProperties

        public Properties getDocumentBundleProperties​(XWikiDocument docBundle)
        Deprecated.
        Parameters:
        docBundle - the document bundle.
        Returns:
        properties of the document bundle.
      • getTranslation

        protected String getTranslation​(String key)
        Deprecated.
        Looks for a translation in the list of internationalization document bundles. It first checks if the translation can be found in the cache.
        Parameters:
        key - the key identifying the translation
        Returns:
        the translation or null if not found or if the passed key is null