Get the dictionary of this TString.
Get the current language of this TString. Throws an error if this is a floating TString with no language selected.
Attempt to translate this TString into one of a list of languages.
const ts = new TString({
en: "color",
de: "Farbe"
});
// We'd like British English or French but we'll get "en"
// (U.S. English) which is the best match for "en-GB"
console.log(ts.toLang(["en-GB", "fr"]), toString()); // "color"
Use the Language Stack Calculator to experiment with the search path that is used to find the best language match.
an array of BCP47 language codes in descending preference order
a new TString with its language
set to the best match
Render this TString as a string. When the TString contains plural
forms an appropriate plural will be chosen based on count
. The
correct plural form is chosen using Intl.PluralRules
.
// Plurals
const ts = new TString({
en: { one: "cat", other: "cats" },
de: { one: "Katze", other: "Katzen" }
});
console.log(ts.toLang(["de"]).toString(10)); // "Katzen"
an optional count to select a plural form
Cast a TString or TFatString to a TString. This and literal
are the
main ways of creating new a TString
.
either a fat string or an existing TString
an optional language
a TString which may be obj
if obj
is already a TString
Cast a string literal and language into a single-language TString.
This and cast
are the main ways of creating new a TString
.
const ts = TString.literal("Hello", "en");
// Try to convert to "de", won't work - we'll get "en" instead
console.log(ts.toLang["de"].language); // "en"
a regular string
the language of the string
a new TString
Generated using TypeDoc
Wrap a fat string with methods to coerce it to a specific language and stringify it. TStrings are immutable; all methods that appear to modify a TString return a new one.
To create a new
TString
callcast
orliteral
.