webmcp
view 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 | 
 line source
     1 function locale._get_translation_table()
     2   local language_code = locale.get("lang")
     3   if language_code then
     4     if type(language_code) ~= "string" then
     5       error('locale.get("lang") does not return a string.')
     6     end
     7     local translation_table = locale._translation_tables[language_code]
     8     if translation_table then 
     9       return translation_table
    10     end
    11     local filename = encode.file_path(WEBMCP_BASE_PATH, "locale", "translations." .. language_code .. ".lua")
    12     local func, load_errmsg = loadcached(filename)
    13     if not func then
    14       error('Could not load translation file: ' .. load_errmsg)
    15     end
    16     translation_table = func()
    17     if type(translation_table) ~= "table" then
    18       error("Translation file did not return a table.")
    19     end
    20     local parent_code = translation_table["__parent"]
    21     if parent_code then
    22       local parent_table = locale._get_translation_table(parent_code)
    23       for key, value in pairs(parent_table) do
    24         if translation_table[key] == nil then
    25           translation_table[key] = value
    26         end
    27       end
    28     end
    29     locale._translation_tables[language_code] = translation_table
    30     return translation_table
    31   else
    32     return locale._empty_translation_table
    33   end
    34 end
