Add locales system

This commit is contained in:
Lorraxs 2024-04-09 12:44:56 +07:00
parent 78bf2c1c3f
commit 481d82d612
5 changed files with 22 additions and 2 deletions

View File

@ -27,7 +27,7 @@ jobs:
working-directory: ./web
run: yarn build
- name: Zip Folder
run: zip -r ${{ github.event.repository.name }}.zip config.lua fxmanifest.lua impl.lua main.lua README.md LICENSE web/build/* client/* server/*
run: zip -r ${{ github.event.repository.name }}.zip config.lua fxmanifest.lua impl.lua main.lua README.md LICENSE web/build/* locales/* client/* server/*
- uses: 'marvinpinto/action-automatic-releases@latest'
with:
repo_token: '${{ secrets.GITHUB_TOKEN }}'

View File

@ -1,9 +1,11 @@
Locales = {}
Config = {}
Config.Dependencies = {} -- Reqired resources loaded to start
Config.Locale = 'vi'
Config.Settings = {
locale = {}
locale = Locales[Config.Locale] or Locales['default']
}
--Dont touch this

View File

@ -29,6 +29,7 @@ ui_page 'web/build/index.html'
shared_scripts {
'@ox_lib/init.lua',
"config.lua",
"locales/*.lua",
"main.lua",
"impl.lua",
}

3
locales/default.lua Normal file
View File

@ -0,0 +1,3 @@
Locales['default'] = {
['TEST'] = "Test"
}

View File

@ -411,3 +411,17 @@ Citizen.CreateThread(function()
end
main:InitImplAfterPlayerLoaded()
end)
function L(key, args)
if not args then args = {} end
if type(args) ~= "table" then args = {} end
if Config.Settings.locale[key] then
local pattern = Config.Settings.locale[key]
for k, v in pairs(args) do
pattern = pattern:gsub(":{" .. k .. "}", v)
end
return pattern
else
return key
end
end