opensearch-project / OpenSearch-Dashboards

📊 Open source visualization dashboards for OpenSearch.
https://opensearch.org/docs/latest/dashboards/index/
Apache License 2.0
1.6k stars 820 forks source link

[BUG] Internationalization not working #772

Open abbyhu2000 opened 2 years ago

abbyhu2000 commented 2 years ago

Describe the bug When changing the locale config from English to Chinese in the opensearch_dashboards.yml file, the application does not change language to Chinese but still showing the default language English.

To Reproduce Steps to reproduce the behavior:

  1. Go to opensearch_dashboards.yml file
  2. Scroll down to 'i18n.locale'
  3. Input "zh-CN"
  4. Restart server and refresh the browser

Expected behavior Language for the Opensearch Dashboard should be changed from the default language English to Chinese as the comments saying "supported languages are the following: English - en, by default, Chinese -zh-CN" in the yml file.

Screenshots Screen Shot 2021-09-08 at 4 49 36 PM

Additional context Legacy application includes the supported translation functions in the X-pack folder, so we do not have access to it.

request:
curl 'http://localhost:5603/uev/translations/zh-cn.json' -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: http://localhost:5603/uev/app/discover' -H 'Connection: keep-alive' -H 'Cookie:xxxxx' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'

resp:
{"locale":"zh-CN","messages":{}}
abbyhu2000 commented 2 years ago

One possible solution is to create a translation plugin.

schleuss commented 2 years ago

I'm working on translating opensearch-dashboard to pt-BR and I had the same problem when deploying.

Investigating the problem, I noticed that the translation files are not loaded

Req:
curl 'http://localhost:5603/translations/pt-BR.json' 

Res:
{"locale":"pt-BR","messages":{}}

Through debugging I've verified that the translation files are not found when executing the script src/legacy/server/i18n/index.ts

The cause of this problem is the format of the expression passed to the globby lib

Changing the code, adding '**' before the I18N_RC the problem was fixed

  const translationPaths = await Promise.all([
    getTranslationPaths({
      cwd: fromRoot('.'),
      glob: `**/${I18N_RC}`,
    }),
    ...(config.get('plugins.paths') as string[]).map((cwd) =>
      getTranslationPaths({ cwd, glob: I18N_RC })
    ),
    ...(config.get('plugins.scanDirs') as string[]).map((cwd) =>
      getTranslationPaths({ cwd, glob: `**/${I18N_RC}` })
    ),
    getTranslationPaths({
      cwd: fromRoot('../opensearch-dashboards-extra'),
      glob: `**/${I18N_RC}`,
    }),
  ]);

After finding the I18N_RC files (.i18nrc.json), the translations are loaded from the json

In my case, the _scripts/i18nintegrate tool did not add the files in this configuration. I had to do this manually.

{
  ...
  "translations": []
}

I can't tell if it's another problem, or something I forgot to do.

PR: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/1276

gaoyan0204 commented 1 year ago

how to customize the language conversion plug-in?

schleuss commented 1 year ago

Here is an example of translation to pt-BR..

https://github.com/schleuss/opensearch-dashboard-i18n-ptbr

But i've found some translations issues. Some opensearrch UI components are not working properly.

joshuarrrr commented 1 year ago

We've created the i18n OpenSearch Dashboards plugin to provide this functionality.