ElEditors, Interface administrators, Administrators
85,546
edits
(Add i18n support module) |
mNo edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 39: | Line 39: | ||
for _, translate_line in ipairs(translate_lines) do | for _, translate_line in ipairs(translate_lines) do | ||
-- Key should always without spaces, so apply trim to it directly. | -- Key should always without spaces, so apply trim to it directly. | ||
local equal_start, equal_end | local equal_start, equal_end = string.find(translate_line, '=') | ||
local key = trim(string.sub(translate_line, 1, equal_start - 1)) | if equal_start then | ||
local key = trim(string.sub(translate_line, 1, equal_start - 1)) | |||
local value = string.sub(translate_line, equal_end + 1) | |||
if trimValues ~= false then | |||
value = trim(value) | |||
end | |||
if key then | |||
translations[key] = value | |||
end | |||
end | end | ||
end | end | ||
Line 54: | Line 56: | ||
return translations | return translations | ||
end | end | ||
function i18n.getTranslatedTitle(title, lang) | |||
title = title or '' | |||
lang = lang or '' | |||
local title_full = title .. lang | |||
local display_title | |||
if title_full then | |||
local tp = mw.title.makeTitle('', title_full) | |||
if tp.exists then | |||
display_title = string.match(tp:getContent(), "%{%{DISPLAYTITLE:([^}]+)%}%}") | |||
end | |||
end | |||
return display_title | |||
end | |||
function i18n.translate(translations, key) | function i18n.translate(translations, key) |