# Translation Issues and Requests

**URL:** <https://jsonforms.discourse.group/t/translation-issues-and-requests/1976>\
**Category:** General\
**Created:** [February 19, 2024, 10:15am UTC](https://jsonforms.discourse.group/t/translation-issues-and-requests/1976 "2024-02-19T10:15:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eternal-dragon](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/eternal-dragon/32/923_2.png) [@eternal-dragon](https://jsonforms.discourse.group/u/eternal-dragon)\
**Post date:** [February 19, 2024, 10:15am UTC](https://jsonforms.discourse.group/t/translation-issues-and-requests/1976/1 "2024-02-19T10:15:58Z")

</div>

**1. No Translation for ‘No Data’ (NoDataMessage):**

The translation for the ‘No Data’ message (NoDataMessage) seems to be missing. When attempting to display a message for an empty data set, the translation is not being applied.

**2. Incorrect ID for ‘Required’ Error (error.required):**

The translation ID for the ‘Required’ error message (error.required) seems to be incorrect. It appears to be using ‘error.custom’ as the ID instead.

**3. Incorrect Input Handling (input):**

The translation for ‘input’ does not seem to be handled correctly. When attempting to translate the term ‘input,’ it does not retrieve the appropriate translation.

 ![图片](https://global.discourse-cdn.com/free1/uploads/jsonforms/original/1X/b1e4aac0f09ba52efee0d34ad2b0418518a973a5.png)

### this is my code：

```auto
import { ArrayTranslationEnum, ArrayTranslations, JsonFormsI18nState, Translator } from "@jsonforms/core"

export const translateZhCN: Translator = ( id, defaultMessage, values ) => {
    if ( id.includes( "error.required" ) ) {
        return '必须填写的字段'
    }

    const key = id.split( '.' ).pop() // 去掉前缀
    const translated = arrayTranslationsZhCN[key as keyof ArrayTranslations]
    if ( typeof translated === 'function' ) {
        return translated( values )
    }

    console.log( "cant traslate " + id )
    return defaultMessage || id
}

export const i18n_ZhCN: JsonFormsI18nState = {
    translate: translateZhCN
}

export const arrayTranslationsZhCN = {
    [ArrayTranslationEnum.addTooltip]: ( input: any ) => ( input ? `添加到 ${ input }` : '添加' ),
    [ArrayTranslationEnum.addAriaLabel]: ( input: any ) => ( input ? `添加到 ${ input } 按钮` : '添加按钮' ),
    [ArrayTranslationEnum.removeTooltip]: () => '删除',
    [ArrayTranslationEnum.removeAriaLabel]: () => '删除按钮',
    [ArrayTranslationEnum.upAriaLabel]: () => '上移项目',
    [ArrayTranslationEnum.up]: () => '上移',
    [ArrayTranslationEnum.down]: () => '下移',
    [ArrayTranslationEnum.downAriaLabel]: () => '下移项目',
    [ArrayTranslationEnum.noDataMessage]: () => '空',
    [ArrayTranslationEnum.noSelection]: () => '无选项',
    [ArrayTranslationEnum.deleteDialogTitle]: () => '确认删除',
    [ArrayTranslationEnum.deleteDialogMessage]: () => '确定要删除所选条目吗？',
    [ArrayTranslationEnum.deleteDialogAccept]: () => '是',
    [ArrayTranslationEnum.deleteDialogDecline]: () => '否',
}

```

And I also got a problem in coding，on the Translator last return，I can’t just `return defaultMessage`. It ask me to return a string.So I change it to `defaultMessage || id`,which might be wrong.  
Seeking guidance, is there something wrong with what I wrote?

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [February 19, 2024, 12:32pm UTC](https://jsonforms.discourse.group/t/translation-issues-and-requests/1976/2 "2024-02-19T12:32:20Z")

</div>

Hi!

> [@eternal-dragon](#):
>
> The translation for the ‘No Data’ message (NoDataMessage) seems to be missing. When attempting to display a message for an empty data set, the translation is not being applied.

The `No Data` message currently can’t be translated. There is already a [PR open](https://github.com/eclipsesource/jsonforms/pull/2286) to improve this. As a workaround you can use a custom renderer until then.

> [@eternal-dragon](#):
>
> The translation ID for the ‘Required’ error message (error.required) seems to be incorrect. It appears to be using ‘error.custom’ as the ID instead.

Usually we first ask for custom and only for required afterwards, see here for the [documentation](https://jsonforms.io/docs/i18n#error-customizations). You probably don’t see the `required` key coming in because you don’t return the `defaultMessage` in case it’s undefined. However you definitely need to do that, [see the documentation](https://jsonforms.io/docs/i18n#defaultmessage).

> If the `defaultMessage` is `undefined` , you should also return `undefined` if there is no translation for the given key. Returning an empty string (or something similar) instead may result in undesired behavior. JSON Forms will use `undefined` when the message could be skipped or another more generic key could be tried.

> [@eternal-dragon](#):
>
> The translation for ‘input’ does not seem to be handled correctly. When attempting to translate the term ‘input,’ it does not retrieve the appropriate translation.

I’m not sure what you mean by this? What is not translated correctly?

* * *

Regarding the code:

- Why are you splitting the key (called `id` in your case)? That should not be necessary
- Please make sure to return the `defaultMessage` when you don’t have a translation. Do **NOT** use `defaultMessage || something-else`. In case you have a type error, use for example the `any` type. What version of JSON Forms are you using? We improved the `Translator` type so that this issue should no longer occur.

---

<div class="post-metadata">

**Author:** ![eternal-dragon](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/eternal-dragon/32/923_2.png) [@eternal-dragon](https://jsonforms.discourse.group/u/eternal-dragon)\
**Post date:** [February 20, 2024, 5:33am UTC](https://jsonforms.discourse.group/t/translation-issues-and-requests/1976/3 "2024-02-20T05:33:03Z")

</div>

for the default message , my typescript don’t allow me to just return `defaultMessage` 🙃

 ![图片](https://global.discourse-cdn.com/free1/uploads/jsonforms/original/1X/fc6ca9b18cfa7634c139a3190f745794254c8519.png)

My version is 3.1.0

---

<div class="post-metadata">

**Author:** ![eternal-dragon](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/eternal-dragon/32/923_2.png) [@eternal-dragon](https://jsonforms.discourse.group/u/eternal-dragon)\
**Post date:** [February 20, 2024, 5:40am UTC](https://jsonforms.discourse.group/t/translation-issues-and-requests/1976/4 "2024-02-20T05:40:17Z")

</div>

the value problem is the translator for add：  
`[ArrayTranslationEnum.addTooltip]: ( input: any ) => ( input ? `添加到 ${ input }` : '添加' ),`  
the translator always got no input.  
But without the translator，it can display the input：

 ![图片](https://global.discourse-cdn.com/free1/uploads/jsonforms/original/1X/a4ce041f5e6ae05d79d3d5018801944eb4f7f099.png)

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [February 20, 2024, 2:42pm UTC](https://jsonforms.discourse.group/t/translation-issues-and-requests/1976/5 "2024-02-20T14:42:35Z")

</div>

> [@eternal-dragon](#):
>
> for the default message , my typescript don’t allow me to just return `defaultMessage` 🙃

You either need to update JSON Forms or you cast the `defaultMessage`, for example to `any`

> [@eternal-dragon](#):
>
> the value problem is the translator for add：  
> `[ArrayTranslationEnum.addTooltip]: ( input: any ) => ( input ? `添加到 ${ input }` : '添加' ),`  
> the translator always got no input.  
> But without the translator，it can display the input：

JSON Forms currently hands over the label only as part of the `defaultMessage`, see [here](https://github.com/eclipsesource/jsonforms/blob/c8d3ecf2255e537e3e3eaefe4e977273c72db572/packages/core/src/i18n/i18nUtil.ts#L176). So at the moment you need to parse the `label` out of the handed over `defaultMessage`.

This should be improved, JSON Forms should hand over the label within the third parameter of `translate`, so that translators like yours can access it directly, instead of needing to parse it out of the `defaultMessage`.

---

<div class="post-metadata">

**Author:** ![eternal-dragon](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/eternal-dragon/32/923_2.png) [@eternal-dragon](https://jsonforms.discourse.group/u/eternal-dragon)\
**Post date:** [February 21, 2024, 2:28pm UTC](https://jsonforms.discourse.group/t/translation-issues-and-requests/1976/6 "2024-02-21T14:28:14Z")

</div>

thanks you! I’ll try it later.
