Permettre de préciser les langues pour une TMX bilingue

This commit is contained in:
Philippe Tourigny 2023-04-22 00:38:49 +09:00
parent dbdec9ef27
commit cdc18f0d50
2 changed files with 43 additions and 16 deletions

View File

@ -22,31 +22,40 @@
<!-- Namespaces needed to access parts of the document --> <!-- Namespaces needed to access parts of the document -->
<xsl:output method = "xml" indent = "yes" encoding = "UTF-8" omit-xml-declaration = "no"/> <xsl:output method = "xml" indent = "yes" encoding = "UTF-8" omit-xml-declaration = "no"/>
<xsl:variable name="headerCell" select="//table:table/table:table-row[1]/table:table-cell"></xsl:variable>
<xsl:template match="/"> <xsl:template match="/">
<!-- Get the source and target languages from the first and second column of the first row. Code based on this answer https://forum.openoffice.org/en/forum/viewtopic.php?p=56627&sid=d4ebce191acc01d99d587fef28377db4#p56627 from the Apache Office forum -->
<xsl:variable name="adminlang" select="$headerCell[2]/text:p"></xsl:variable>
<xsl:variable name="srclang" select="$headerCell[1]/text:p"></xsl:variable>
<xsl:variable name="tgtlang" select="$headerCell[2]/text:p"></xsl:variable>
<tmx version="1.4"> <tmx version="1.4">
<header <header>
creationtool="TMX-export for LibreOffice" <xsl:attribute name="creationtool">ods2tmx filter</xsl:attribute>
creationtoolversion="0.9" <xsl:attribute name="creationtoolversion">0.93</xsl:attribute>
segtype="sentence" <xsl:attribute name="segtype">sentence</xsl:attribute>
o-tmf="application/vnd.oasis.opendocument.spreadsheet" <xsl:attribute name="o-tmf">application/vnd.oasis.opendocument.spreadsheet</xsl:attribute>
adminlang="fr-BE" <xsl:attribute name="adminlang"><xsl:value-of select="$adminlang"></xsl:value-of></xsl:attribute>
srclang="nl-BE" <xsl:attribute name="srclang"><xsl:value-of select="$srclang"></xsl:value-of></xsl:attribute>
datatype="plaintext"> <xsl:attribute name="datatype">plaintext</xsl:attribute>
</header> </header>
<!-- Todo : get the language from Calc, if any, or from a dialog, if LibreOffice allows,
to set the srclang of the header and the xml:lang of the tuv. -->
<body> <body>
<xsl:for-each select="//table:table-row"> <xsl:for-each select="//table:table-row[position()>1]">
<tu> <tu>
<xsl:for-each select="table:table-cell"> <xsl:for-each select="table:table-cell">
<xsl:choose> <xsl:choose>
<xsl:when test="position()=1"> <xsl:when test="position()=1">
<tuv xml:lang="nl-BE"> <tuv>
<xsl:attribute name="xml:lang"><xsl:value-of select="$srclang"></xsl:value-of></xsl:attribute>
<seg><xsl:value-of select="text:p"/></seg> <seg><xsl:value-of select="text:p"/></seg>
</tuv> </tuv>
</xsl:when> </xsl:when>
<xsl:when test="position()=2"> <xsl:when test="position()=2">
<tuv xml:lang="fr-BE"> <tuv>
<xsl:attribute name="xml:lang"><xsl:value-of select="$tgtlang"></xsl:value-of></xsl:attribute>
<seg><xsl:value-of select="text:p"/></seg> <seg><xsl:value-of select="text:p"/></seg>
</tuv> </tuv>
</xsl:when> </xsl:when>

View File

@ -49,12 +49,11 @@
<!-- Properties of the columns --> <!-- Properties of the columns -->
<!-- I consider the case of a two-languages TMX --> <!-- I consider the case of a two-languages TMX -->
<!-- Todo : pass the source and target languages as attributes to the text in Calc -->
<style:style style:name="co1" style:family="table-column"><!-- source language --> <style:style style:name="co1" style:family="table-column"><!-- source language -->
<style:table-column-properties fo:break-before="auto" style:column-width="16.000cm"/> <style:table-column-properties fo:break-before="auto" style:column-width="20.000cm"/>
</style:style> </style:style>
<style:style style:name="co2" style:family="table-column"><!-- target language --> <style:style style:name="co2" style:family="table-column"><!-- target language -->
<style:table-column-properties fo:break-before="auto" style:column-width="16.000cm"/> <style:table-column-properties fo:break-before="auto" style:column-width="20.000cm"/>
</style:style> </style:style>
<!-- Properties of the rows --> <!-- Properties of the rows -->
@ -72,6 +71,10 @@
</style:style> </style:style>
</office:automatic-styles> </office:automatic-styles>
<!-- Get the source and target languages from the TMX file -->
<xsl:variable name="srclang" select="tmx/body/tu/tuv[1]/@*[local-name() = 'lang']"></xsl:variable>
<xsl:variable name="tgtlang" select="/tmx/body/tu/tuv[2]/@*[local-name() = 'lang']"></xsl:variable>
<office:body> <office:body>
<office:spreadsheet> <office:spreadsheet>
<table:table> <table:table>
@ -80,6 +83,21 @@
<table:table-column table:style-name="co1" table:default-cell-style-name="ce1"/> <table:table-column table:style-name="co1" table:default-cell-style-name="ce1"/>
<table:table-column table:style-name="co2" table:default-cell-style-name="ce2"/> <table:table-column table:style-name="co2" table:default-cell-style-name="ce2"/>
<!-- Put the source and target languages retrieved from
the TMX file in the first two columns of the first row -->
<table:table-row>
<table:table-cell>
<text:p>
<xsl:value-of select="$srclang"></xsl:value-of>
</text:p>
</table:table-cell>
<table:table-cell>
<text:p>
<xsl:value-of select="$tgtlang"></xsl:value-of>
</text:p>
</table:table-cell>
</table:table-row>
<!-- Process XML of the input TMX file: one row for each tu, one cell for the segment in each tuv --> <!-- Process XML of the input TMX file: one row for each tu, one cell for the segment in each tuv -->
<xsl:for-each select="tmx/body/tu"> <xsl:for-each select="tmx/body/tu">
<table:table-row> <table:table-row>