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

I am not able to load a js file in locale that contains other attached json files. #2950

Open
joaquinCaceres opened this issue May 17, 2024 · 1 comment

Comments

@joaquinCaceres
Copy link

Environment


  • Operating System: Linux
  • Node Version: v20.2.0
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: npm@9.6.7
  • Builder: -
  • User Config: devtools, modules, i18n
  • Runtime Modules: @nuxtjs/i18n@8.3.1
  • Build Modules: -

Reproduction

.

Describe the bug

I'm trying to config a locale whose file is a javascript file that return a object. if the dictionary is simple like {‘title’: ‘about’, ‘data’: ‘the data’} everything works correctly and I can access those values via $t(title) without problems. However, if the dictionary includes other elements imported from other js files, I am not able to access them.

The configuration of my environment is as follows:

NUXT.CONFIG.TS:

export default defineNuxtConfig({
devtools: { enabled: true },
modules: ["@nuxtjs/i18n"],
i18n: {
lazy: true,
langDir: "./locales",
strategy: 'prefix_and_default',
locales: [
{
code: "en",
name: "English(US)",
file: "en/index.js",
},
{
code: "es",
name: "Español",
file: "es/index.js",
},
],
defaultLocale: "es",
}
})

INDEX.JS

import portfolioMain from './pages/portfolioMain'
import blogMain from './pages/blogMain'

export default {
portfolioMain,
blogMain,
"section-name": "about me"

}

PORTFOLIOMAIN.JS

export default {
title: 'the house'
}

In this configuration, I can access to section-name without problems. Could I help me, please? My intention is to have the files as tidy as possible within the directory

Additional context

No response

Logs

WARN  [intlify] Not found 'portfolioMain.title' key in 'es' locale messages.
@dawid-ziobro
Copy link

Hi @joaquinCaceres I've had the same issue. Try using defineI18nLocale function in your translation file.

So instead of this:

export default {
portfolioMain,
blogMain,
"section-name": "about me"
}

do this:

export default defineI18nLocale(() => {
  portfolioMain,
  blogMain,
  "section-name": "about me"

});

You can read more about that here -> https://i18n.nuxtjs.org/docs/guide/lazy-load-translations

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

No branches or pull requests

2 participants