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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lastused can not work with locize saveMissing properly #5

Open
jindong-y opened this issue Mar 15, 2023 · 1 comment
Open

Lastused can not work with locize saveMissing properly #5

jindong-y opened this issue Mar 15, 2023 · 1 comment
Assignees

Comments

@jindong-y
Copy link

🐛 Bug Report

If I use lastUsed and savsMissing=ture at same time (using locize backend), translation can not work properly. When I tried to switch local, no translation shows. Only the default local will be shown, translations of the other locals are not shown. I looked at logs and network and it seems that it didn't try to fetch the translation.

If i use either lastUsed or locize saveMissing alone, it works with no problem.

To Reproduce

I used the example repo to reproduce it.

next-i18next.config.js file:

module.exports = {
  debug: true,
  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'zh'],
  },
  backend: {
    backendOptions: [{
      expirationTime: 1 // 1s
    }, {
      projectId: 'id',
      apiKey: 'key',
      version: 'latest'
    },

      ],
    backends: isBrowser ? [LocalStorageBackend, LocizeBackend,] : [],
  },
  locizeLastUsed:{
    projectId: 'id',
    apiKey: 'key',
    version: "latest",
    debounceSubmit: 90000,
    referenceLng: "en",
  },
  serializeConfig: false,
  use: isBrowser ? [ChainedBackend, LocizeLastused] : [],
  saveMissing: true
}

Expected behavior

Translation of all locals can be displayed.

Your Environment

"i18next": "22.4.9",
    "i18next-chained-backend": "4.2.0",
    "i18next-localstorage-backend": "4.1.0",
    "i18next-locize-backend": "6.2.1",
    "locize-lastused": "^3.1.1",
    "next": "13.1.6",
    "next-i18next": "13.1.5",
  • runtime version:node v16.15.0, Chrome Version 111.0.5563.64 (Official Build) (x86_64)
  • os: Mac
@adrai adrai self-assigned this Mar 15, 2023
@adrai
Copy link
Contributor

adrai commented Mar 15, 2023

Just tested with this config:

const isBrowser = typeof window !== 'undefined'

module.exports = {
  debug: process.env.NODE_ENV === 'development',
  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'de'],
  },
  backend: {
    backendOptions: [{
      expirationTime: 10 // 1 hour
    }, {
      projectId: 'd3b405cf-2532-46ae-adb8-99e88d876733',
      apiKey: 'my-key',
      version: 'latest'
    }],
    backends: isBrowser ? [LocalStorageBackend, LocizeBackend] : [],
  },
  serializeConfig: false,
  use: isBrowser ? [ChainedBackend, require('locize-lastused')] : [],
  locizeLastUsed: {
    projectId: 'd3b405cf-2532-46ae-adb8-99e88d876733',
    apiKey: 'my-key,
    version: 'latest',
    debounceSubmit: 10000
  },
  saveMissing: process.env.NODE_ENV === 'development' && isBrowser // do not set saveMissing to true for production and also not when using the chained backend
}

Seems to work as expecetd:
image
image
image

Maybe in your project the saveMissing request is not done anymore, because the key is not missing anymore? It may be it is saved in your local json files on server side?

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

2 participants