i18next / i18next-scanner

Scan your code, extract translation keys/values, and merge them into i18n resource files.
http://i18next.github.io/i18next-scanner
MIT License
567 stars 128 forks source link

Trans component does not respect the defaultValue #104

Open mariakatsourani opened 5 years ago

mariakatsourani commented 5 years ago

Version

Configuration

{ 
    debug: true,
    sort: true,
    func: {
      list: ['i18next.t', 'i18n.t', 't'],
      extensions: ['.js', '.jsx']
    },
    trans: {
      component: 'Trans',
      extensions: ['.js', '.jsx'],
      defaultsKey: "-",
      fallbackKey: true,
    },
    removeUnusedKeys: true,
    lngs: ['en-us', 'sv-se'],
    defaultLng: 'en-us',
    defaultValue: function (lng, ns, key) {
      if (lng === 'en-us') {
        return key; // key as value for en-us
      }
      return ''; // empty for the rest
    },
    resource: {
      loadPath: 'src/locales/{{lng}}/{{ns}}.json',
      savePath: 'src/locales/{{lng}}/{{ns}}.json',
    },
    nsSeparator: false,
    keySeparator: false,
    interpolation: {
      prefix: '{{',
      suffix: '}}'
    }
}

Expected: to get an empty string in all languages other than English Result: the same english string is used in all languages

Here is a PR #103 where I 've added a failing test for this case.

daliusd commented 5 years ago

IMHO there should be separate option for Trans. E.g. I am not using natural keys and that means that defaultValue for t is preferred but defaultValue for Trans is not. If I were using natural keys I would like your desired behavior.

ramiel commented 5 years ago

Any news on this? I also think the defaultValue should be respected. If not any language will have a default value which is wrong (the english one) instead of the desired. Also, the fallbackKey option should only affect key, not values.

ramiel commented 5 years ago

I would be available to propose a PR but I need some guidance through the code, or at least to know where to look at.

LuisSaybe commented 3 years ago

Are there any updates for this?

JohnRDOrazio commented 1 year ago

I also have not succeeded in getting an empty defaultValue for languages other than English (or whatever the source language is set to). I've tried multiple ways, even using a customTransform, to no avail...