2016-03-31 18:57 GMT+02:00 Elvis Stansvik <[email protected]>:
> 2016-03-31 17:14 GMT+02:00 Jason H <[email protected]>:
>> 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@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@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>&#10;</xsl:text>
>     </xsl:template>
>
>     <xsl:template match="text()|@*"/>
> </xsl:stylesheet>
> [estan@pyret ~]$ xsltproc test.xsl test.ts
> ChangePasswordScreen, Passwords do not match
> ChangePasswordScreen, At least %n character(s) are required
> [estan@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.

It also seems the format allows contexts within contexts, so if you
need the name of all ancestor contexts to the message in your output
(as opposed to just the immediate parent context), you would need to
loop over all context elements along the ancestor axis using something
like (untested):

<xsl:for-each select="ancestor::context">
    <xsl:value-of select="name"/>
</xsl:for-each>

Elvis

>
> Cheers,
> Elvis
>
> [1] http://doc.qt.io/qt-5/linguist-ts-file-format.html
>
>
>> _______________________________________________
>> Interest mailing list
>> [email protected]
>> http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to