Replies: 2 comments 2 replies
-
So you basically want to make this work for single page apps ? I don't see how that would work with astro. I did think of making a common i18n logic package that astro-i18n or other frameworks could implement. I'm currently in early development of version 2.0 so maybe I can think about client-side but for now I don't really see the point. |
Beta Was this translation helpful? Give feedback.
-
I just finished adding this feature to the version 2.0 (unreleased at the moment). Translations are now divided into groups: common translations, page-specific translations, grouped translations. As for routing, all the route segment translations get serialized into the HTML, because of this hidden endpoints should not be added to the astro-i18n (I might add some kind of server-only route segment translations feature later on). |
Beta Was this translation helpful? Give feedback.
-
Hi, first of all thank you for the high quality translation library, Alexandre. I see a point of pride is "built for Astro and nothing else." Nevertheless, I'd like to ask about or propose an isomorphic versions of this library's translation functions. By "isomorphic" I mean something that works both in the Astro server context and the browser context, meaning framework components like Vue, React, Solid, etc.
Right now astro-i18n is server only and doesn't work in framework components in the browser. You can't do
import { t } from 'astro-i18n'
in a Vue component, for example. I wrestled with a different translation library (vue-i18n) that happens to use the same JSON files but it had the opposite problem, failing to render on the server. AFAICT astro-i18n is closer to implementing browser compatibility than vue-i18n is to fixing SSR. It would be better to have a single awesome translation library that works with many frameworks. I cobbled together some code that used a dynamic import on the server and fetch on the client. Without access to the current locale during SSR, Astro just loaded English and then Vue complained about a hydration mismatch for all other languages.Ultimately, I want to put JSON translation files in the
/public
directory and use at()
function that works in static and dynamic Astro components and also client-side framework components. What if the astro-i18n configuration could specify either a file location or a URL to load at runtime, or maybe a load callback function? Is this already possible somehow? If not, would you consider this feature worthwhile?Beta Was this translation helpful? Give feedback.
All reactions