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

translation.json not hot reloading. need to restart astro dev #167

Open
sickerin opened this issue Jun 20, 2023 · 1 comment
Open

translation.json not hot reloading. need to restart astro dev #167

sickerin opened this issue Jun 20, 2023 · 1 comment

Comments

@sickerin
Copy link

This probably isn't a bug, just need some help, in case I may have set things up wrong. I currently have set up i18n according to the suggested recommendations in the README.md (A file I have ispublic/locales/en/translation.json). I'm using astrowind as my starter code, and it seems that whenever I make a change in translation.json the change is not reflected in the website even though I get this message [astro] update /public/locales/en/translation.json.

To see the changes I need to kill and rerun pnpm dev.

I'm using "astro-i18next": "1.0.0-beta.21",

@orditeck
Copy link

orditeck commented Jun 9, 2024

Here's a small integrations that might help:

astro-i18next-reloader.mjs, same dir as astro.config.mjs:

import { fileURLToPath } from "node:url";
import glob from "fast-glob";

export default function astroI18nextReloader() {
  return {
    name: "astro-i18next-reloader",
    hooks: {
      "astro:config:setup": async ({ command, config, addWatchFile }) => {
        if (command !== "dev") return;

        await glob(`**/*.json`, {
          cwd: fileURLToPath(config.publicDir),
        }).then((f) =>
          f.map((file) => {
            addWatchFile(new URL(`./${file}`, config.publicDir));
          })
        );
      },
    },
  };
}

eg:
astro.config.mjs:

import { defineConfig } from "astro/config";
import astroI18next from "astro-i18next";
import astroI18nextReloader from "./astro-i18next-reloader";

// https://astro.build/config
export default defineConfig({
  integrations: [
    astroI18next(),
    astroI18nextReloader(),
  ],
});

It's not perfect but it's enough for me so I thought I'd share.

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