Module:I18n: Difference between revisions

m
no edit summary
(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 = string.find(translate_line, '=')
         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 value = string.sub(translate_line, equal_end + 1)
            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)
            if trimValues ~= false then
        end
                value = trim(value)
            end


        if key then
            if key then
            translations[key] = value
                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)