# New API to get a rendered translation in LocalizationManager

**URL:** <https://forum.xwiki.org/t/new-api-to-get-a-rendered-translation-in-localizationmanager/12622>\
**Category:** Development\
**Tags:** proposal\
**Created:** [June 5, 2023, 10:07am UTC](https://forum.xwiki.org/t/new-api-to-get-a-rendered-translation-in-localizationmanager/12622 "2023-06-05T10:07:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [June 5, 2023, 10:07am UTC](https://forum.xwiki.org/t/new-api-to-get-a-rendered-translation-in-localizationmanager/12622/1 "2023-06-05T10:07:22Z")

</div>

Hi devs,

I’d like to propose adding `String getTranslation(String key, Locale locale, Syntax targetSyntax, Object... parameters)` in `LocalizationManager`, as in:

```auto
    /**
     * 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...](https://jira.xwiki.org/browse/XWIKI-20954) 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](https://github.com/xwiki/xwiki-platform/blob/c681aac454829b8942d539879d6ccc6c48d66d0e/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/UploadAction.java#L229) and have code call this new signature when it needs to get a String (properly escaped).

WDYT?

Thanks

---

<div class="post-metadata">

**Author:** ![tmortagne](https://forum.xwiki.org/user_avatar/forum.xwiki.org/tmortagne/32/4930_2.png) [@tmortagne](https://forum.xwiki.org/u/tmortagne)\
**Post date:** [June 5, 2023, 11:36am UTC](https://forum.xwiki.org/t/new-api-to-get-a-rendered-translation-in-localizationmanager/12622/2 "2023-06-05T11:36:01Z")

</div>

+1

---

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [June 5, 2023, 4:39pm UTC](https://forum.xwiki.org/t/new-api-to-get-a-rendered-translation-in-localizationmanager/12622/3 "2023-06-05T16:39:30Z")

</div>

Implemented in [Loading...](https://jira.xwiki.org/browse/XWIKI-20968)
