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
524 stars 37 forks source link

Generate folder for default language #142

Open dmitryuck opened 1 year ago

dmitryuck commented 1 year ago

Describe the bug

npx astro-i18next generate command generates folders for all languages but defaultLocale

Expected behavior

I believe better to generate folder for default locale also

defaultLocale: 'en' locales: ['en', 'fr']

in this case, only pages/fr is generated

but when user put url directly in the browser for e.x.

https://site.com/en

we have an 404 error - page not found,

from root index.astro we can remove changeLanguage("en"); and do not patch user files, instead use dafault locale, when open on / so from pages/index.astro we can show defaultLocale content when a language is set in url - from generated folder "pages/en" or "pages/fr"

Context (please complete the following information):

dmitryuck commented 1 year ago

also this will make pages folder structure clear for ex, we have a structure like pages/blog/index.astro when we look at pages folder it confusing is it generated or my created files when it will put generated files in 'en' or 'fr' folder is more clear I do not need to touch these files since they are generated by i18next plugin

fabien-roy commented 1 year ago

+1 for this, because generation overrides source files, which is a bummer

bmenant commented 1 year ago

It really comes with trouble when showDefaultLocale is enabled:

{
  defaultLocale: 'en',
  locales: ['en', 'fr'],
  showDefaultLocale: true,
}

localizePath('/about') gives /en/about which turns out to be a broken link since /en/about.astro isn’t generated.

Foxandxss commented 1 year ago

It really comes with trouble when showDefaultLocale is enabled:

{
  defaultLocale: 'en',
  locales: ['en', 'fr'],
  showDefaultLocale: true,
}

localizePath('/about') gives /en/about which turns out to be a broken link since /en/about.astro isn’t generated.

Agreed.

Is there any solution to this?

vjandrei commented 1 year ago

I have issue that npx astro-i18next generate does not create folders at all.

import type { AstroI18nextConfig } from "astro-i18next";

const config: AstroI18nextConfig = {
  defaultLocale: "fi",
  locales: ["fi", "en"],
  showDefaultLocale: false,
  i18nextServer: {
    returnObjects: true,
  },
  namespaces: [
    "lunchlist"
  ]
};

export default config;