PoTranslation

loreline.translation.PoTranslation (Class)

Converts GNU gettext PO file content into a Loreline translation file body.

Mapping: msgctxt "" -> # hash comment (preferred if present) msgid "" -> fallback for key if no msgctxt, else used as // <source> reference comment msgstr "" -> the translation text line

Empty msgstr -> entry skipped. Plural forms (msgstr[N]) -> take msgstr[0]. Multi-line msgid/msgstr (msgid ""\n"line1"\n"line2") -> concatenated.

PO files are mono-locale by design; the locale parameter is accepted for API uniformity with the other format converters but unused here.

msgstr must be valid Loreline body content. Its value is written verbatim into the synthesised .lor and re-parsed by Loreline. See the full rules in loreline.translation.TranslationFormats.

Static Members

toLoreline(content: String, locale: String): String
Name Type
content String
locale String
Returns
String

fromScript(script: loreline.AstNode, existing: Null<Map>, locale: String): String

Generates a PO file body for the given source script, suitable for the given locale. If existing is provided, entries already present there are preserved as the msgstr value; otherwise the msgstr defaults to the source text (placeholder).

Name Type
script loreline.AstNode
existing Null<Map>
locale String
Returns
String

Private Members

escapeForPoString(s: String): String

Escape a string for use inside a PO double-quoted string literal. Escapes \ -> \\ and " -> \". Other escapes (like \n from the Loreline printer) round-trip correctly because they get re-applied by the Loreline parser when the synthesized body is re-parsed.

Name Type
s String
Returns
String

Name Type
content String
Returns
Array<loreline.translation._PoTranslation.PoEntry>

readKeyword(line: String): String
Name Type
line String
Returns
String

readQuotedString(line: String, from: Int): String

Reads "..." starting at character offset from in line. Skips leading whitespace. Returns the unescaped content, or null if not a quoted string.

Name Type
line String
from Int
Returns
String

trimLeft(s: String): String
Name Type
s String
Returns
String

escapeLineForComment(s: String): String

Escape a string for use as a Loreline // ... line comment. Replaces newlines with spaces (line comments can't span lines).

Name Type
s String
Returns
String

escapeLineForBody(s: String): String

Escape a string for use as a Loreline text body line. Real newlines stay (Loreline groups consecutive non-blank lines into a single multi-line text block). The $ character is doubled to avoid triggering interpolation in the synthesized .lor content.

Name Type
s String
Returns
String

Metadata

Name Parameters
:hxGen -