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

Not found when i add backend option #162

Open
VigilioYonatan opened this issue Aug 23, 2023 · 1 comment
Open

Not found when i add backend option #162

VigilioYonatan opened this issue Aug 23, 2023 · 1 comment

Comments

@VigilioYonatan
Copy link

When i add backend option not found translation in express but zod translate zod found but when i remove resources option, translation it found. How can i fix it?

import i18next from "i18next";
import i18nextMiddleware from "i18next-http-middleware";
import i18nextBackend from "i18next-node-fs-backend";
import { setErrorMap, z } from "zod";
import { zodI18nMap } from "zod-i18n-map";
import translation from "zod-i18n-map/locales/es/zod.json";
import path from "path";
// lng and resources key depend on your locale.

i18next
    .use(i18nextBackend)
    .use(i18nextMiddleware.LanguageDetector)
    .init({
        // debug: true,
        lng: "es-ES",
        fallbackLng: "en-US",
        preload: ["en-US", "es-ES"],
        resources: {
            es: { zod: translation },
        },
        backend: {
            loadPath: path.resolve(
                __dirname,
                "..",
                "lang",
                "{{lng}}",
                "{{ns}}.json"
            ),
        },
        detection: {
            caches: ["cookie"],
        },
    });

setErrorMap(zodI18nMap);
@jurajkrivda
Copy link

jurajkrivda commented Aug 29, 2023

const resources = languages.reduce(
  (acc, lang) => {
    acc[lang.key] = { zod: lang.zod }
    return acc
  },
  {} as Record<string, { zod: (typeof languages)[0]['zod'] }>,
)

export const i18n = {
  supportedLngs: languages.map(lang => lang.key),
  fallbackLng: 'en',
  defaultNS: 'common',
  nsSeparator: '::',
  react: { useSuspense: false },
  partialBundledLanguages: true,
  resources,
  debug: false,
}

Note: partialBundledLanguages must be set to true

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