yassinedoghri / astro-i18next

An astro integration of i18next + some utility components to help you translate your astro websites!
https://astro-i18next.yassinedoghri.com
MIT License
511 stars 36 forks source link

1.0.0 beta 14 breaks loadPath #79

Closed fmilioni closed 1 year ago

fmilioni commented 1 year ago

After this commit all my keys returns default untranslated string.

The temporary workaround that works for me is this snippet bellow:


/** @type {import('astro-i18next').AstroI18nextConfig} */
export default {
  ...
  i18nextServer: {
    backend: {
      loadPath: "./public/locales/{{lng}}/{{ns}}.json",
    },
  },
};

My config file (works fine in beta 13, but not in 14)

/** @type {import('astro-i18next').AstroI18nextConfig} */
export default {
  namespaces: ["common", "footer", "nav"],
  defaultNamespace: "common",
  defaultLocale: "en",
  locales: ["en", "pt", "vi"],
  showDefaultLocale: true
};

My page

Path: src/pages/[lang]/index.astro

💡 The reason I made a path that way is precisely because it is not possible to use the generate command with showDefaultLocale set to true. It just doesn't extract anything, so the alternative was to create a folder with lang as param and manually set it inside the page (since this is a small project with only one page anyway)

---
import i18n from "i18next";

import MainLayout from "@layouts/MainLayout.astro";

// ....

export function getStaticPaths() {
  return [{ params: { lang: "en" } }, { params: { lang: "pt" } }, { params: { lang: "vi" } }];
}

const { lang } = Astro.params;
i18n.changeLanguage(lang as string);
---

<MainLayout>
  <p>{i18n.t('example')}</p>
  <!-- all contents -->
</MainLayout>
yassinedoghri commented 1 year ago

Hey @fmilioni, I guess you are on Windows, right?

florian-lefebvre commented 1 year ago

Hey @yassinedoghri I can confirm this issue on Windows. The path generated is /D:/somepath instead of D:/somepath. https://github.com/unjs/pathe works well for path normalization across OSs (used in nuxt3)

zogar1993 commented 1 year ago

+1 to having this issue on Windows. The proposed workaround works fine tho.

fmilioni commented 1 year ago

Hey @fmilioni, I guess you are on Windows, right?

Sorry for late response, and yes, Windows 11. My project is located in D: partition.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 1.0.0-beta.15 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Silbad commented 1 year ago

Hello, Should the configuration be changed accordingly? I still have the bug on the beta 15 version...

/** @type {import('astro-i18next').AstroI18nextConfig} */
export default {
    defaultLocale: "fr",
    locales: ["fr", "en"],
    showDefaultLocale: true,
};

No issue on beta 13