Compare commits
7 Commits
main
...
filtres_TM
Author | SHA1 | Date | |
---|---|---|---|
ecad229058 | |||
6796bc0128 | |||
f8faf4bbeb | |||
663aca2b9c | |||
a83e1aba50 | |||
5d1f849dcb | |||
27a3e88d89 |
@ -19,4 +19,4 @@ Les différents projets sont distribués sous des licenses différentes :
|
||||
1. Filtres TMX pour Calc : [LGPL](https://www.gnu.org/licenses/lgpl-3.0.html) version 3 ou ultérieure.
|
||||
2. Conversion de TMX en TBX : [GPL](https://www.gnu.org/licenses/gpl-3.0.html) version 3.0 ou ultérieure.
|
||||
|
||||
Un ficher « LICENSE » est inclus dans le répertoire de chacun des projets.
|
||||
Un ficher `LICENSE` est inclus dans le répertoire de chacun des projets.
|
@ -1,12 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<!-- Dominique Meeùs, created 30-9-2013, version 0.9.
|
||||
XSLT transformation of a TMX translation memory exchange file
|
||||
into an Open Document Format spreadsheet in two columns.
|
||||
Filter to install as an import filter for LibreOffice Calc. -->
|
||||
<!-- Philippe Tourigny, modified 12-9-2022, version 0.97
|
||||
<!-- Philippe Tourigny, modified 12-9-2022, version 0.95
|
||||
Allow the filter to retrieve the languages in the TMX from its
|
||||
first <tu> element, and create a column for each language. -->
|
||||
<!-- Philippe Tourigny, modified 3-6-2023, version 0.96
|
||||
Streamline namespaces to only those used in the transformation.
|
||||
Improve formatting for attributes too long to fit on a single line and
|
||||
fix awkward indentation. -->
|
||||
<!-- Philippe Tourigny, modified 5-6-2023, version 0.97
|
||||
Refactor code to use templates. -->
|
||||
<!-- Copyright 2013 Dominique Meeùs, and 2022 Philippe Tourigny.
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License
|
||||
@ -17,114 +22,113 @@
|
||||
See the GNU Lesser General Public License for more details.
|
||||
You should have received a copy of the GNU Lesser General Public License along with this program.
|
||||
If not, see http://www.gnu.org/licenses/. -->
|
||||
|
||||
<!-- Declare the namespaces needed to create the document. -->
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
|
||||
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
|
||||
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
|
||||
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
|
||||
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0">
|
||||
|
||||
<xsl:template match="/">
|
||||
<office:document-content
|
||||
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
|
||||
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
|
||||
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
|
||||
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
|
||||
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
|
||||
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
|
||||
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
|
||||
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
|
||||
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
|
||||
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
|
||||
xmlns:math="http://www.w3.org/1998/Math/MathML"
|
||||
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
|
||||
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
|
||||
xmlns:ooo="http://openoffice.org/2004/office"
|
||||
xmlns:ooow="http://openoffice.org/2004/writer"
|
||||
xmlns:oooc="http://openoffice.org/2004/calc"
|
||||
xmlns:dom="http://www.w3.org/2001/xml-events"
|
||||
xmlns:xforms="http://www.w3.org/2002/xforms"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
office:version="1.0">
|
||||
<office:document-content>
|
||||
|
||||
<!-- Define styles to make the table easier to read. -->
|
||||
<office:automatic-styles>
|
||||
<!-- PTable properties -->
|
||||
<style:style style:name="ta1" style:family="table" style:master-page-name="Default">
|
||||
<style:table-properties table:display="true" style:writing-mode="lr-tb"/>
|
||||
</style:style>
|
||||
|
||||
|
||||
<!-- Column properties (for all languages) -->
|
||||
<style:style style:name="co1" style:family="table-column">
|
||||
<style:table-column-properties fo:break-before="auto" style:column-width="14.000cm"/>
|
||||
<style:table-column-properties fo:break-before="auto"
|
||||
style:column-width="14.000cm"/>
|
||||
</style:style>
|
||||
|
||||
<!-- Row properties -->
|
||||
<!-- All rows are set to “optimal height” -->
|
||||
<!-- All rows are set to “optimal height”. -->
|
||||
<style:style style:name="ro1" style:family="table-row">
|
||||
<style:table-row-properties fo:break-before="auto" style:use-optimal-row-height="true"/>
|
||||
<style:table-row-properties fo:break-before="auto"
|
||||
style:use-optimal-row-height="true"
|
||||
/>
|
||||
</style:style>
|
||||
|
||||
<!-- Cell properties -->
|
||||
<!-- Language code heading cells
|
||||
The language codes are centered and set in bold
|
||||
in the first column. -->
|
||||
Language codes are centered and set in bold
|
||||
in the first row. -->
|
||||
<style:style style:name="heading" style:family="table-cell"
|
||||
style:parent-style-name="Default">
|
||||
style:parent-style-name="Default">
|
||||
<style:table-cell-properties style:text-align-source="fix"
|
||||
style:repeat-content="false" fo:wrap-option="wrap"/>
|
||||
style:repeat-content="false"
|
||||
fo:wrap-option="wrap"/>
|
||||
<style:paragraph-properties fo:text-align="center"/>
|
||||
<style:text-properties fo:font-weight="bold"/>
|
||||
</style:style>
|
||||
|
||||
<!-- Style for cells with the segment text -->
|
||||
<style:style style:name="ce2" style:family="table-cell" style:parent-style-name="Default">
|
||||
<style:table-cell-properties fo:wrap-option="wrap"/>
|
||||
<!-- Style for the cells that contain the segment text. -->
|
||||
<style:style style:name="ce2" style:family="table-cell"
|
||||
style:parent-style-name="Default">
|
||||
<style:table-cell-properties fo:wrap-option="wrap"
|
||||
style:vertical-align="top"/>
|
||||
</style:style>
|
||||
</office:automatic-styles>
|
||||
|
||||
<!-- Define variables used to identify the languages
|
||||
In a TMX with three or more languages. All translation unit
|
||||
(<tuv>) elements are assumed to contain the same number of
|
||||
languages, and the first <tu> is used to identify them. -->
|
||||
|
||||
<!-- Todo: Identify the <tu> with the largest highest number of <tuv> elements to identify all languages in a TMX file with more languages in some <tu> elements than others. -->
|
||||
<xsl:variable name="firstTU" select="tmx/body/tu[1]"/>
|
||||
<xsl:variable name="numLangs" select="count($firstTU/tuv)"/>
|
||||
|
||||
<office:body>
|
||||
<office:spreadsheet>
|
||||
<table:table table:style-name="ta1">
|
||||
<!-- Set the format for a number of columns equal to
|
||||
the number of languages in the imported TMX file -->
|
||||
<table:table-column table:style-name="co1" table:number-columns-repeated="{$numLangs}"
|
||||
table:default-cell-style-name="ce2"/>
|
||||
<table:table>
|
||||
|
||||
<!-- Fill in the language headers in the first row
|
||||
The use of the "local-name()" function enables
|
||||
the filter to handle older versions that use the
|
||||
"lang" attribute as well as recent versions that
|
||||
use the "xml:lang"` attributes -->
|
||||
<table:table-row table:style-name="ro1">
|
||||
<xsl:for-each select="$firstTU/tuv">
|
||||
<table:table-cell table:style-name="heading">
|
||||
<text:p>
|
||||
<xsl:value-of select="@*[local-name()='lang']"/>
|
||||
</text:p>
|
||||
</table:table-cell>
|
||||
</xsl:for-each>
|
||||
<!-- Get the number of languages in the TMX. -->
|
||||
<xsl:variable name="numLangs" select="count(//tu[1]/tuv)"/>
|
||||
|
||||
<!-- Set column width for a number of columns equal to the
|
||||
number of languages in the TMX file. -->
|
||||
<table:table-column table:style-name='co1'
|
||||
table:number-columns-repeated="{$numLangs}"
|
||||
table:default-cell-style-name="ce2"/>
|
||||
|
||||
<!-- Create the header row and retrieve the languages.
|
||||
Use the mode attribute to retrieve the language attribute
|
||||
from the <tuv> segment text. -->
|
||||
|
||||
<!-- Todo: Identify the <tu> with the largest highest number of <tuv> elements to identify all languages in a TMX file with more languages in some <tu> elements than others. -->
|
||||
<table:table-row table:style-name="ro1">
|
||||
<xsl:apply-templates select="//tu[1]/tuv" mode="lang"/>
|
||||
<table:table-column table:style-name="co1"/>
|
||||
</table:table-row>
|
||||
|
||||
<!-- Process the <tu> and <tuv> elements in the TMX file:
|
||||
One row per tu, one column per segment in each <tuv>. -->
|
||||
<xsl:for-each select="tmx/body/tu">
|
||||
<table:table-row table:style-name="ro1">
|
||||
<xsl:for-each select="tuv">
|
||||
<table:table-cell>
|
||||
<text:p><xsl:value-of select="seg"/></text:p>
|
||||
</table:table-cell>
|
||||
</xsl:for-each>
|
||||
</table:table-row>
|
||||
</xsl:for-each>
|
||||
<!-- Get the text of each <tuv> in each <tu>. -->
|
||||
<xsl:apply-templates select="//tu"/>
|
||||
</table:table>
|
||||
</office:spreadsheet>
|
||||
</office:body>
|
||||
</office:document-content>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Retrieve the languages to use as headers in the first row.
|
||||
The "local-name()" function enables the filter to handle both older
|
||||
versions with the "lang" attribute and newer versions with the
|
||||
"xml:lang"` attribute. -->
|
||||
<xsl:template match="tu[1]/tuv" mode="lang">
|
||||
<table:table-cell table:style-name="heading">
|
||||
<text:p>
|
||||
<xsl:value-of select="@*[local-name()='lang']"/>
|
||||
</text:p>
|
||||
</table:table-cell>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Process the <tu> elements. -->
|
||||
<xsl:template match="tu">
|
||||
<table:table-row table:style-name="ro1">
|
||||
<xsl:apply-templates select="tuv" mode="text"/>
|
||||
</table:table-row>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Retrieve the text of the segments in each <tuv> in the <tu>. -->
|
||||
<xsl:template match="tuv" mode="text">
|
||||
<table:table-cell table:style-name="ce2">
|
||||
<text:p>
|
||||
<xsl:value-of select="seg"/>
|
||||
</text:p>
|
||||
</table:table-cell>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user