Package de.xima.fc.form.common
Class XItemPropertyI18NUtils
- java.lang.Object
-
- de.xima.fc.form.common.XItemPropertyI18NUtils
-
public class XItemPropertyI18NUtils extends Object
Static methods for finding the localized value of anXItem
'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 Summary
Constructors Constructor Description XItemPropertyI18NUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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.static String
getI18NValue(XItem xitem, IXFormRenderConfig config, XPropertyEnum xProperty)
Gets the localized value for the given property, with all placeholders replaced.static String
getI18NValue(IXFormRenderConfig config, com.alibaba.fastjson.JSONObject json, String defaultValue, XPropertyEnum property)
Deprecated.UsegetI18NValue(XItem, IXFormRenderConfig, XPropertyEnum)
if you have aXPropertyEnum
; orgetI18NValue(IXFormRenderConfig, JSONObject, String, String, boolean)
if you have a custom property.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.static String
getI18NValueR(IXFormRenderConfig config, com.alibaba.fastjson.JSONObject json, String defaultValue, XPropertyEnum property)
Stands for getI18NValueRaw.static String
getI18NValueR(IXFormRenderConfig config, com.alibaba.fastjson.JSONObject json, String defaultValue, String property)
Stands for getI18NValueRaw.static String
getI18NValueR(IXFormRenderConfig config, XPropertyEnum property, String defaultValue, XItemRenderData properties)
Stands for getI18NValueRaw.static String
getI18NValueR(IXFormRenderConfig config, String property, String defaultValue, com.alibaba.fastjson.JSONObject i18n)
Stands for getI18NValueRaw.static String
getI18NValueR(IXFormRenderConfig config, String property, String defaultValue, XItemRenderData properties)
Stands for getI18NValueRaw.static String
replaceI18NAndEmptyValue(String value, IXFormRenderConfig config)
Deprecated.static String
replaceI18NAndEmptyValue(String value, IXFormRenderConfig config, boolean escapeHtml)
Replaces placeholders in the given value, using the data from the given render config.
-
-
-
Method Detail
-
replaceI18NAndEmptyValue
public static String replaceI18NAndEmptyValue(String value, IXFormRenderConfig config)
Deprecated.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 languagefr-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 tagfr
. 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 theXPropertyEnum.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 theXPropertyEnum.i18n
with the localized values.- Returns:
- The localized value, with all placeholders replaced.
-
getI18NValueR
public static String getI18NValueR(IXFormRenderConfig config, String property, String defaultValue, com.alibaba.fastjson.JSONObject i18n)
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.i18n
- JSON object 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 ani18n
property, which must be aJSONObject
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 ani18n
property, which must be aJSONObject
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 ani18n
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 totrue
when the property's content is an HTML string.- Returns:
- The localized value, with all placeholders replaced.
-
getI18NValue
public static String getI18NValue(IXFormRenderConfig config, com.alibaba.fastjson.JSONObject json, String defaultValue, XPropertyEnum property)
Deprecated.UsegetI18NValue(XItem, IXFormRenderConfig, XPropertyEnum)
if you have aXPropertyEnum
; orgetI18NValue(IXFormRenderConfig, JSONObject, String, String, boolean)
if you have a custom property.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 ani18n
key that contains the localized values.defaultValue
- Value to return when no localized value was found.property
- Property instance from which to take thename
of the property.- Returns:
- The localized value, with all placeholders replaced.
-
-