A typical Developer Blog
by Gordon Franke
Icon

How can i automatic add ids to my trans-unit nodes in my XML Xliff Tanslation files?

When you validate you XML Xliff file you have often the problem that a trans-unit node has no or a already existing id. So i have wrote a small script for that problem.

fix_id.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
 
$doc = new DOMDocument();
$doc->load($argv[1]);
 
$xpath = new DOMXPath($doc);
 
$query = '//trans-unit';
 
$entries = $xpath->query($query);
foreach ($entries as $i => $entry) {
    $entry->setAttribute('id', $i+1);
}
 
$doc->save($argv[1]);

Execute the following command in your symfony1 root directory ;)

for FILE in `find apps/*/i18n -name *\.xml`; do php fix_id.php $FILE; done;

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Author:

Category: symfony, unix

Tagged: , , , ,

2 Responses

  1. Kuba says:

    Very simple but SO useful! :)

  2. great script, simple and fast, thank you for share it

    greetings
    joaquín núñez´s last [type] ..sfWidgetFormChoiceChileanBanks

Leave a Reply

CommentLuv badge