Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trans doesn't call parseMissingKeyHandler #1354

Closed
igorsantos07 opened this issue Aug 6, 2021 · 6 comments
Closed

Trans doesn't call parseMissingKeyHandler #1354

igorsantos07 opened this issue Aug 6, 2021 · 6 comments

Comments

@igorsantos07
Copy link

馃悰 Bug Report

Common t() calls with missing keys go through parseMissingKeyHandler if that's defined, but Trans doesn't, what feels like inconsistent/unexpected behavior.

To Reproduce

I created a single sandbox for multiple issues I'm reporting, so it's a bit bigger than expected, sorry :)

Expected behavior

Trans should also go through parseMissingKeyHandler? Or should it go somewhere else? I tried the missingInterpolationHandler, to no avail as well.

Your Environment

  • runtime version: React 17, Chrome 91
  • i18next version: 20.3.5 (installed last week?)
  • react-i18next version: 11.11.4
  • os: Linux
@jamuhl
Copy link
Member

jamuhl commented Aug 6, 2021

Never requested by devs to have that option -> so it's not added. We add features needed not just to be consistent with other calls -> Trans is a completely different beast (so there is no need to compare it to the API call of a simple t call).

So, yes...can be added - if someone needs it...but I won't add lines just to have them...save the bytes

@jamuhl jamuhl closed this as completed Aug 6, 2021
@adrai
Copy link
Member

adrai commented Aug 6, 2021

fyi: seems it is not directly because of Trans, but because of the defaultValue usage...
i.e. i18n.t('keyWithDefault', 'some default')

this would fix it: https://github.com/i18next/i18next/blob/master/src/Translator.js#L273
image

@jamuhl
Copy link
Member

jamuhl commented Aug 6, 2021

@adrai lgtm

@adrai
Copy link
Member

adrai commented Aug 6, 2021

@igorsantos07 will be fixed in the next i18next version: i18next/i18next@da47faa

@kg-currenxie
Copy link

kg-currenxie commented Feb 7, 2022

Hope its OK to borrow this thread (if not I can make a new issue)

We have a case like this

<Text text={t('.placeholder', { defaultValue: '' })} />

We have a generated form, where translation might, or might not be defined. So we'd like to just print nothing.

This commit/release (20.4.0) changes this behavior, and it will now look for the translation key '' instead.
Seems a bit strange to me, as its named defaultValue and not like defaultKey or fallbackKey, a feature already available if you use t(['key1', 'fallback'])

Is this intended? Feels more like a breaking change imo. If yes, how can i fall back to a string, and not a translation?
(We don't want to define translations with empty string values)

Update:
This is part of the config:

          parseMissingKeyHandler: (key: string) => {
            if (isDevelopment) {
              console.log(`Translation for key '${key}' is missing`)
            }
            return `[[MISSING KEY: ${key}]]`
          },

Screenshot 2022-02-07 at 11 39 40

Update 2:
Documentation says

parseMissingKeyHandler:

function(key) { // return value to display }

@adrai
Copy link
Member

adrai commented Feb 7, 2022

@kg-currenxie Please create a reproducible example and open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants