#Problem with translation module.

34 messages · Page 1 of 1 (latest)

stark raft
#

WARNING(astro-i18next): missing translation key component.header.leaderboard.

My translation file.

{
  "site": {
    "title": "My awesome website!",
    "description": "Here is the description of my awesome website!"
  },
  "home": {
    "title": "Welcome to my awesome website!",
    "subtitle": "This is a <0>more complex</0> string to translate, mixed with <1>html elements</1>, such as a <2>a cool link</2>!"
  },
  "component": {
    "header": {
      "earn": "Earn",
      "leaderboard": "Leaderboard"
    }
  }
}
#

I'm suppose to put astro-i18next.config.mjs in root, right?

#

Please ping me if you can help.

hollow otter
#

Hi @stark raft, my name is Alexander Lill and I am a researcher at the University of Zurich trying to help people find answers on Discord faster.

Based on your question, I figured that the following suggested links could be helpful. If you are okay with checking my suggestions for answering your question and giving feedback, please continue reading.

If not, you can opt-out by clicking the ❌ symbol below, and I will immediately delete this message and my suggestions, and apologize for the disturbance.

#

Could you please go through the suggested links below and comment or react with the number of the first suggestion that was helpful for answering your question? In case none of the suggestions was helpful, please react with the number 0.

1️⃣ Trying to do translation (/localization) with i18n and am struggling to implement it without making a mess of my codebase.
https://discord.com/channels/830184174198718474/1017099338725466232

2️⃣ trying to import simple object in astro config mjs but I am getting the error: Error [ERR_MODULE_NOT
https://discord.com/channels/830184174198718474/1013465224092848138

3️⃣ how do i handle localization within my astro website (i18n)?
https://discord.com/channels/830184174198718474/985190038289653780

More information about the study can be found here: https://hasel.dev/study-discord-suggestions/. You can DM me any time in case of questions.

tribal tusk
hollow otter
stark raft
hollow otter
#

@stark raft have you tried it without the "component" sub-key (so move "header" one level up in the translations file)?

stark raft
#

Okay, I put test key at top level. And translated with the t function, like this i18next.t("test")

#

It doesn't work.

warm comet
#

@stark raft missing translation key means i18next cannot find the translation key from the target translation file.
You need to provide/check these information:

  1. current language -> translation file
  2. astro-i18next config. -> to make sure translation files are loaded properly.
  3. Make sure you restarted the dev server each time changing translation.
  4. Code snippets where you called translation function.
    Check out this for reference: https://github.com/ansidev/astro-i18next-example-ssg
GitHub

Astro I18next SSG. Contribute to ansidev/astro-i18next-example-ssg development by creating an account on GitHub.

stark raft
#

My config looks like this.

/** @type {import('astro-i18next').AstroI18nextConfig} */
export default {
  defaultLocale: "en",
  locales: ["en", "es"],
};
warm comet
#

So what is the astro-i18next version? Where is the locales folder? By default, it is public/locales

stark raft
#

Also have the react version installed

#

And yes the translations are in /public/locales

stark raft
warm comet
#

Enabling debug option can help you to collect more information

stark raft
#

i18next::translator: missingKey en translation test test

#
i18next::backendConnector: loading namespace translation for language en failed Error: ENOENT: no such file or directory, open '/D:/Github/Repositories/BucksBoost/client/public/locales/en/translation.json'
    at Object.openSync (node:fs:600:3)
    at Object.readFileSync (node:fs:468:35)
    at readFileInNodeSync (D:\Github\Repositories\BucksBoost\client\node_modules\i18next-fs-backend\cjs\readFile.js:22:17)
    at readFileSync (D:\Github\Repositories\BucksBoost\client\node_modules\i18next-fs-backend\cjs\readFile.js:127:16)
    at Backend.read (D:\Github\Repositories\BucksBoost\client\node_modules\i18next-fs-backend\cjs\index.js:61:58)
    at Connector.read (D:\Github\Repositories\BucksBoost\client\node_modules\i18next\dist\cjs\i18next.js:1804:14)
    at Connector.loadOne (D:\Github\Repositories\BucksBoost\client\node_modules\i18next\dist\cjs\i18next.js:1847:12)
    at D:\Github\Repositories\BucksBoost\client\node_modules\i18next\dist\cjs\i18next.js:1824:16
    at Array.forEach (<anonymous>)
    at Connector.prepareLoading (D:\Github\Repositories\BucksBoost\client\node_modules\i18next\dist\cjs\i18next.js:1823:21) {
  errno: -4058,
  syscall: 'open',
  code: 'ENOENT',
  path: '/D:/Github/Repositories/BucksBoost/client/public/locales/en/translation.json'
}
#

The file exists.

#

I can CTRL + Click on it and it takes me to the file

#

For some reason i18next can't find it.

#

My Astro config btw.

warm comet
#

IMO, the possible solution might be downgrade to beta 13

stark raft
#

TY

#

It works now!

#

W Support

hollow otter
#

Thank you for your feedback @stark raft and sorry the links were not helpful!

Are you available for a short follow-up survey on your experience with the suggestions and your technical background (max. 10 mins)? Your feedback would help our research a lot. For your efforts, you will be entered in a raffle for an Amazon gift card of USD 100 value (in case you want to).

To participate in the survey, please click on the link and follow the instructions there: https://uzhwwf.qualtrics.com/jfe/form/SV_9ZC7pmLXkxeMPrw?Q_CHL=gl&Q_DL=nRTuryr8hpE8ID9_9ZC7pmLXkxeMPrw_CGC_gXXrXsIXvLsmJq6 (your responses will be treated confidentially)