intlify / vue-i18n-loader

:globe_with_meridians: vue-i18n loader for custom blocks
MIT License
268 stars 29 forks source link

Empty .yml files throw a warnings #202

Closed Vannsl closed 3 years ago

Vannsl commented 3 years ago

Reporting a bug?

When an empty .yml file gets loaded, the Loader throws a warning when using the webpack loader.

An empty .yml file looking like this:

---

The thrown warning is:

WARNING in ./app/javascript/src/apps/LearningResource/locales/de-DE.yml 1:15
Module parse failed: Unexpected token (1:15)
File was processed with these loaders:
 * ./node_modules/@intlify/vue-i18n-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
> export default 

Expected behavior

There is no warning thrown, but the file is loaded, compiled the yml file to an empty javascript object

Reproduction

  1. Add the vue-i18n-loader via webpack with:
var path = require("path");

module.exports = {
  test: /\.(json5?|ya?ml)$/, // target json, json5, yaml and yml files
  type: "javascript/auto",
  loader: "@intlify/vue-i18n-loader",
  include: [
    // Use `Rule.include` to specify the files of locale messages to be pre-compiled
    path.resolve(__dirname, "..", "..", [INSERT YOUR PATH]),
  ],
};
  1. Add an empty yaml file
  2. Run the loader

System Info

Webpack 4 with:

  System:
    OS: macOS 11.5.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 2.77 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.1 - ~/.nvm/versions/node/v14.17.1/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.1/bin/npm
  Browsers:
    Brave Browser: 93.1.29.76
    Edge: 93.0.961.38
    Firefox: 90.0.2
    Safari: 14.1.2
  npmPackages:
    @intlify/vue-i18n-loader: ^3.0.0 => 3.0.0 
    vue: ^3.2.6 => 3.2.6 
    vue-i18n: ^9.1.7 => 9.1.7

Screenshot

No response

Additional context

No response

Validations

kazupon commented 3 years ago

Thank you for your reporting!

Expected behavior There is no warning thrown, but the file is loaded, compiled the yml file to an empty javascript object

The compiling YAML with the incorrect format as an empty JavaScript object, without warning, it's not good behavior. This is because you will not be able to notice the incorrectly formatted YAML. The current behavior is correct, although the warning message output by vue-i18n-loader needs to be improved to output a clearer message.

Thanks!

Vannsl commented 3 years ago

Thanks for the answer :+1:

Our localization platform exports these empty yml if the translations are missing. I agree that failing silently might be worse. I will look into another solutions.

kazupon commented 3 years ago

Our localization platform exports these empty yml

Hmm, :thinking: I was a little interested in it. If you don't mind me asking, could you tell me if you are using any localization platform?

Vannsl commented 3 years ago

Sure: Crowdin. It creates pull requests into our dev branch for new translations (de-DE). But also everytime I merge en-US files into dev, it creates a PR with the empty de-DE file.

We would not add them manually of course. I need to check if I can disable in their interface that it creates the PRs with empty files at all.

kazupon commented 3 years ago

Thanks!