Git Product home page Git Product logo

Comments (3)

adrai avatar adrai commented on June 13, 2024

documented here: https://www.i18next.com/principles/fallback#key-fallback

what what you are referring to with $t(variable) is nesting: and is documented here: https://www.i18next.com/translation-function/nesting and works like that as expected

from i18next.

zemlint avatar zemlint commented on June 13, 2024

Thanks for the quick answer!

Still I am confused why skipOnVariable: true does not work for the fallback. In the linked documentation
i18next.t('notExistingKey'); // -> "notExistingKey"
is written as an example for when the key is not found.
That is why I would expect
i18next.t("Not a key $t(variable)"; // -> "Not a key $t(variable)" instead of
i18next.t("Not a key $t(variable)"; // -> "Not a key Hello World!"
when skipOnVariable: true

Is this wrong and I can't enable skipOnVariable for the fallback?

from i18next.

adrai avatar adrai commented on June 13, 2024
const i18next = require('i18next')
i18next.init({
  lng: 'en',
  // interpolation: { // skipOnVariables by default true
  //   skipOnVariables: false
  // },
  resources: {
    en: {
      translation: {
        keyWithNesting: 'gets nested: $t(nested) | this is a variable: {{variable}}',
        anotherKey: 'value {{variable}}',
        nested: 'this is a nested key'
      },
    },
  },
})

console.log(i18next.t('anotherKey'))
console.log(i18next.t('anotherKey', { variable: 'whatever' }))

console.log(i18next.t('keyWithNesting', { variable: '$t(nested2)' }))

console.log(i18next.t('Not a key $t(anotherKey) | {{variable}}'))
console.log(i18next.t('Not a key $t(anotherKey) | {{variable}}', { variable: '$t(nested)' }))

with skipOnVariables: true (default), you will see this output:

value {{variable}}
value whatever
gets nested: $t(nested) | this is a variable: $t(nested2)
Not a key value {{variable}} | {{variable}}
Not a key $t(anotherKey) | $t(nested)

with skipOnVariables: false, you will see this output:

value
value whatever
gets nested: this is a nested key | this is a variable: nested2
Not a key value  |
Not a key value this is a nested key | this is a nested key

You see skipOnVariables only influences the nesting resolving behaviour if passed via variable...

everything that you pass to the t function is handled the same way, it doesn't matter if it is a known key or an not existing key...

so it works as designed

from i18next.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.