svghmi/i18n.ysl2
author Edouard Tisserant <edouard@beremiz.fr>
Fri, 30 Aug 2024 11:50:23 +0200
changeset 4008 f30573e98600
parent 3489 5335895ce526
permissions -rw-r--r--
IDE: allow structures to be located.
3108
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     1
// i18n.ysl2
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     2
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     3
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     4
template "svg:tspan", mode="extract_i18n" {
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     5
    if "string-length(.) > 0" line {
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     6
        value ".";
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     7
    }
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     8
}
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     9
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    10
template "svg:text", mode="extract_i18n" {
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    11
    msg {
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    12
        attrib "id" value "@id";
3112
bd20f9112014 SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents: 3108
diff changeset
    13
        attrib "label" value "substring(@inkscape:label,2)";
3489
5335895ce526 SVGHMI: Seems inkscape doesn't necessarily use tspan inside of text anymore.
Edouard Tisserant
parents: 3144
diff changeset
    14
        if "string-length(text()) > 0" line {
5335895ce526 SVGHMI: Seems inkscape doesn't necessarily use tspan inside of text anymore.
Edouard Tisserant
parents: 3144
diff changeset
    15
            value "text()";
5335895ce526 SVGHMI: Seems inkscape doesn't necessarily use tspan inside of text anymore.
Edouard Tisserant
parents: 3144
diff changeset
    16
        }
3108
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    17
        apply "svg:*", mode="extract_i18n";
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    18
    }
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    19
}
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    20
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    21
const "translatable_texts", "//svg:text[starts-with(@inkscape:label, '_')]";
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    22
const "translatable_strings" apply "$translatable_texts", mode="extract_i18n";
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    23
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    24
emit "preamble:i18n" {
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    25
    const "translations", "ns:GetTranslations($translatable_strings)";
3144
2af6afaccaf2 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.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3133
diff changeset
    26
    > var langs = [ ["Default", "C"],
3116
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    27
    foreach "$translations/langs/lang" {
3144
2af6afaccaf2 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.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3133
diff changeset
    28
        > ["«.»","«@code»"]
3116
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    29
        if "position()!=last()" > ,
3108
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    30
    }
3116
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    31
    | ];
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    32
    | var translations = [
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    33
    foreach "$translatable_texts" {
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    34
        const "n","position()";
3126
f45e413a0f40 SVGHMI: generate JS translation literals so that it is possible to also translate uses of texts, and added JS code that apply translations to tspans
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3116
diff changeset
    35
        const "current_id","@id";
f45e413a0f40 SVGHMI: generate JS translation literals so that it is possible to also translate uses of texts, and added JS code that apply translations to tspans
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3116
diff changeset
    36
        const "text_unlinked_uses","$result_svg_ns//svg:text[@original = $current_id]/@id";
f45e413a0f40 SVGHMI: generate JS translation literals so that it is possible to also translate uses of texts, and added JS code that apply translations to tspans
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3116
diff changeset
    37
    >   [[
f45e413a0f40 SVGHMI: generate JS translation literals so that it is possible to also translate uses of texts, and added JS code that apply translations to tspans
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3116
diff changeset
    38
        foreach "@id | $text_unlinked_uses" {
f45e413a0f40 SVGHMI: generate JS translation literals so that it is possible to also translate uses of texts, and added JS code that apply translations to tspans
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3116
diff changeset
    39
            > id("«.»")
f45e413a0f40 SVGHMI: generate JS translation literals so that it is possible to also translate uses of texts, and added JS code that apply translations to tspans
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3116
diff changeset
    40
            if "position()!=last()" > ,
f45e413a0f40 SVGHMI: generate JS translation literals so that it is possible to also translate uses of texts, and added JS code that apply translations to tspans
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3116
diff changeset
    41
        }
f45e413a0f40 SVGHMI: generate JS translation literals so that it is possible to also translate uses of texts, and added JS code that apply translations to tspans
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3116
diff changeset
    42
    > ],[
3116
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    43
        foreach "$translations/messages/msgid[$n]/msg" {
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    44
            > "
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    45
            foreach "line" {
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    46
                value ".";
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    47
                if "position()!=last()" > \\\\n
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    48
            }
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    49
            > "
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    50
            if "position()!=last()" > ,
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    51
        }
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    52
        > ]]
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    53
        if "position()!=last()" > ,
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    54
        > \n
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    55
    }
6da94ec04325 SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents: 3112
diff changeset
    56
    | ]
3108
079419e7228d SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    57
}