# Localisation guide

This guide shows how to choose the player's language from the SDK, keep English as the fallback and avoid the layout and font problems translations cause. English is required for every visible string. Extra languages are welcome and help the game reach more players, but they never replace English. Examples assume `const SDK = window.ZokoGames.SDK;` and `await SDK.init();` as in the [SDK introduction](https://docs.zokogames.com/sdk/introduction#loading); unfamiliar terms are in the [glossary](https://docs.zokogames.com/getting-started/glossary).

## Pick the language

`SDK.user.systemInfo.locale` is a BCP 47 language tag (a language code such as `"de"`, optionally with a region such as `"pt-BR"`). Inside the portal it is the language the player chose for the **portal's own pages**, not the browser language. The portal currently offers: `en`, `nl`, `it`, `es`, `id`, `fr`, `pt-BR`, `ru`, `uk`, `nb` (Norwegian), `ro`, `fi`, `sv`, `da`, `cs`, `hu`, `tr`, `ar`, `vi`, `th`, `ko`, `ja`, `pl`, `el` and `de`, so a Japanese-speaking player on the English site gets `"en"`. `countryCode` is an ISO country code such as `"BR"`, taken from the request. Read both after `await SDK.init()`; `systemInfo` is synchronous but throws `sdkDisabled` when the SDK is disabled, hence the guard below.

```js
const SDK = window.ZokoGames.SDK;
await SDK.init();

const SUPPORTED = ["en", "es", "pt", "de", "fr"];

function pickLanguage() {
  const raw = SDK.environment !== "disabled" ? SDK.user.systemInfo.locale : navigator.language;
  const base = String(raw).toLowerCase().split("-")[0];
  return SUPPORTED.includes(base) ? base : "en";
}
const lang = pickLanguage();
```

Rules:

- Decide the language **automatically**. Do not make players choose before they can play. A small language switch in settings is fine.
- Always fall back to English, for the whole game and for any single missing string.
- In local mode (your own `localhost` page) the locale is your browser's language and the country is always `"US"`. Change the browser language to test, or force a language with your own query parameter (for example `?lang=de` read by your code).
- Guests, ad-blocked and offline players get the same locale; it is a property of the portal page, not of the account.
- The [Preview tool](https://www.zokogames.com/preview) shows what the portal reports to the game.

## Keep strings out of code

```js
const STRINGS = {
  en: { play: "Play", gameOver: "Game over", score: "Score: {n}" },
  es: { play: "Jugar", gameOver: "Fin del juego", score: "Puntos: {n}" },
};

function t(key, vars = {}) {
  const table = STRINGS[lang] ?? STRINGS.en;
  const raw = table[key] ?? STRINGS.en[key] ?? key;
  return raw.replace(/\{(\w+)\}/g, (_, k) => String(vars[k] ?? ""));
}
```

- Use named placeholders (`{n}`), never string concatenation. Word order differs between languages.
- Use `Intl.NumberFormat(locale)` and `Intl.DateTimeFormat(locale)` for numbers and dates.
- Use `Intl.PluralRules(locale)` for plurals; many languages have more than two forms.
- Load only the language you need, so translations do not grow the initial download.

## Layout and fonts

- Text expands: German and Finnish are often 30 percent longer than English. Size buttons from their content and test with the longest language.
- Right-to-left languages (Arabic, Hebrew) need mirrored layout and `dir="rtl"`. Only ship them when you have tested them.
- Pick a font that covers your scripts. A pixel font with only Latin glyphs shows empty boxes for Cyrillic or CJK. Subset fonts to keep them small.
- Do not bake text into images. Put it in a text layer so it can be translated.

## Engines

- **Unity:** the Localization package or your own table; read the locale from the wrapper's system info before the first scene loads.
- **Godot:** `TranslationServer.set_locale()` with the SDK locale.
- **Construct 3:** a language object or the Localization plugin.
- **Phaser and library games:** your own table as above.

See the [engine pages](https://docs.zokogames.com/engines/overview) for how each wrapper exposes `systemInfo`.

## Listing text

The title, descriptions and controls you enter in the console are in English. Make sure the in-game controls text matches the description. Other languages inside the game do not need separate listing text.

## Checklist

- [ ] Every visible string, including errors and the tutorial, exists in English.
- [ ] Language is chosen from `systemInfo.locale` with an English fallback.
- [ ] Longest translation still fits every button.
- [ ] Fonts contain the glyphs for each shipped language.
- [ ] No language prompt blocks the first play.

## Next steps

- [Gameplay requirements](https://docs.zokogames.com/requirements/gameplay)
- [Mobile, touch and orientation](https://docs.zokogames.com/guides/mobile)
