mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-03 06:28:53 +00:00
Update Shared.md
This commit is contained in:
1 parent
12572a8178
commit
724894ef31
1 file changed
+44
-26
@@ -1,38 +1,14 @@
|
|||||||
Allows servers to set a preferred language and attempt to load locale files in any resources using the module.
|
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`
|
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
|
To change the preferred language from English, add the convar to your server.cfg
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
setr ox:locale en
|
setr ox:locale en
|
||||||
```
|
```
|
||||||
|
|
||||||
Initialise the locale module in your resource (once).
|
Create a locales directory and a file for your language.
|
||||||
|
|
||||||
```lua
|
|
||||||
lib.locale()
|
|
||||||
```
|
|
||||||
|
|
||||||
Format your strings with the new locale global.
|
|
||||||
|
|
||||||
```lua
|
|
||||||
locale(str, ...)
|
|
||||||
```
|
|
||||||
|
|
||||||
* str: `string`
|
|
||||||
* ...: `string` or `number`
|
|
||||||
|
|
||||||
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.json"
|
```json title="locales/en.json"
|
||||||
{
|
{
|
||||||
@@ -57,3 +33,45 @@ files {
|
|||||||
'locales/*.json'
|
'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`
|
||||||
|
* ...: `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 title="locales/en.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'))
|
||||||
|
```
|
||||||
Reference in new issue
Block a user