feat(locales): include some locales

Partial, and google translated just for the sake of setting an example.
Also renamed many of the language codes where the extra characters are
redundant (i.e. fr-FR, de-DE).
This commit is contained in:
Linden
2022-04-30 05:04:15 +10:00
parent 031cccd886
commit 48728f0241
4 changed files with 14 additions and 4 deletions

View File

@@ -16,7 +16,7 @@ end
local function loadLocale(locale) local function loadLocale(locale)
local resourceName = GetCurrentResourceName() local resourceName = GetCurrentResourceName()
local JSON = LoadResourceFile(resourceName, ('locales/%s.json'):format(locale)) or LoadResourceFile(resourceName, ('locales/en-US.json'):format(locale)) local JSON = LoadResourceFile(resourceName, ('locales/%s.json'):format(locale)) or LoadResourceFile(resourceName, ('locales/en.json'):format(locale))
if JSON then if JSON then
dict = json.decode(JSON) dict = json.decode(JSON)
@@ -26,6 +26,6 @@ end
AddEventHandler('ox_lib:setLocale', loadLocale) AddEventHandler('ox_lib:setLocale', loadLocale)
return function() return function()
local lang = IsDuplicityVersion() and lib.getServerLocale() or GetExternalKvpString('ox_lib', 'locale') or 'en-US' local lang = IsDuplicityVersion() and lib.getServerLocale() or GetExternalKvpString('ox_lib', 'locale') or 'en'
loadLocale(lang) loadLocale(lang)
end end

5
locales/en.json Normal file
View File

@@ -0,0 +1,5 @@
{
"language": "English",
"ui.close": "Close",
"ui.confirm": "Confirm"
}

5
locales/fr.json Normal file
View File

@@ -0,0 +1,5 @@
{
"language": "Français",
"ui.close": "Fermer",
"ui.confirm": "Confirmer"
}

View File

@@ -1,7 +1,7 @@
local userLocale = GetResourceKvpString('locale') local userLocale = GetResourceKvpString('locale')
local function loadLocale(locale, cb) local function loadLocale(locale, cb)
local JSON = LoadResourceFile('ox_lib', ('locales/%s.json'):format(locale)) or LoadResourceFile('ox_lib', ('locales/en-US.json'):format(locale)) local JSON = LoadResourceFile('ox_lib', ('locales/%s.json'):format(locale)) or LoadResourceFile('ox_lib', ('locales/en.json'):format(locale))
if cb then cb(JSON) end if cb then cb(JSON) end
SetResourceKvp('locale', locale) SetResourceKvp('locale', locale)
@@ -11,7 +11,7 @@ end
RegisterNUICallback('getLocale', loadLocale) RegisterNUICallback('getLocale', loadLocale)
if not userLocale then if not userLocale then
local default = { 'en-US', 'fr-FR', 'de-DE', 'it-IT', 'es-ES', 'pt-BR', 'pl-PL', 'ru-RU', 'ko-KR', 'zh-TW', 'ja-JP', 'es-MX', 'zh-CN' } local default = { 'en', 'fr', 'de', 'it', 'es', 'pt-BR', 'pl', 'ru', 'ko', 'zh-TW', 'ja', 'es-MX', 'zh-CN' }
userLocale = default[GetCurrentLanguage() + 1] userLocale = default[GetCurrentLanguage() + 1]
end end