svghmi/i18n.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 16 Feb 2021 09:38:28 +0100
branchsvghmi
changeset 3144 2af6afaccaf2
parent 3133 450cd01324ad
child 3489 5335895ce526
permissions -rw-r--r--
SVGHMI: i18n: ensure langs always appea in same order, and add two variables that are updated automatically when selecting a new language : lang_name and lang_code. Also fixed i18n startup, prevent wrong lang numer to crash loading.
// i18n.ysl2


template "svg:tspan", mode="extract_i18n" {
    if "string-length(.) > 0" line {
        value ".";
    }
}

template "svg:text", mode="extract_i18n" {
    msg {
        attrib "id" value "@id";
        attrib "label" value "substring(@inkscape:label,2)";
        apply "svg:*", mode="extract_i18n";
    }
}

const "translatable_texts", "//svg:text[starts-with(@inkscape:label, '_')]";
const "translatable_strings" apply "$translatable_texts", mode="extract_i18n";

emit "preamble:i18n" {
    const "translations", "ns:GetTranslations($translatable_strings)";
    > var langs = [ ["Default", "C"],
    foreach "$translations/langs/lang" {
        > ["«.»","«@code»"]
        if "position()!=last()" > ,
    }
    | ];
    | var translations = [
    foreach "$translatable_texts" {
        const "n","position()";
        const "current_id","@id";
        const "text_unlinked_uses","$result_svg_ns//svg:text[@original = $current_id]/@id";
    >   [[
        foreach "@id | $text_unlinked_uses" {
            > id("«.»")
            if "position()!=last()" > ,
        }
    > ],[
        foreach "$translations/messages/msgid[$n]/msg" {
            > "
            foreach "line" {
                value ".";
                if "position()!=last()" > \\\\n
            }
            > "
            if "position()!=last()" > ,
        }
        > ]]
        if "position()!=last()" > ,
        > \n
    }
    | ]
}