1 year ago

#369028

test-img

Joey Slomowitz

How to do if check and perform operation with xmlstarlet

I have just one section of my XML that I want to perform some operations in the case that there is a field missing.

In the trans-unit there is a source tag as well as a target tag.

However there are parts with missing target tags and values -

I would like to be able to check for these. If the target field is missing, I would like to get the source's value, translate it, and add the target tag with the translated text as its value.

(I will likely use translate-shell for the translation.)

The structure looks like this

<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd">
<file original="WabiTime/en.lproj/Localizable.strings" source-language="en" target-language="fr" datatype="plaintext">
    <header>
      <tool tool-id="com.apple.dt.xcode" tool-name="Xcode" tool-version="13.3" build-num="13E113"/>
    </header>
    <body>
      <trans-unit id="%@ complete" xml:space="preserve">
        <source>%@ complete</source>
        <target>complété à %@</target>
        <note/>
      </trans-unit>
      <trans-unit id="%lld Completed" xml:space="preserve">
        <source>%lld Completed</source>
        <target>%lld complète</target>
        <note/>
      </trans-unit>
      <trans-unit id="(No project): %@" xml:space="preserve">
        <source>(No project): %@</source>
        <target>(aucun projet): %@</target>
        <note/>
      </trans-unit>
      <trans-unit id="A time limit should be greater than or equal to 1 minute" xml:space="preserve">
        <source>A time limit should be greater than or equal to 1 minute</source>
        <target>Une limite de temps doit être supérieure ou égale à 1 minute</target>
        <note>alert body</note>
      </trans-unit>
      <trans-unit id="About WabiTime" xml:space="preserve">
        <source>About WabiTime</source>
        <target>A propos WabiTime</target>
        <note>menu item</note>
      </trans-unit>
      <trans-unit id="Active tint color:" xml:space="preserve">
        <source>Active tint color:</source>
        <note/>
      </trans-unit>
</body>
 </file>
</xliff>

If I use xml el -v fr.xliff then I can see the path I want shown as;

xliff/file[@original='WabiTime/en.lproj/Localizable.strings' and @source-language='en' and @target-language='fr' and @datatype='plaintext']

However I can't seem to figure out how to work with this.

How do I do my if check and edit in the new field?

xml

xmlstarlet

xliff

0 Answers

Your Answer

Accepted video resources