Skip to content

Add a site language

Follow these steps to add a new site language to your LightNet project:

  1. Identify the language code: Find the correct BCP-47 language code for your language, for example en for English or de for German. Tools like r12a Language Subtag Lookup can help you find the right code.
  2. Add the language to your config: Add the new language to the languages array in astro.config.mjs.
    astro.config.mjs
    export default defineConfig({
    integrations: [
    lightnet({
    languages: [
    {
    code: "de",
    label: {
    en: "German",
    de: "Deutsch"
    },
    isSiteLanguage: true
    },
    ],
    }),
    ],
    })
  3. Create a translations file: Add a file in src/translations named after your language code, for example src/translations/de.yml.
  4. Check built-in LightNet translations: Inspect LightNet’s built-in translations on GitHub and look for a file named [your-language-code].yml.
    • If no such file exists, LightNet does not yet provide built-in translations for that language.
    • If the file exists, check the translation status to see whether any keys are still missing.
  5. Add missing built-in translations to your project: If your language is not built in yet, or if the built-in translation file is incomplete, copy the missing keys from the English translation file into your project translation file and translate those values.
  6. Add your custom translation keys: If your project already uses custom translation keys in other locale files, add translated values for those keys to the new file as well.
  7. Set the default language if needed: Your site must have exactly one default site language. If the new language should become the default, add isDefaultSiteLanguage: true to that entry and remove isDefaultSiteLanguage from the current default language.
  8. Validate the new locale: Run npm run dev and check that the new language appears in the language selector. Switch to the new locale and verify that built-in strings, your custom translations, and language labels display correctly.
  9. Contribute upstream: If you translated missing LightNet built-in strings, consider sharing them through this translations update form.