webmcp

view framework/env/locale/_get_translation_table.lua @ 64:3d43a5cf17c1

Compatibility with Lua 5.2
author jbe
date Sun Apr 15 16:04:33 2012 +0200 (2012-04-15)
parents 9fdfb27f8e67
children 2cb27106aa73
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(request.get_app_basepath(), "locale", "translations." .. language_code .. ".lua")
12 local func
13 if _ENV then
14 func = assert(loadfile(filename), nil, {})
15 else
16 func = assert(loadfile(filename))
17 setfenv(func, {})
18 end
19 translation_table = func()
20 if type(translation_table) ~= "table" then
21 error("Translation file did not return a table.")
22 end
23 locale._translation_tables[language_code] = translation_table
24 return translation_table
25 else
26 return locale._empty_translation_table
27 end
28 end

Impressum / About Us