Lab 4.2: XLIFF Transformation & PO File Parsing
Act as a localization engineer managing translation interchange payloads.
Objective
In this hands-on lab, you will act as a localization engineer managing translation interchange payloads. You will inspect and edit an XLIFF 2.0 asset to verify inline code protection (<ph>) and segment states, audit and repair a Gettext PO file to fix missing contexts (msgctxt) and broken plural arrays (msgstr[N]), and validate both files against build pipeline standards in Visual Studio Code.
Required Setup & Prerequisites
Editor: Visual Studio Code installed.
Working Directory: Open your
loc_labworking directory in VS Code.
Step-by-Step Instructions
Step 1: Create the XLIFF 2.0 Delivery Asset (app_ja.xlf)
Open VS Code and navigate to
assets/loc/software/.Create a file named
app_ja.xlfand paste the following XLIFF 2.0 interchange document:
XML
app_ja.xlfxml<?xml version="1.0" encoding="UTF-8"?> <xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en" trgLang="ja"> <file id="f_dashboard" original="src/components/Dashboard.json"> <unit id="u_greeting"> <notes> <note priority="1">Login banner greeting. Keep variable tag intact.</note> </notes> <segment state="initial"> <source>Welcome back, <ph id="0" dataRef="d1"/>!</source> <target>おかえりなさい、<ph id="0" dataRef="d1"/>様!</target> </segment> </unit> <unit id="u_sync_status"> <segment state="initial"> <source>All files synchronized.</source> <target></target> </segment> </unit> </file> </xliff>
Save
app_ja.xlf.
Step 2: Audit and Complete XLIFF Segment States
Open
app_ja.xlfin VS Code.Inspect
unit id="u_greeting":Notice that the translation payload
<target>contains localized Japanese text and the protected variable tag<ph id="0" dataRef="d1"/>.However,
state="initial"is still set on the<segment>tag.
Update
state="initial"tostate="translated"foru_greeting.Inspect
unit id="u_sync_status":Complete the translation by adding target text inside
<target>:すべてのファイルが同期されました。.Change
state="initial"tostate="translated".
Save
app_ja.xlf.
Step 3: Create and Repair a Corrupted Gettext PO File (messages_pl.po)
Navigate to
assets/loc/software/and createmessages_pl.po.Paste the following broken PO file containing a missing context collision and an incomplete Polish plural array:
Code snippet
messages_pl.po# Localization payload for Polish release msgid "" msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" # Context collision: "File" as a verb vs noun msgid "File" msgstr "Plik" # Broken plural payload: Polish requires 3 plural forms (msgstr[0], msgstr[1], msgstr[2]) msgid "One item deleted." msgid_plural "%d items deleted." msgstr[0] "%d element został usunięty." msgstr[1] "%d elementy zostały usunięte."
Save
messages_pl.po.
Step 4: Disambiguate Context and Complete Plural Array in PO File
Open
messages_pl.poin VS Code.Fix Context Collision:
To prevent the software engine from confusing "File" (noun) with "File" (verb action), add a
msgctxtdisambiguation block beforemsgid "File":
Code snippet
msgctxt "noun_single_file" msgid "File" msgstr "Plik"Fix Incomplete Polish Plural Array:
Inspect the
Plural-Formsheader:nplurals=3indicates Polish requires 3 distinct plural indices (0,1,2).Notice that
messages_pl.pois missingmsgstr[2](for counts ending in 5–20 or 0).Add the missing
msgstr[2]index to line 16:
Code snippet
messages_pl_clean.pomsgid "One item deleted." msgid_plural "%d items deleted." msgstr[0] "%d element został usunięty." msgstr[1] "%d elementy zostały usunięte." msgstr[2] "%d elementów zostało usuniętych."Save the file as
messages_pl_clean.po.
Self-Verification Checklist
Check your remediated interchange assets against these production criteria before completing Lab 4.2:
[ ]
app_ja.xlfcontains non-empty<target>tags withstate="translated"on all segments.[ ] Inline placeholder tags (
<ph id="0"/>) insideapp_ja.xlfare preserved verbatim between<source>and<target>.[ ]
messages_pl_clean.poincludesmsgctxtto disambiguate string contexts.[ ]
messages_pl_clean.podefines all 3 Polish plural array positions (msgstr[0],msgstr[1],msgstr[2]).
Ready to move on?
Mark this lesson complete when you’re ready.