From 0fde972facfad584eedadf576bed13c7c729b98c Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Fri, 29 Apr 2022 17:21:09 +1000 Subject: [PATCH] Add docs for locales --- .editorconfig | 4 +-- docs/ox_lib/Shared/locale.md | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 docs/ox_lib/Shared/locale.md diff --git a/.editorconfig b/.editorconfig index 99e226f1..e2aa8693 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,6 @@ root = true end_of_line = lf insert_final_newline = true charset = utf-8 -trim_trailing_whitespace = true +trim_trailing_whitespace = false indent_size = 2 -indent_style = space \ No newline at end of file +indent_style = space diff --git a/docs/ox_lib/Shared/locale.md b/docs/ox_lib/Shared/locale.md new file mode 100644 index 00000000..a60039e3 --- /dev/null +++ b/docs/ox_lib/Shared/locale.md @@ -0,0 +1,48 @@ +# Localisation + +Allows players 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](www.lingoes.net/en/translator/langcode.htm) and be saved as `./locales/langcode.json` + +Players can use `setlocale [langcode]`, and admins can use `serverlocale [langcode]` to change the loaded file. + +```lua +-- str: string +-- ...: string | number +locale(str, ...) +``` + +Additional arguments can be sent to format the locale output. + +```lua +-- Load the locale module +lib.locale() + +SetInterval(function() + print(locale('grand_theft_auto')) + print(locale('suspect_sex', locale('male'))) +end, 5000) +``` + +```json title="locales/en-US.json" +{ + "grand_theft_auto": "grand theft auto", + "male": "male", + "female": "female", + "suspect_sex": "suspect is %s", +} +``` + +```json title="locales/fr-FR.json" +{ + "grand_theft_auto": "vol de voiture", + "male": "homme", + "female": "femme", + "suspect_sex": "le suspect est %s", +} +``` + +```lua title="fxmanifest.lua" +files { + 'locales/*.json' +} +```