webmcp
diff framework/env/locale/_get_translation_table.lua @ 0:9fdfb27f8e67
Version 1.0.0
author | jbe/bsw |
---|---|
date | Sun Oct 25 12:00:00 2009 +0100 (2009-10-25) |
parents | |
children | 3d43a5cf17c1 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/locale/_get_translation_table.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,23 @@ 1.4 +function locale._get_translation_table() 1.5 + local language_code = locale.get("lang") 1.6 + if language_code then 1.7 + if type(language_code) ~= "string" then 1.8 + error('locale.get("lang") does not return a string.') 1.9 + end 1.10 + local translation_table = locale._translation_tables[language_code] 1.11 + if translation_table then 1.12 + return translation_table 1.13 + end 1.14 + local filename = encode.file_path(request.get_app_basepath(), "locale", "translations." .. language_code .. ".lua") 1.15 + local func = assert(loadfile(filename)) 1.16 + setfenv(func, {}) 1.17 + translation_table = func() 1.18 + if type(translation_table) ~= "table" then 1.19 + error("Translation file did not return a table.") 1.20 + end 1.21 + locale._translation_tables[language_code] = translation_table 1.22 + return translation_table 1.23 + else 1.24 + return locale._empty_translation_table 1.25 + end 1.26 +end