Bakerversity
Module 4: Respecting the Reader's Time & EyesLesson 5 of 8

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_lab working directory in VS Code.

Step-by-Step Instructions

Step 1: Create the XLIFF 2.0 Delivery Asset (app_ja.xlf)

  1. Open VS Code and navigate to assets/loc/software/.

  2. Create a file named app_ja.xlf and 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>
  1. Save app_ja.xlf.

Step 2: Audit and Complete XLIFF Segment States

  1. Open app_ja.xlf in VS Code.

  2. 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.

  3. Update state="initial" to state="translated" for u_greeting.

  4. Inspect unit id="u_sync_status":

    • Complete the translation by adding target text inside <target>: すべてのファイルが同期されました。.

    • Change state="initial" to state="translated".

  5. Save app_ja.xlf.

Step 3: Create and Repair a Corrupted Gettext PO File (messages_pl.po)

  1. Navigate to assets/loc/software/ and create messages_pl.po.

  2. 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."
  1. Save messages_pl.po.

Step 4: Disambiguate Context and Complete Plural Array in PO File

  1. Open messages_pl.po in VS Code.

  2. Fix Context Collision:

    • To prevent the software engine from confusing "File" (noun) with "File" (verb action), add a msgctxt disambiguation block before msgid "File":

    Code snippet

    msgctxt "noun_single_file"
    msgid "File"
    msgstr "Plik"
    
  3. Fix Incomplete Polish Plural Array:

    • Inspect the Plural-Forms header: nplurals=3 indicates Polish requires 3 distinct plural indices (0, 1, 2).

    • Notice that messages_pl.po is missing msgstr[2] (for counts ending in 5–20 or 0).

    • Add the missing msgstr[2] index to line 16:

    Code snippet

    messages_pl_clean.po
    msgid "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."
  4. 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.xlf contains non-empty <target> tags with state="translated" on all segments.

  • [ ] Inline placeholder tags (<ph id="0"/>) inside app_ja.xlf are preserved verbatim between <source> and <target>.

  • [ ] messages_pl_clean.po includes msgctxt to disambiguate string contexts.

  • [ ] messages_pl_clean.po defines all 3 Polish plural array positions (msgstr[0], msgstr[1], msgstr[2]).


Ready to move on?

Mark this lesson complete when you’re ready.

→ Sign in to track your progress