# i18n `[Shared]`

i18n module is a specialized tool for internationalization within RedM.

## Setup

Create a `locales` folder in your resource and add your locale files there.
::: code-group
```lua [locales/en.lua]
return {
    "helloWorld": "Hello World",
    "goodbyeWorld": "Goodbye World"
}
```
```lua [locales/fr.lua]
return {
    "helloWorld": "Bonjour le monde",
    "goodbyeWorld": "Au revoir le monde"
}
```
:::

Load them in your fxmanifest.lua:
::: code-group
```lua [fxmanifest.lua]
files {
    "locales/*.lua"
}
```

Done, you're all set!
:::

## Configuration Variables (Convars)

| Convar | Side | Type | Default | Description |
|--------|------|------|---------|-------------|
| `jo_libs:i18n:allowSwitchLocale` | `[Client]` | String | `true` | Allow switching locale |
| `jo_libs:i18n:localeCommand` | `[Client]` | String | `setLocale` | Command to switch locale |
| `jo_libs:i18n:locale` | `[Shared]` | String | `en` |  |

## JO Functions

### jo.i18n.__()

Translate a key <br>

#### Syntax

```lua
jo.i18n.__(key)
```

#### Parameters

`key` : _string_
> The key to translate
>

#### Return Value

Type : _string_

> The translated key

---

### jo.i18n.addEntries()

Add multiple entries to the i18n dictionary <br>

#### Syntax

```lua
jo.i18n.addEntries(entries)
```

#### Parameters

`entries` : _table_

> The entries to add
>

---

### jo.i18n.addEntry()

Add a single entry to the i18n dictionary <br>

#### Syntax

```lua
jo.i18n.addEntry(key, value)
```

#### Parameters

`key` : _string_
> The key to add
>

`value` : _string_
> The value to add
>

---

### jo.i18n.findMissingKeys()

Find missing keys in a locale <br>

#### Syntax

```lua
jo.i18n.findMissingKeys(locale)
```

#### Parameters

`locale` : _string_
> The locale to check
>

---

### jo.i18n.getEntries()

Get all entries <br>

#### Syntax

```lua
jo.i18n.getEntries()
```

#### Return Value

Type : _table_

> The entries

---

### jo.i18n.getLocale()

Returns the current locale <br>

#### Syntax

```lua
jo.i18n.getLocale()
```

#### Return Value

Type : _string_

> The current locale

---

### jo.i18n.init()

Initialize the i18n module <br>

#### Syntax

```lua
jo.i18n.init()
```

---

### jo.i18n.loadLocale()

Load a locale <br>

#### Syntax

```lua
jo.i18n.loadLocale(locale)
```

#### Parameters

`locale` : _string_
> The locale to load
>

---

### jo.i18n.onLocaleChange()

Register a callback to be called when the locale changes <br>

#### Syntax

```lua
jo.i18n.onLocaleChange(callback, priority)
```

#### Parameters

`callback` : _function_
> The callback to register
>

`priority` : _number_
> The priority of the callback
>

---

### jo.i18n.setLocale()

Set the current locale <br>

#### Syntax

```lua
jo.i18n.setLocale(locale)
```

#### Parameters

`locale` : _string_
> The locale to set
>
