webmcp

annotate framework/env/locale/_get_translation_table.lua @ 569:5b19007574de

New argument active_link_attr for env.ui.paginate{...}
author jbe
date Wed Oct 13 17:21:44 2021 +0200 (2021-10-13)
parents 2c31275322db
children
rev   line source
jbe/bsw@0 1 function locale._get_translation_table()
jbe/bsw@0 2 local language_code = locale.get("lang")
jbe/bsw@0 3 if language_code then
jbe/bsw@0 4 if type(language_code) ~= "string" then
jbe/bsw@0 5 error('locale.get("lang") does not return a string.')
jbe/bsw@0 6 end
jbe/bsw@0 7 local translation_table = locale._translation_tables[language_code]
jbe/bsw@0 8 if translation_table then
jbe/bsw@0 9 return translation_table
jbe/bsw@0 10 end
jbe@209 11 local filename = encode.file_path(WEBMCP_BASE_PATH, "locale", "translations." .. language_code .. ".lua")
jbe@309 12 local func, load_errmsg = loadcached(filename)
jbe@309 13 if not func then
jbe@314 14 error('Could not load translation file: ' .. load_errmsg)
jbe@64 15 end
jbe/bsw@0 16 translation_table = func()
jbe/bsw@0 17 if type(translation_table) ~= "table" then
jbe/bsw@0 18 error("Translation file did not return a table.")
jbe/bsw@0 19 end
jbe@563 20 local parent_code = translation_table["__parent"]
jbe@563 21 if parent_code then
jbe@563 22 local parent_table = locale._get_translation_table(parent_code)
jbe@563 23 for key, value in pairs(parent_table) do
jbe@563 24 if translation_table[key] == nil then
jbe@563 25 translation_table[key] = value
jbe@563 26 end
jbe@563 27 end
jbe@563 28 end
jbe/bsw@0 29 locale._translation_tables[language_code] = translation_table
jbe/bsw@0 30 return translation_table
jbe/bsw@0 31 else
jbe/bsw@0 32 return locale._empty_translation_table
jbe/bsw@0 33 end
jbe/bsw@0 34 end

Impressum / About Us