Class XliffBuilder
Constructs XLIFF 1.2 documents and trans-units in the shape this codebase uses across every loc surface
(main game loc, Ecopedia, Web Client). Companion to XliffFormatter: Builder produces the
XLinq tree, Formatter serialises it to bytes that match translate-toolkit's (Weblate's) conventions.
Inheritance
System.Object
XliffBuilder
Assembly: Eco.Shared.dll
Syntax
public static class XliffBuilder : Object
Fields
Ns
Declaration
public static readonly XNamespace Ns
Field Value
| Type |
Description |
| System.Xml.Linq.XNamespace |
|
ObsoleteNoteText
Marker text on a <note from="developer"> that flags a trans-unit as obsolete.
Replaces the pre-Weblate <target state="obsolete"> convention, which Weblate doesn't recognise.
Declaration
public const string ObsoleteNoteText = "Obsolete string"
Field Value
| Type |
Description |
| System.String |
|
XmlNs
Declaration
public static readonly XNamespace XmlNs
Field Value
| Type |
Description |
| System.Xml.Linq.XNamespace |
|
Methods
BuildDocument(String, String, String, XElement)
Standard XLIFF 1.2 document scaffold around a body element. original is the
<file original="..."> attribute used to identify the surface ("defaultstrings", "EcopediaStrings",
"WebClientStrings").
Declaration
public static XDocument BuildDocument(string sourceLang, string targetLang, string original, XElement body)
Parameters
| Type |
Name |
Description |
| System.String |
sourceLang |
|
| System.String |
targetLang |
|
| System.String |
original |
|
| System.Xml.Linq.XElement |
body |
|
Returns
| Type |
Description |
| System.Xml.Linq.XDocument |
|
BuildTextElement(XName, String, Boolean)
Builds a <source> or <target> element with xml:space="preserve". When
wrapPlaceholders is true, {N} substrings are wrapped as <ph id="N">{N}</ph>
(main-loc strings only); otherwise the text becomes the element's verbatim value.
xml:space="preserve" is critical: without it, the serialiser injects indentation inside the element
(e.g. between adjacent <ph> children), corrupting round-trip text content.
Declaration
public static XElement BuildTextElement(XName name, string text, bool wrapPlaceholders = false)
Parameters
| Type |
Name |
Description |
| System.Xml.Linq.XName |
name |
|
| System.String |
text |
|
| System.Boolean |
wrapPlaceholders |
|
Returns
| Type |
Description |
| System.Xml.Linq.XElement |
|
BuildTransUnit(Int32, String, String, Boolean)
Trans-unit with an integer id — Ecopedia / WebClient convention. Source/target are plain text with
xml:space="preserve"; no placeholder wrapping (those surfaces don't use {N} syntax).
When markNeedsTranslation is true, sets state="needs-translation" on <target>
instead of writing the target text — used when bootstrapping skeletons or untranslated entries.
Declaration
public static XElement BuildTransUnit(int id, string source, string target, bool markNeedsTranslation = false)
Parameters
| Type |
Name |
Description |
| System.Int32 |
id |
|
| System.String |
source |
|
| System.String |
target |
|
| System.Boolean |
markNeedsTranslation |
|
Returns
| Type |
Description |
| System.Xml.Linq.XElement |
|
BuildTransUnit(String, String, String, String, Boolean)
Trans-unit with a text id — main-loc convention where id = the English text verbatim.
<source> and <target> both go through BuildTextElement(XName, String, Boolean) with placeholder
wrapping enabled by default. Optional developer note is appended as <note from="developer">.
Declaration
public static XElement BuildTransUnit(string id, string source, string target, string developerNote = null, bool wrapPlaceholders = true)
Parameters
| Type |
Name |
Description |
| System.String |
id |
|
| System.String |
source |
|
| System.String |
target |
|
| System.String |
developerNote |
|
| System.Boolean |
wrapPlaceholders |
|
Returns
| Type |
Description |
| System.Xml.Linq.XElement |
|
GetBody(XDocument)
The only correct way to navigate to the body of an XLIFF document we author.
Declaration
public static XElement GetBody(XDocument doc)
Parameters
| Type |
Name |
Description |
| System.Xml.Linq.XDocument |
doc |
|
Returns
| Type |
Description |
| System.Xml.Linq.XElement |
|
IsObsolete(XElement)
True if unit carries the obsolete marker
(<note from="developer">Obsolete string</note>).
Declaration
public static bool IsObsolete(XElement unit)
Parameters
| Type |
Name |
Description |
| System.Xml.Linq.XElement |
unit |
|
Returns
| Type |
Description |
| System.Boolean |
|
MarkObsolete(XElement)
Marks unit obsolete: adds the obsolete developer note and sets
translate="no" so Weblate skips the entry. Target content (existing translation) is preserved
— we don't want to waste translator work in case the entry comes back. Idempotent.
Declaration
public static void MarkObsolete(XElement unit)
Parameters
| Type |
Name |
Description |
| System.Xml.Linq.XElement |
unit |
|
UnObsolete(XElement)
Removes the obsolete marker from unit. Also removes translate="no"
UNLESS another non-obsolete reason for it exists (any "Chat command"-family developer note that
isn't a "Help text for chat command" entry). Idempotent.
Declaration
public static void UnObsolete(XElement unit)
Parameters
| Type |
Name |
Description |
| System.Xml.Linq.XElement |
unit |
|