From 156673d1079084039af9bc3b74c619e89656cce9 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 13 Aug 2018 17:45:20 -0400 Subject: [PATCH] LP#1775466 XLIFF->PO->XLIFF crosswalk repair tool Script to repair message-id chaos caused by crosswalking between PO and XLIFF files for translations. Script duplicates the message context value into the id attribute on the translation unit, to match Angular's expectations. Signed-off-by: Bill Erickson --- Open-ILS/src/eg2/src/locale/.gitkeep | 0 Open-ILS/src/eg2/src/locale/fix-po2xliff.pl | 88 +++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) delete mode 100644 Open-ILS/src/eg2/src/locale/.gitkeep create mode 100755 Open-ILS/src/eg2/src/locale/fix-po2xliff.pl diff --git a/Open-ILS/src/eg2/src/locale/.gitkeep b/Open-ILS/src/eg2/src/locale/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/Open-ILS/src/eg2/src/locale/fix-po2xliff.pl b/Open-ILS/src/eg2/src/locale/fix-po2xliff.pl new file mode 100755 index 0000000000..2c3eee2b3c --- /dev/null +++ b/Open-ILS/src/eg2/src/locale/fix-po2xliff.pl @@ -0,0 +1,88 @@ +#!/usr/bin/perl +use XML::LibXML; +# ------------------------------------------------------------ +# The xliff2po and po2xliff crosswalk results in message IDs +# getting stored in an unexpected location as far as Angular is +# concerned. +# +# E.g. +# +# +# Sort Priority +# Sort Priority +# +# 1f93d86f7ad773b5f4232b60fff10567179f28f4 +# +# +# +# Angular expaect the trans-unit id attribute to match the "sourcefile" +# hash from the context group. This script makes that happen. +# Result is: +# +# +# Sort Priority +# Sort Priority +# +# 1f93d86f7ad773b5f4232b60fff10567179f28f4 +# +# +# +# NOTES: +# npm run build-translations +# xliff2po -i src/locale/messages.fr-CA.xlf -o src/locale/messages.fr-CA.po +# # add translations to .po file ... +# po2xliff -i src/locale/messages.fr-CA.po -o src/locale/messages.fr-CA.from-PO.xlf +# perl src/locale/fix-po2xliff.pl src/locale/messages.fr-CA.from-PO.xlf src/locale/messages.fr-CA.xlf +# ng build --configuration=production-fr-CA ... +# ------------------------------------------------------------ + +sub usage { + print <getElementsByTagName($name)->[0]; +} + +my $infile = shift; +my $outfile = shift; + +usage() unless $infile; + +my $doc = XML::LibXML->new->parse_file($infile); + +my $body = gbn(gbn($doc->documentElement, 'file'), 'body'); + +for my $trans ($body->getElementsByTagName('trans-unit')) { + + my $source = gbn($trans, 'source'); + my $target = gbn($trans, 'target'); + my $context_group = gbn($trans, 'context-group'); + next unless $context_group; + + my $context = gbn($context_group, 'context'); + my $msg_id = $context->textContent; + $trans->setAttribute('id', $msg_id); +} + +if ($outfile) { + open OUTFILE, '>', $outfile; + print OUTFILE $doc->toString(1); +} else { + print $doc->toString(1) . "\n"; +} + + + + + -- 2.11.0