Module:Calc fn name

    From The Document Foundation Wiki

    This module is used in Calc function articles to save translator time. It replaces an English Calc function name with its translation automatically according to the language of the article.

    The Python script used to extract the translated function names is included below (click expand to see it).


    -- Invoke from a wrapper template like so:
    -- {{#invoke:Calc_fn_name|main}}
    -- Pass arguments to template like so:
    -- {{Calc_fn_name|IF|{{PAGELANGUAGE}}}}
    -- Starting with MW 1.42, we should be able to get page language with:
    -- local lang = mw.title.pageLang:getCode()
    -- Implemented in https://phabricator.wikimedia.org/T161976
    local p = {};
    
    local function get_fn_name( frame )
    
        local fn_names = mw.loadData( 'Module:Calc_fn_name/data' )
        local fn_name = frame:getParent().args[1]
        local lang = frame:getParent().args[2]
    
        if not lang or lang == '' then
            return fn_name
        end    
        
        local tr_name = fn_names[fn_name][lang]
        
        if not tr_name or tr_name == '' then
            tr_name = fn_name
        end
    
        -- have to escape # chars or they will be rendered as ordered lists!
        local tr_name_escaped = string.gsub( tr_name, "#", "#" )
    
        return tr_name_escaped
    
    end
    
    function p.main( frame )
        return get_fn_name( frame )
    end
    
    return p