Skip to content

Commit

Permalink
Moving to a translation cache.
Browse files Browse the repository at this point in the history
This loads all translations in, and then switches between them.
  • Loading branch information
manix84 committed Jul 7, 2020
1 parent 1d44601 commit 7cfbed9
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lua/utils/locale.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,25 @@ end
getSelectedLanguage()
print_debug("Selected language: ", selectedLanguage)

local translationsCache = {}
local function getTranslationsCache()
if (table.Count(translationsCache) <= 0) then
print_debug('Caching language files:')
local localesTable = getAvailableLanguages()
for i, localeFileName in ipairs(localesTable) do
translationsCache[localeFileName] = include('locale/'..localeFileName..'.lua')
print_debug(' -', 'locale/'..localeFileName..'.lua')
end
end
return translationsCache
end
getTranslationsCache()

local translations = {}
function getTranslations()
local selectedLanguage = getSelectedLanguage();
translations = include('locale/'..selectedLanguage..'.lua')
local selectedLanguage = getSelectedLanguage()
local translationsCache = getTranslationsCache()
translations = translationsCache[selectedLanguage]
return translations
end
getTranslations()
Expand Down

0 comments on commit 7cfbed9

Please sign in to comment.