--- /dev/null
+#!/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.
+#
+# <trans-unit xml:space="preserve" id="52" approved="no">
+# <source>Sort Priority</source>
+# <target state="needs-translation">Sort Priority</target>
+# <context-group name="po-reference" purpose="location">
+# <context context-type="sourcefile">1f93d86f7ad773b5f4232b60fff10567179f28f4</context>
+# </context-group>
+# </trans-unit>
+#
+# Angular expaect the trans-unit id attribute to match the "sourcefile"
+# hash from the context group. This script makes that happen.
+# Result is:
+#
+# <trans-unit xml:space="preserve" id="1f93d86f7ad773b5f4232b60fff10567179f28f4" approved="no">
+# <source>Sort Priority</source>
+# <target state="needs-translation">Sort Priority</target>
+# <context-group name="po-reference" purpose="location">
+# <context context-type="sourcefile">1f93d86f7ad773b5f4232b60fff10567179f28f4</context>
+# </context-group>
+# </trans-unit>
+#
+# 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 <<DOCS;
+ Synopsis:
+
+ $0 messages.fr-CA.from-PO.xlf messages.fr-CA.xlf
+
+ 1. First param is input file.
+ 2. Second param is output file. Defaults to STDOUT.
+DOCS
+ exit(0);
+}
+
+# Returns the first element by tag name that's a child of $node.
+sub gbn {
+ my ($node, $name) = @_;
+ return $node->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";
+}
+
+
+
+
+