Skip to content
Snippets Groups Projects
Commit 75fc94e1 authored by DarkGod's avatar DarkGod
Browse files

support loading locales from engine, modules and addons

parent e6b4ce6f
No related branches found
No related tags found
No related merge requests found
......@@ -103,12 +103,24 @@ function _M:loadLocale(file)
end,
}, {__index=getfenv(2)})
local f, err = util.loadfilemods(file, env)
if not f and err then error(err) end
if not f and err then
if config.settings.cheat then
error(err)
else
print("[I18N] ERROR, localization file ", file, "not loaded due to error:", err)
return
end
end
f()
print("[I18N] Loaded locale file:", file)
end
function _M:setLocale(lc)
cur_locale_name = lc
if not locales[lc] then locales[lc] = {} end
if not locales_args[lc] then locales_args[lc] = {} end
if not locales_special[lc] then locales_special[lc] = {} end
if not flags[lc] then flags[lc] = {} end
cur_locale = locales[lc] or {}
cur_locale_args = locales_args[lc] or {}
cur_locale_special = locales_special[lc] or {}
......@@ -155,6 +167,10 @@ function _M.setFlag(lc, flag, data)
end
end
function _M:getLocalesData()
return cur_locale_name, cur_locale, cur_locale_args, cur_locale_special, cur_flags, "::", locales, locales_args, locales_special, flags
end
function _M:test()
self:loadLocale("/data/locales/fr_FR.lua")
self:setLocale("fr_FR")
......
......@@ -501,6 +501,11 @@ function _M:loadAddon(mod, add, hashlist, hooks_list)
elseif add.teaa then fs.mount("subdir:/data/|"..fs.getRealPath(add.teaa), "/data-"..add.short_name, true)
else fs.mount(base.."/data", "/data-"..add.short_name, true)
end
-- Load localizations, addons just need to provide the file and it's autoloaded
if mod.i18n_support and config.settings.locale then
I18N:loadLocale("/data-"..add.short_name.."/locales/"..config.settings.locale..".lua")
end
end
if add.superload then
print(" * with superload")
......@@ -939,14 +944,9 @@ function _M:instanciate(mod, name, new_game, no_reboot, extra_module_info)
mod.load("setup")
-- Load localizations
if mod.i18n_support then
local locale = config.settings.locale or "en_US"
I18N:setLocale(locale)
I18N:loadLocale("/data/i18n/"..locale..".lua")
if mod.i18n_support and config.settings.locale then
I18N:loadLocale("/data/locales/"..config.settings.locale..".lua")
end
-- I18N:loadLocale("/data/locales/zh_hans.lua")
-- I18N:setLocale("zh_hans")
-- Load font packages
FontPackage:loadDefinition("/data/font/packages/default.lua")
......
......@@ -125,9 +125,10 @@ if core.display.safeMode() then
config.settings.window = {size='800x600 Windowed'}
end
-- I18N:loadLocale("/data/locales/zh_hans.lua")
-- I18N:setLocale("zh_hans")
if config.settings.locale then
I18N:loadLocale("/data/locales/engine/"..config.settings.locale..".lua")
I18N:setLocale(config.settings.locale)
end
-- Default resolution as big as possible
if not config.settings.window or not config.settings.window.size then
......
......@@ -61,7 +61,7 @@ teams = {
i18n_support = true
show_funfacts = true
loading_wait_ticks = 260
loading_wait_ticks = 280
profile_stats_fields = {"artifacts", "characters", "deaths", "uniques", "scores", "lore", "escorts"}
allow_userchat = true -- We can talk to the online community
no_get_name = true -- Name setting for new characters is done by the module itself
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment