CsvTranslation

loreline.translation.CsvTranslation (Class)

Converts CSV/TSV file content into a Loreline translation file body.

Requires a header row. Recognized columns (case-insensitive):

  • "key" (required, used as #key in the synthesized .lor)
  • "source" / "en" / "original" (optional, used as // <source> reference)
  • the column whose header equals locale = the translation, so a single multi-locale CSV (key, source, en, fr, es, de) can serve every locale.

Fallback: if no column header matches locale, the last column is used as the translation (legacy 2-column shape key, value).

Quoting follows RFC 4180: values containing the separator, quotes, or newlines must be wrapped in double-quotes; literal quotes are doubled ("").

The locale-column value must be valid Loreline body content. It 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

tsvToLoreline(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 CSV file body for the given source script and locale. The output has three columns: key, source, <locale>. If existing is provided, entries already present there are preserved as the translation value; otherwise the translation defaults to the source text.

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

tsvFromScript(script: loreline.AstNode, existing: Null<Map>, locale: String): String
Name Type
script loreline.AstNode
existing Null<Map>
locale String
Returns
String

Private Members

convert(content: String, sep: Int, locale: String): String
Name Type
content String
sep Int
locale String
Returns
String

generate(script: loreline.AstNode, existing: Null<Map>, locale: String, sep: Int): String
Name Type
script loreline.AstNode
existing Null<Map>
locale String
sep Int
Returns
String

escapeForCsvField(s: String, sep: Int): String

Escape a field for CSV/TSV output per RFC 4180. Wraps the value in double-quotes if it contains the separator, a quote, or a newline; and doubles any literal " to "" inside the wrapped value.

Name Type
s String
sep Int
Returns
String

findColumn(header: Array<String>, names: Array<String>): Int
Name Type
header Array<String>
names Array<String>
Returns
Int

findLocaleColumn(header: Array<String>, locale: String): Int
Name Type
header Array<String>
locale String
Returns
Int

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

parseRows(content: String, sep: Int): Array<Array<String>>
Name Type
content String
sep Int
Returns
Array<Array<String>>

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