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 (opens in a new tab) and be saved as ./locales/langcode.json
Setup
To change the preferred language from English, add the convar to your server.cfg
setr ox:locale en
Create a locales directory and a file for your language.
locales/en.json
locales/fr.json
fxmanifest.lua
Usage
Initialise the locale module in your resource (once).
lib.locale()
Format your strings with the new locale global.
Additional arguments can be sent to format the locale output.
locale(str, ...)
- str:
string
- ...:
string
ornumber
-- 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.
locales/en.json
print(locale('hello_my_name_is', 'doka', 'linden'))