From 481d82d6122bbcd6e9fd8b607b5247b423cc8b14 Mon Sep 17 00:00:00 2001 From: Lorraxs Date: Tue, 9 Apr 2024 12:44:56 +0700 Subject: [PATCH] Add locales system --- .github/workflows/autorelease.yml | 2 +- config.lua | 4 +++- fxmanifest.lua | 1 + locales/default.lua | 3 +++ main.lua | 14 ++++++++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 locales/default.lua diff --git a/.github/workflows/autorelease.yml b/.github/workflows/autorelease.yml index 57b540a..7df684b 100644 --- a/.github/workflows/autorelease.yml +++ b/.github/workflows/autorelease.yml @@ -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 }}' diff --git a/config.lua b/config.lua index 9cb2b26..a490a6b 100644 --- a/config.lua +++ b/config.lua @@ -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 diff --git a/fxmanifest.lua b/fxmanifest.lua index 98fa07a..4412cb0 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -29,6 +29,7 @@ ui_page 'web/build/index.html' shared_scripts { '@ox_lib/init.lua', "config.lua", + "locales/*.lua", "main.lua", "impl.lua", } diff --git a/locales/default.lua b/locales/default.lua new file mode 100644 index 0000000..93908aa --- /dev/null +++ b/locales/default.lua @@ -0,0 +1,3 @@ +Locales['default'] = { + ['TEST'] = "Test" +} diff --git a/main.lua b/main.lua index cee9762..b11e341 100644 --- a/main.lua +++ b/main.lua @@ -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