Hi devs,
I’d like to propose adding String getTranslation(String key, Locale locale, Syntax targetSyntax, Object... parameters)
in LocalizationManager
, as in:
/**
* Find a translation in the specified locale.
*
* @param key the key identifying the message to look for
* @param locale the {@link Locale} for which this translation is searched. The result might be associated to a
* different {@link Locale} (for example getting the {@code fr} translation when asking for the
* {@code fr_FR} one).
* @param parameters the parameters
* @return the translation in the defined language, rendered as plain text, null if no translation could be found
* @see #getTranslation(String, Locale)
* @since 14.1RC1
* @since 13.10.3
*/
default String getTranslationPlain(String key, Locale locale, Object... parameters)
{
return getTranslation(key, locale, Syntax.PLAIN_1_0, parameters);
}
/**
* Find a translation in the specified locale.
*
* @param key the key identifying the message to look for
* @param locale the {@link Locale} for which this translation is searched. The result might be associated to a
* different {@link Locale} (for example getting the {@code fr} translation when asking for the
* {@code fr_FR} one).
* @param targetSyntax the syntax in which to render the translation
* @param parameters the parameters
* @return the translation in the defined language, rendered in the target syntax, null if no translation could be
* found
* @see #getTranslation(String, Locale)
* @since 15.5RC1
* @since 14.10.2
*/
default String getTranslation(String key, Locale locale, Syntax targetSyntax, Object... parameters)
{
return null;
}
The rationale is to have some helper method to get a translation as a string and then to refactor the following places:
LocalizationScriptService#render(... Syntax syntax...)
- Fix Loading... which is caused by the change at xwiki-platform/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/UploadAction.java at c681aac454829b8942d539879d6ccc6c48d66d0e · xwiki/xwiki-platform · GitHub and have code call this new signature when it needs to get a String (properly escaped).
WDYT?
Thanks