[Interest] ts file format / export

Elvis Stansvik elvstone at gmail.com
Thu Mar 31 18:57:37 CEST 2016


2016-03-31 17:14 GMT+02:00 Jason H <jhihn at gmx.com>:
> I find it somewhat confusing that phrases are grouped (nested) in the editor, but not in the file:
>
> <TS version="2.1" language="en_US">
> <context>
>     <name>ChangePasswordScreen</name>
>     <message>
>         <source>Passwords do not match</source>
>         <translation>Passwords do not match</translation>
>     </message>
>     <message numerus="yes">
>         <source>At least %n character(s) are required</source>
>         <translation>
>             <numerusform>At least 1 character is required</numerusform>
>             <numerusform>At least %n characters are required</numerusform>
>         </translation>
>     </message>
> </context>
>
> Here, I would expect the message elements to child children of the name element.

That would be strange I think, they logically belong to the context,
not the context's name.

> I'm trying to export a list as: <name>, <source>
> ChangePasswordScreen, Passwords do not match
> ChangePasswordScreen, At least %n character(s) are required
>
> But the XSLT to do the conversion is beyond me because they aren't parented.
> Does anyone have any XSLT advice?

I think you can simply use ".." to get to the parent, like this:

[estan at pyret ~]$ cat test.ts
<TS version="2.1" language="en_US">
<context>
    <name>ChangePasswordScreen</name>
    <message>
        <source>Passwords do not match</source>
        <translation>Passwords do not match</translation>
    </message>
    <message numerus="yes">
        <source>At least %n character(s) are required</source>
        <translation>
            <numerusform>At least 1 character is required</numerusform>
            <numerusform>At least %n characters are required</numerusform>
        </translation>
    </message>
</context>
</TS>
[estan at pyret ~]$ cat test.xsl
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="context/message">
        <xsl:value-of select="../name"/>
        <xsl:text>, </xsl:text>
        <xsl:value-of select="source"/>
        <xsl:text>
</xsl:text>
    </xsl:template>

    <xsl:template match="text()|@*"/>
</xsl:stylesheet>
[estan at pyret ~]$ xsltproc test.xsl test.ts
ChangePasswordScreen, Passwords do not match
ChangePasswordScreen, At least %n character(s) are required
[estan at pyret ~]$

Note though, that looking at the content model for the TS format [1],
it seems messages can also appear directly as children of the TS
element. Not sure when that happens, or if you want to handle such
messages.

Cheers,
Elvis

[1] http://doc.qt.io/qt-5/linguist-ts-file-format.html


> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list