Class XItemPropertyI18NUtils


  • public class XItemPropertyI18NUtils
    extends Object
    Static methods for finding the localized value of an XItem's property. For properties that can be localized, the form designer lets the user configure a translation for each supported language, stored in a JSON object with the language tag as the key. These helper methods look up the requested language in that map, and use the translation for the best matching available language. If for example no translation is available for de_DE, the translation for de is used, if available.
    Author:
    XIMA MEDIA GmbH
    • Constructor Detail

      • XItemPropertyI18NUtils

        public XItemPropertyI18NUtils()
    • Method Detail

      • replaceI18NAndEmptyValue

        public static String replaceI18NAndEmptyValue​(String value,
                                                      IXFormRenderConfig config)
        Replaces placeholders in the given value, using the data from the given render config. If the value is one of the special empty strings (such as e.g. (empty)), returns the empty string.
        Parameters:
        value - Value that may contain placeholders to replace.
        config - Render config to use for the replacement process.
        Returns:
        The value with all placeholders replaced.
      • replaceI18NAndEmptyValue

        public static String replaceI18NAndEmptyValue​(String value,
                                                      IXFormRenderConfig config,
                                                      boolean escapeHtml)
        Replaces placeholders in the given value, using the data from the given render config. If the value is one of the special empty strings (such as e.g. (empty)), returns the empty string.
        Parameters:
        value - Value that may contain placeholders to replace.
        config - Render config to use for the replacement process.
        escapeHtml - true to escape HTML in form placeholders, false otherwise.
        Returns:
        The value with all placeholders replaced.
      • getBestLanguage

        public static String getBestLanguage​(IXFormRenderConfig config,
                                             com.alibaba.fastjson.JSONObject object,
                                             String propName)
        Given a language, searches for the closest language with an available translation for the given form element property. For example, if the form is to be rendered in the language fr-CA, this method first checks whether a translation is available for that language. If so, that language is returned. Otherwise, this method checks whether a translation is available for the language tag fr. If none is available either, the empty string is returned.
        Parameters:
        config - A form configuration with a language tag.
        object - A JSON object with the language tag as the key and another JSON object as the value. These JSON objects have the property name as the key and the localized text as the value.
        propName - Name of the (form element) property for which to find the localized text.
        Returns:
        The current language of the given form if a translation exists for that language, or a fallback language that has a translation.
      • getI18NValueR

        public static String getI18NValueR​(IXFormRenderConfig config,
                                           XPropertyEnum property,
                                           String defaultValue,
                                           XItemRenderData properties)
        Stands for getI18NValueRaw.

        Gets the localized value for the given property, without replacing any placeholders.

        Parameters:
        config - Current render configuration for the replacement process.
        property - Property for which to get the localized value.
        defaultValue - Value to return when no localized value was found.
        properties - All properties of the item for which to get the localized property value. This is used to access the XPropertyEnum.i18n with the localized values.
        Returns:
        The localized value, with all placeholders replaced.
      • getI18NValueR

        public static String getI18NValueR​(IXFormRenderConfig config,
                                           String property,
                                           String defaultValue,
                                           XItemRenderData properties)
        Stands for getI18NValueRaw.

        Gets the localized value for the given property, without replacing any placeholders.

        Parameters:
        config - Current render configuration for the replacement process.
        property - Property for which to get the localized value.
        defaultValue - Value to return when no localized value was found.
        properties - All properties of the item for which to get the localized property value. This is used to access the XPropertyEnum.i18n with the localized values.
        Returns:
        The localized value, with all placeholders replaced.
      • getI18NValueR

        public static String getI18NValueR​(IXFormRenderConfig config,
                                           com.alibaba.fastjson.JSONObject json,
                                           String defaultValue,
                                           XPropertyEnum property)
        Stands for getI18NValueRaw.

        Gets the localized value for the given property, without replacing any placeholders.

        Parameters:
        config - Current render configuration for the replacement process.
        json - A JSON object with an i18n property, which must be a JSONObject and contain the localized values.
        defaultValue - Value to return when no localized value was found.
        property - Property for which to get the localized value.
        Returns:
        The localized value, with all placeholders replaced.
      • getI18NValueR

        public static String getI18NValueR​(IXFormRenderConfig config,
                                           com.alibaba.fastjson.JSONObject json,
                                           String defaultValue,
                                           String property)
        Stands for getI18NValueRaw.

        Gets the localized value for the given property, without replacing any placeholders.

        Parameters:
        config - Current render configuration for the replacement process.
        json - A JSON object with an i18n property, which must be a JSONObject and contain the localized values.
        defaultValue - Value to return when no localized value was found.
        property - Property for which to get the localized value.
        Returns:
        The localized value, with all placeholders replaced.
      • getI18NValue

        public static String getI18NValue​(XItem xitem,
                                          IXFormRenderConfig config,
                                          XPropertyEnum xProperty)
        Gets the localized value for the given property, with all placeholders replaced.
        Parameters:
        xitem - Item with the property.
        config - Current render configuration for the replacement process.
        xProperty - Property for which to get the localized value.
        Returns:
        The localized value, with all placeholders replaced.
      • getI18NValue

        public static String getI18NValue​(IXFormRenderConfig config,
                                          com.alibaba.fastjson.JSONObject json,
                                          String defaultValue,
                                          String property,
                                          boolean escapeHtml)
        Gets the localized value for the given property, with all placeholders replaced.
        Parameters:
        config - Current render configuration for the replacement process.
        json - A JSON object with an i18n key that contains the localized values.
        defaultValue - Value to return when no localized value was found.
        property - Name of the property for which to the localized value.
        escapeHtml - Whether to escape HTML in the placeholder content of form element placeholders. Should be set to true when the property's content is an HTML string.
        Returns:
        The localized value, with all placeholders replaced.