> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/cas-advanced-hunting/localization.md).

# Localization

## Supported languages

| Code | Language | File             |
| ---- | -------- | ---------------- |
| en   | English  | `locales/en.lua` |
| tr   | Turkish  | `locales/tr.lua` |
| fr   | French   | `locales/fr.lua` |
| de   | German   | `locales/de.lua` |

## Adding a new language

1. **Create the language file** in `locales/` (e.g. `locales/es.lua`):

```lua
Locales["es"] = {
    open_hunting_menu = "Abrir menu de caza",
    cancel_contract = "Cancelar contrato",
    deliver_products = "Entregar productos",
    contract_completed = "Contrato completado! Ganaste $%d y %d XP",
    no_active_contract = "No tienes un contrato activo",
    track_found = "%s encontrado - %s - Calidad: %s",
    -- ...add every key from en.lua
}
```

2. **Register it** in `config.lua`:

```lua
Config.Languages = { ["en"] = "English", ["tr"] = "Turkce", ["fr"] = "Francais", ["de"] = "Deutsch", ["es"] = "Espanol" }
```

3. **Add a flag** to `nui/assets/flags/es.png` (32x32 or 64x64 PNG).
4. **Restart** the resource: `ensure cas-hunting`.

## Placeholders

Translations support `%s` (string) and `%d` (number):

```lua
contract_completed = "Completed! You earned $%d and %d XP"
-- GetLocaleForPlayer(src, "contract_completed", money, xp)
```

## Helper functions

```lua
-- Server: translation for a specific player
local msg = GetLocaleForPlayer(source, "key_name", arg1, arg2)

-- Client: translation in the current language
local msg = GetLocale("key_name")
local msg2 = GetClientLocale("contract_completed", 150, 25)
```

## NUI translations

The NUI receives strings via `localeStrings`:

```lua
SendNUIMessage({ action = "setLanguage", language = "es", localeStrings = Locales["es"] })
```

Accessed in JS as `window.localeStrings?.some_key || "Default Text"`.

## Best practices

* Always provide fallbacks: `Locales[lang][key] or Locales["en"][key] or key`.
* Keep the same placeholder order across languages.
* Test with `/resetlang`; missing keys fall back to English.
