i18next-scanner icon indicating copy to clipboard operation
i18next-scanner copied to clipboard

Trans component does not respect the defaultValue

Open mariakatsourani opened this issue 5 years ago • 5 comments

Version

  • i18next: 11.6.0
  • i18next-scanner: 2.6.5

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.

mariakatsourani avatar Oct 04 '18 09:10 mariakatsourani

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.

daliusd avatar Nov 15 '18 12:11 daliusd

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 avatar Aug 05 '19 10:08 ramiel

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.

ramiel avatar Aug 06 '19 09:08 ramiel

Are there any updates for this?

LuisSaybe avatar Feb 22 '21 16:02 LuisSaybe

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...

JohnRDOrazio avatar Jun 13 '23 20:06 JohnRDOrazio