From the code I’ve read it should be by their identify for example http://localhost:4321/en/
for English.
That’s what I’ve been trying based on this: feat: i18n by mrshmllow · Pull Request #3 · auxolotl/website · GitHub, but given that I keep getting 404’s I’m guessing some type of redirect is missing - perhaps specifically from the dev mode?
taking a look into how i18n works for astro. Gimme a few moments.
Ok, I’ve done some digging @AngryAnt, there’s a couple of steps.
- In
src/pages
create a directory named the 2 letter code of the language (eg: french would befr
). - Copy and paste the index.astro file into the directory (it can stay unmodified).
- In
public/locales
create a directory named the same 2 letter code as earlier. - Copy
public/locales/en/translations.json
into the directory you just made. - Add the language in
src/i18n/ui.ts
in the same way English is added. - Do your translations.
There may be a way to do this with dynamic routing, but since Astro needs to build everything to static I’ll have to do some more research on that. This way is fine for now.
Excellent! I have it working. Notes for others:
- Remember to prefix all the imports in
index.astro
now that you have copied the file up one level. - Modified
ui.ts
looks something like this:
import en from "../../public/locales/en/translations.json"
import dk from "../../public/locales/dk/translations.json"
export const languages = {
en: 'English',
dk: 'Danish'
};
export const defaultLang = 'en';
export const ui = {
en,
dk
} as const;
I take it that for the PR I’ll not commit the duplicate index.astro
?
Looks great. You should be committing one additional index.astro
for the PR. I’ll work on adding the dynamic routing later.
Hello everyone! I will try and add a language switcher soon.
Add the language in src/i18n/ui.ts in the same way English is added.
Also, you need to make sure the name of the language is in that language. For example French becomes Français.
I’m currently translating strings to Spanish and I’m having some trouble with certain tech specific terms. How would you think the verb “to fork” should be translated?
This is probably better off at the PRs of the website but I think it’s to soon to move it there.
Ready for review
With these translations we are already providing a more accessible project than NixOS, believe it or not! I can’t seem to find any internationalization infrastructure for the NixOS site or its documentation. This is a pretty big deal, we are already beginning to fill a void and bring the project within reach of more people!
Nice work. I dropped some quick comments and it gave me the push I needed to wrap up content completion: translations: init danish by AngryAnt · Pull Request #14 · auxolotl/website · GitHub
I got started on the german translation, but it’s very early stage right now