How to extract the actual ID instead of resname

9 views
Skip to first unread message

Manuel Souto Pico

unread,
Jan 5, 2023, 8:22:10 AM1/5/23
to okapi-users
Dear all,

I would like to extract the ID from an XML file, but I can only get the resname attribute, whereas the actual trans-unit's id attribute is defined automatically.

In other words, given

<label key="01_welcome">
  <text xml:id="1001" xml:lang="en">Hello world</text>
</label>

I get this is what I get

<trans-unit id="1" resname="1001">
  <source xml:lang="en-US">Hello world</source>
  <target xml:lang="fr-FR"></target>
</trans-unit>

whereas this is what I would like to get:

<trans-unit id="1001" resname="01_welcome">
  <source xml:lang="en-US">Hello world</source>
  <target xml:lang="fr-FR"></target>
</trans-unit>

I'm using the attached filter configuration file.

Is there any way I can do that in Okapi Rainbow?

Thanks a lot in advance.
Cheers, Manuel
okf_xml@oat.fprm

yves.s...@gmail.com

unread,
Jan 5, 2023, 8:33:49 AM1/5/23
to Manuel Souto Pico, okapi-users

Hi Manuel,

 

In XLIFF resname is the attribute that is meant to have the identifier of the original resource.

(See http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#resname)

 

The id attribute is tool-specific. It may or may not correspond to the ID of the resource. It depends on how the tool doing the extraction/merge is handling references to the original document.

(See http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#id):

 

Id - Identifier - The id attribute is used in many elements as a reference to the original corresponding code data or format for the given element. The value of the id element is determined by the tool creating the XLIFF document. It may or may not be a resource identifier. The identifier of a resource should, at least, be stored in the resname attribute.

 

-ys

--
You received this message because you are subscribed to the Google Groups "okapi-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to okapi-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/okapi-users/CABm46bbxzRvhVo7wr9ZpSpqdBr_2eRGTB8b4pmjDvRWmdNTaHA%40mail.gmail.com.

Manuel Souto Pico

unread,
Jan 5, 2023, 8:53:57 AM1/5/23
to yves.s...@gmail.com, okapi-users
Hi Yves,

Thanks for your quick reply and the references. More or less I think I understand the two concepts.

In this case, it's the <label>'s key attribute that the engineers will use to merge back the translation with the skeleton, whereas it's the <text>'s id attribute that I need to become the <trans-unit>'s id which is what will be used in OmegaT to bind alternative translations.

Shall take your answer as meaning that it's not possible to do this in Rainbow, or is there a way?

Thank you.

Cheers, Manuel


Manuel Souto Pico

unread,
Jan 10, 2023, 11:44:00 AM1/10/23
to yves.s...@gmail.com, okapi-users
Hi Yves,

In any case, is it possible at all to extract some key, either as the value that populates the resname or as any other untranslatable detail?

input text looks like (it is the "key" that I would like to extract and include in the XLIFF file):

<label key="ca6f8952870e36e3b9e7442767e414ec">
  <text>Hello world</text>
</label>

Thanks in advance.
Cheers, Manuel

yves.s...@gmail.com

unread,
Jan 10, 2023, 3:12:01 PM1/10/23
to Manuel Souto Pico, okapi-users

You can use one of the XML/ITS filter extension to select a specific resname.

But there is one case where it will not work: if you have an xml:id attribute, it will take precedence over any other declaration.

 

So, using your example, if you have:

 

<?xml version="1.0"?>

<root>

<label key="key1">

  <text>Hello world</text>

</label>

<label key="key2">

  <text>Hello world</text>

</label>

</root>

 

You can use the following config file:

 

<?xml version="1.0"?>

<its:rules version="1.0" xmlns:its=http://www.w3.org/2005/11/its

  xmlns:itsx=http://www.w3.org/2008/12/its-extensions>

  <its:translateRule selector="//text" translate="yes" itsx:idValue=../@key/>

</its:rules>

 

(for example in a file named okf...@test.fprm)

 

That will give you:

 

<?xml version="1.0" encoding="UTF-8"?>

<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:okp="okapi-framework:xliff-extensions" xmlns:its=http://www.w3.org/2005/11/its xmlns:itsxlf=http://www.w3.org/ns/its-xliff/ its:version="2.0">

<file original="test.xml" source-language="en-US" target-language="fr-FR" datatype="xml">

<body>

<trans-unit id="1" resname="key1">

<source xml:lang="en-US">Hello world</source>

<target xml:lang="fr-FR"></target>

</trans-unit>

<trans-unit id="2" resname="key2">

<source xml:lang="en-US">Hello world</source>

<target xml:lang="fr-FR"></target>

</trans-unit>

</body>

</file>

</xliff>

 

Where your key values are visible in resname attributes

The example files are attached.

I hope this helps.

 

-ys

files-its-example.zip

Manuel Souto Pico

unread,
Jan 11, 2023, 4:31:34 AM1/11/23
to yves.s...@gmail.com, okapi-users
Thank you so much, Yves.

Your examples served as confirmation that I was on the right track. The problem was binding the namespaces... (a detail I don't fully grasp but some trial and error helped).

My fprm file includes:
<?xml version="1.0"?>
<its:rules version="1.0" xmlns:its="http://www.w3.org/2005/11/its"
  xmlns:itsx="http://www.w3.org/2008/12/its-extensions" xmlns:oat="http://www.imsglobal.org/xsd/imsqti_v2p2" >
  <its:translateRule selector="//oat:text" translate="yes" itsx:idValue="parent::oat:label/@key"/>
 </its:rules>

And my XML file has the following preamble:

I needed to use the namespace in all xpaths:
  <its:translateRule selector="//oat:text" translate="yes" itsx:idValue="parent::oat:label/@key"/>

Thanks a lot.
Cheers, Manuel

Manuel Souto Pico

unread,
Jan 22, 2023, 2:51:26 PM1/22/23
to yves.s...@gmail.com, okapi-users
Dear all,


I believe the subject of this thread was not too clear. Probably I didn't have a clear idea myself of what I was trying to achieve and how when I wrote it.

Hopefully the title of the ticket (Use resname as segment identifier instead of the id) clarifies.

Thanks.

Cheers, Manuel
Reply all
Reply to author
Forward
0 new messages