vue.jsinternationalizationvue-i18n

Why does vite-plugin-vue-i18n give Internal server error: Cannot read properties of undefined (reading 'message')?


I am updating i18n translations for our project. After running 17 translations for French I started getting an error from the i18n plugin, with none of the stack trace leading back to my code line, just the file name.

Cannot read properties of undefined (reading 'message')
5:56:50 PM [vite] Internal server error: Cannot read properties of undefined (reading 'message')
  Plugin: vite-plugin-vue-i18n
  File: /var/src/project/src/i18n/fr.json
      at newOptions.onError (/var/src/project/node_modules/@intlify/bundle-utils/lib/codegen.js:102:48)
      at newOptions.onError (/var/src/project/node_modules/@intlify/bundle-utils/lib/codegen.js:102:36)
      at newOptions.onError (/var/src/project/node_modules/@intlify/bundle-utils/lib/codegen.js:102:36)
      at emitError (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:197:13)
      at readTokenInPlaceholder (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:681:21)
      at readToken (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:776:20)
      at Object.nextToken (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:823:16)
      at parseNamed (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:910:19)
      at parseMessage (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:1048:37)
      at parseResource (/var/src/project/node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:1096:25)

Any idea of the problem?


Solution

  • It turns out that the VSCode plugin I18N Ally that I use to translate the strings automatically got a bad one back from its translator.

    "from-users-usernames": "from users {usernames}",
    became
    "from-users-usernames": "des utilisateurs {nom d'utilisateurs}",
    (or something like that. I already fixed it.)

    The plugin can't handle the two word variable within the braces and therefore generates this warning.

    I will try to open an issue with intlify to get them to detect this problem and report it more explicitly, giving the source line number and a useful description.

    I've seen the translation problem in https://translate.google.com when doing Gettext translations manually, usually in Spanish (of the 5 languages I currently manage). Sometimes it chooses to translate the values that Gettext or i18N use as parameters, but most of the time it doesn't.