elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.72k stars 8.14k forks source link

language file produced by i18n_extract is not usable as-is #61544

Open adelisle opened 4 years ago

adelisle commented 4 years ago

Kibana version: 7.5.0 Elasticsearch version: 7.5.0 Server OS version: Windows 10 Browser version: Edge 82.0.453.2 Browser OS version: Windows 10 Original install method (e.g. download page, yum, from source, etc.): From source Describe the bug: node scripts/i18n_extract --output-dir ./translations produces a file according to format specified here but, once configured to be used as a source translation file, errors like this are produced:

FATAL  Error: [I18n] Error formatting message: "timelion.help.functions.label.args.labelHelpText" for locale: "en-we".
TypeError: A message must be provided as a String or AST.

Steps to reproduce:

  1. Make sure a folder translations exists
  2. Run the command node scripts/i18n_extract --output-dir ./translations
  3. Add a reference to the file in .i18nrc.json
  4. Configure kibana.yml to use the new locale
  5. Start Kibana yarn start

The same error is visible in the Console Logs of the broswer if a page load is attempted.

Expected behavior: The form of messages with text and comment is supported as produced by the extraction tool.

Screenshots (if relevant):

Errors in browser console (if relevant):

C:\Workspace\kibana\src\core\public\core_system.ts:391 Error: [I18n] Error formatting message: "core.euiBasicTable.selectAllRows" for locale: "en-we".
TypeError: A message must be provided as a String or AST.
    at Object.translate (C:\Workspace\kibana\packages\kbn-i18n\target\web\core\i18n.js:298)
    at I18nService.getContext (C:\Workspace\kibana\src\core\public\i18n\i18n_service.tsx:48)
    at I18nService.start (C:\Workspace\kibana\src\core\public\i18n\i18n_service.tsx:380)
    at CoreSystem._callee2$ (C:\Workspace\kibana\src\core\public\core_system.ts:287)
    at tryCatch (runtime.js:45)
    at Generator.invoke [as _invoke] (runtime.js:271)
    at Generator.prototype.<computed> [as next] (runtime.js:97)
    at asyncGeneratorStep (C:\Workspace\kibana\src\core\public\core_system.ts:50)
    at _next (C:\Workspace\kibana\src\core\public\core_system.ts:52)

Provide logs and/or server output (if relevant):

server    log   [21:07:02.966] [fatal][root] Error: [I18n] Error formatting message: "timelion.help.functions.label.args.labelHelpText" for locale: "en-we".
TypeError: A message must be provided as a String or AST.
    at Object.translate (C:\Workspace\kibana\packages\kbn-i18n\target\node\core\i18n.js:227:13)
    at Object.<anonymous> (C:\Workspace\kibana\src\legacy\core_plugins\timelion\server\series_functions/label.js:33:18)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Module._compile (C:\Workspace\kibana\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Object.newLoader [as .js] (C:\Workspace\kibana\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at getTuple (C:\Workspace\kibana\src\legacy\core_plugins\timelion\server\lib/load_functions.js:28:19)
    at C:\Workspace\kibana\src\legacy\core_plugins\timelion\server\lib/load_functions.js:34:12
    at arrayMap (C:\Workspace\kibana\node_modules\lodash\index.js:1432:25)
    at Function.map (C:\Workspace\kibana\node_modules\lodash\index.js:6758:14)
    at _default (C:\Workspace\kibana\src\legacy\core_plugins\timelion\server\lib/load_functions.js:32:19)
    at TimelionServerPlugin.setup (C:\Workspace\kibana\src\legacy\core_plugins\timelion\server/plugin.ts:55:23)
    at Plugin.externalInit (C:\Workspace\kibana\src\legacy\core_plugins\timelion/index.ts:200:34)
    at Object.register (C:\Workspace\kibana\src\legacy\server\plugins\lib/plugin.js:85:20)
    at internals.Server.register (C:\Workspace\kibana\node_modules\hapi\lib\server.js:431:35)
    at Plugin.init (C:\Workspace\kibana\src\legacy\server\plugins\lib/plugin.js:89:28)
    at Plugin.init (C:\Workspace\kibana\node_modules\lodash\index.js:7411:25)
    at callPluginHook (C:\Workspace\kibana\src\legacy\server\plugins\lib/call_plugin_hook.js:49:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Any additional context: I have managed to fix this issue for me using the following patch.

In this file, replace the line:

      const formattedMessage = getMessageFormat(message, getLocale(), getFormats()).format(values);

with

      const actualMessage = typeof message.text !== 'undefined' ? message.text : message;
      const formattedMessage = getMessageFormat(actualMessage, getLocale(), getFormats()).format(values);
elasticmachine commented 4 years ago

Pinging @elastic/kibana-operations (Team:Operations)

mshustov commented 4 years ago

also bumped into this problem in https://discuss.elastic.co/t/the-problem-with-a-custom-translation-file/230370/2

Baresse commented 4 years ago

I had the same error but it seems the file produced by the script i18n_extract contains some comments useful to people doing the translation. Theses comments should not be present in the JSON file used by Kibana.

To get rid of theses comments I've used the provided script i18n_integrate which generates a new JSON from your translated one.

node scripts/i18n_integrate --source path/to/locale.json --target locale-integrated.json

If you put the generated file in the translations folder you should get rid of the errors.