Files
overextended.github.io/pages/ox_lib/Modules/Locale/Shared.mdx
T
Jag 74227cc262 chore: oxmysql and ox_lib clean-up (#134)
* oxmysql and some lib interface fixes

- Various fixes throughout oxmysql
- started ox_lib audit

* chore: More clean up

- Reword some confusing descriptions
- Add some descriptions
- Type fixes
- Spelling and grammar fixes
- Swapping in `-` where `*` used to be for 
bullet point consistency

ox_lib
- Interface, ACL through GetClosestVehicle audited

* chore: Finishing up ox_lib
2023-07-03 13:13:56 +10:00

79 lines
1.6 KiB
Plaintext

Allows servers to set a preferred language and attempt to load locale files in any resources using the module.
Locale files should use the [ISO Language Code](http://www.lingoes.net/en/translator/langcode.htm) and be saved as `./locales/langcode.json`
## Setup
To change the preferred language from English, add the convar to your server.cfg and change `en` to the desired language code.
```yaml
setr ox:locale en
```
Create a locales directory and a file for your language.
```json filename="locales/en.json"
{
"grand_theft_auto": "grand theft auto",
"male": "male",
"female": "female",
"suspect_sex": "suspect is %s"
}
```
```json filename="locales/fr.json"
{
"grand_theft_auto": "vol de voiture",
"male": "homme",
"female": "femme",
"suspect_sex": "le suspect est %s"
}
```
```lua filename="fxmanifest.lua"
files {
'locales/*.json'
}
```
## Usage
Initialise the locale module in your resource (once).
```lua
lib.locale()
```
Format your strings with the new locale global.
Additional arguments can be sent to format the locale output.
```lua
locale(str, ...)
```
- str: `string`
- vararg?: `string` or `number`
```lua
-- Load the locale module
lib.locale()
SetInterval(function()
print(locale('grand_theft_auto'))
print(locale('suspect_sex', locale('male')))
end, 5000)
```
## Phrases
You can create a locale string that references other locales to construct a phrase, rather than calling locale multiple times.
```json
{
"hello": "hello %s",
"my_name_is": "my name is %s",
"hello_my_name_is": "${hello}! ${my_name_is}."
}
```
```lua
print(locale('hello_my_name_is', 'doka', 'linden'))
```