vue-cli-plugin-i18n icon indicating copy to clipboard operation
vue-cli-plugin-i18n copied to clipboard

Allow fallback of keys when value is empty.

Open pikax opened this issue 7 years ago • 0 comments

When you add a new key It will add on the others locales with the same key and an empty string value, this behavior is good for development, but production you want allow to fallback to the fallbackLocale.

I think the default value should be null,

https://github.com/kazupon/vue-cli-plugin-i18n/blob/dev/ui.js#L136

additional[path] = null // set default

or in the file i18n.ts

messages[locale] = process.env.NODE_ENV !== 'production' &&  locales(key) || removeEmpty(locales(key));


// ....
// simple recursive remove keys with empty value
const removeEmpty = (obj: object | any): object =>
  Object.keys(obj)
    .filter((k: string) => obj[k] !== null && obj[k] !== undefined && obj[k] !== '') // Remove undef. and null and empty.string.
    .reduce(
      (newObj, k) =>
        typeof obj[k] === 'object'
          ? Object.assign(newObj, { [k]: removeEmpty(obj[k]) }) // Recurse.
          : Object.assign(newObj, { [k]: obj[k] }), // Copy value.
      {},
    );

I can do a PR if agreed

pikax avatar Sep 13 '18 08:09 pikax