luxe: string
import "luxe: string" for LocInterface for the localisation system.
Each translation always exists in a space and in a language. Spaces are contexts, so you might want different spaces for dialogue/menus/icons. Or you can leave everything in the default “game” translation space.
Unless specified otherwise, the system will fetch the string from the currently active language if possible, if its not available there it will fall back to the set primary language. If the key isn’t registered for that either, “MISSING.STRING” will be returned.
By default there is no active active language set and the primary language is “en”.
//by default language is not set and primary language is `en` with no registered stringsLog.print(Strings.get(Loc.get_language())) //nullLog.print(Strings.get(Loc.get_primary())) //enLoc.set_language("en")Log.print(Loc.get("start_game")) //MISSING.STRING//as soon as we add a line, we can query itLoc.add("en", Loc.default_space, "start_game", "Start Game!")Log.print(Loc.get("start_game")) //Start Game!//if we query a word in a language where that translation doesnt exist yet (like toki pona here), it falls back to the primary languageLog.print(Loc.get("tp", Loc.default_space, "start_game")) //Start Game!//but as soon as it is registered, the translation in the respective language is returnedLoc.add("tp", Loc.default_space, "start_game", "o open e musi!")Log.print(Loc.get("tp", Loc.default_space, "start_game")) //o open e musi!//same when we set the current language and use the shorthand getLoc.set_language("tp")Log.print(Loc.get("start_game")) //o open e musi!
Loc.default_space
Section titled “Loc.default_space”Loc.default_space : unknownThe default space for localisations, “game”.
Loc.missing_string
Section titled “Loc.missing_string”Loc.missing_string : unknownThe missing string fallback for the engine, typically “MISSING.STRING”.
Loc.set_primary(.)
Section titled “Loc.set_primary(.)”Loc.set_primary(language : String) : NoneSet the primary language that is used as fallback if a key can’t be found in another language.
Loc.get_primary(.)
Section titled “Loc.get_primary(.)”Loc.get_primary() : unknownGet the primary language.
Loc.set_language(.)
Section titled “Loc.set_language(.)”Loc.set_language(language : String) : NoneSet the current language that strings are gotten for unless specified otherwise.
Loc.get_language(.)
Section titled “Loc.get_language(.)”Loc.get_language() : unknownGet the current language.
Loc.add_language(..)
Section titled “Loc.add_language(..)”Loc.add_language(language : String, plural_form : String) : unknownAdd a language with the given
idandplural_formexpression string (just the expression part, not the whole header).
Loc.add(…)
Section titled “Loc.add(…)”Loc.add(language : String, space : String, key : String, string : String) : NoneAdd a string to the localisation system.
Loc.add_plural(…)
Section titled “Loc.add_plural(…)”Loc.add_plural(language : String, space : String, key : String, strings : List) : NoneAdd a plural string to the localisation system.
Loc.get(…)
Section titled “Loc.get(…)”Loc.get(language : String, space : String, key : String) : StringGet the string for a key (or fallback in primary language) from the localisation system for a specific language/space.
Loc.has(…)
Section titled “Loc.has(…)”Loc.has(language : String, space : String, key : String) : BoolCheck if the string for a key exists in the localisation system for a specific language/space.
Loc.get_plural(…)
Section titled “Loc.get_plural(…)”Loc.get_plural(language : String, space : String, key : String, count : Num) : StringGet the string for a key from the localisation system for a specific language/space, with the plural count.
Loc.get(..)
Section titled “Loc.get(..)”Loc.get(space : String, key : String) : StringGet the string for a key (or fallback in primary language) from the localisation system in the current language and in a specific space.
Loc.get(.)
Section titled “Loc.get(.)”Loc.get(key : String) : StringGet the string for a key (or fallback in primary language) from the localisation system in the current language and in the default space.
Loc.has(.)
Section titled “Loc.has(.)”Loc.has(key : String) : BoolCheck if the string for a key exists in the localisation system for the current language and default space
Loc.load_primary(.)
Section titled “Loc.load_primary(.)”Loc.load_primary(asset_id : String) : Boolno docs found
Loc.load_language(.)
Section titled “Loc.load_language(.)”Loc.load_language(asset_id : String) : Boolno docs found
Loc.load_language(..)
Section titled “Loc.load_language(..)”Loc.load_language(asset_id : String, primary : Bool) : Boolno docs found
import "luxe: string" for StrUtility class for String functions.
Str.split_lines(.)
Section titled “Str.split_lines(.)”Str.split_lines(string : String) : ListSplit a string into its lines. Returns
[""]for empty strings.var multiline_string = \"\"\"leaftreefruitmushroom\"\"\"var split_string = Str.split_lines(multiline_string)Log.print(split_string) //[leaf, tree, fruit, mushroom]
Str.split(..)
Section titled “Str.split(..)”Str.split(string : String, delim : String) : ListDeprecated use
string.split(delim)Split a string at every occurance of an delimiter.var input = "Owl eats Squirrel eats Nuts"var split_string = Str.split(input, " eats ")Log.print(split_string) //[Owl, Squirrel, Nuts]
Str.indent_strip(.)
Section titled “Str.indent_strip(.)”Str.indent_strip(string : String) : StringRemoves indentation from the first line of a string, and the same amount from subsequent lines if any. Lines with shorter indentation than the first line are skipped.
var input = \"\"\"SparrowPidgeonCrow\"\"\"var unindented = Str.indent_strip(input)Log.print(unindented) //Sparrow\nPidgeon\n Crow
Str.indent(.)
Section titled “Str.indent(.)”Str.indent(string : String) : Numreturns how much indentation characters (whitespace or tabs) a string has.
var line = "\t text"var indent = Str.indent(line)Log.print(indent) //3
Str.trim(.)
Section titled “Str.trim(.)”Str.trim(string : String) : StringTrims whitespace characters (” ”, “\n”, “\t”) from front and end of an string. Calls wren core
String.triminternally.var input = " \n\t Pallas's cat \n\t "var trimmed = Str.trim(input)Log.print(trimmed) //Pallas's cat
Str.compare(..)
Section titled “Str.compare(..)”Str.compare(a : String, b : String) : NumComparison function for strings. Order is based on the unicode number of the first non-equal codepoint or length. Returns
1whena > bReturns-1whena < breturns0when theyre equalLog.print(Str.compare("a", "b")) // -1Log.print(Str.compare("a", "Z")) // 1Log.print(Str.compare("abc", "abc")) // 0Log.print(Str.compare("abc", "abcd")) // -1Log.print(Str.compare("ö", "ä")) // 1
Str.replace(…)
Section titled “Str.replace(…)”Str.replace(string : String, sub : String, repl : String) : StringReplace all occurances of one substring with another. Call wren core
String.replaceinternally.var input = "Hello World"var replaced = Str.replace(input, "o", "ø")Log.print(replaced) //Hellø Wørld
Str.is_alphanumeric(.)
Section titled “Str.is_alphanumeric(.)”Str.is_alphanumeric(str : String) : BoolGet whether all characters in a string are alphanumeric (uppercase or lowercase latin characters or arabic numerals)
Log.print(Str.is_alphanumeric("Leaf")) //trueLog.print(Str.is_alphanumeric("4Leaf")) //trueLog.print(Str.is_alphanumeric("4-leaf")) //falseLog.print(Str.is_alphanumeric("Wørld")) //false
Str.is_numeric(.)
Section titled “Str.is_numeric(.)”Str.is_numeric(str : String) : BoolGet whether all characters in a string are numeric (arabic numerals)
Log.print(Str.is_alphanumeric("Leaf")) //falseLog.print(Str.is_alphanumeric("4")) //trueLog.print(Str.is_alphanumeric("4-leaf")) //falseLog.print(Str.is_alphanumeric("3¾")) //false
Str.increment_end(.)
Section titled “Str.increment_end(.)”Str.increment_end(string : String) : Stringno docs found
Str.vec(.)
Section titled “Str.vec(.)”Str.vec(value : Vec) : StringGet the string representation of a vector. (uses 6 digits after decimal point and spaces between numbers)
Str.vec(..)
Section titled “Str.vec(..)”Str.vec(value : Vec, precision : Num) : StringGet the string representation of a vector with the specified digits after the decimal point. (puts spaces between numbers)
Str.vec(…)
Section titled “Str.vec(…)”Str.vec(value : Vec, precision : Num, sep : String) : StringGet the string representation of a vector. You can specify both the precision (digits after decimal point) and the seperator of how the vector is rendered.
var vector = [1, 2, 3.14159265359]Log.print(Str.print(vector)) //1 2 3.141593Log.print(Str.print(vector, 2)) //1 2 3.14Log.print(Str.print(vector, 1, ", ")) //1, 2, 3.1
Str.fixed(..)
Section titled “Str.fixed(..)”Str.fixed(number : Num, precision : Num) : StringGet the string representation of a number with a specified amount of digits after the decimal point.
Str.fixed(.)
Section titled “Str.fixed(.)”Str.fixed(number : Num) : StringGet the string representation of a number with 6 digits after the decimal points.
Str.fixed(…)
Section titled “Str.fixed(…)”Str.fixed(number : Num, precision : Num, padded : Bool) : StringGet the string representation of a number with a specified amount of digits after the decimal point. If padded is true, this function adds zeroes until the requested amount of digits after the decimal point is reached.
Str.url_encode(.)
Section titled “Str.url_encode(.)”Str.url_encode(string : String) : Stringno docs found
Str.hex(.)
Section titled “Str.hex(.)”Str.hex(number : Num) : StringGet string representation of number in base-16/hexadecimal.
Str.binary(.)
Section titled “Str.binary(.)”Str.binary(number : Num) : StringGet string representation of number in base-2/binary.
Str.binary(..)
Section titled “Str.binary(..)”Str.binary(number : Num, bit_width : Num) : StringGet string representation of (positive integer) number in base-2/binary.
bit_widthdeclares to how many digits the number should be expanded (adds zeroes to left of it).
Str.path_is_absolute(.)
Section titled “Str.path_is_absolute(.)”Str.path_is_absolute(path : String) : BoolGet whether a path is absolute (instead of relative).
Str.path_directory(.)
Section titled “Str.path_directory(.)”Str.path_directory(path : String) : StringGet the directory path of a path pointing to a file.
Str.path_filename(.)
Section titled “Str.path_filename(.)”Str.path_filename(path : String) : StringGet the filename (including extension) of a path pointing to a file.
Str.path_extension(.)
Section titled “Str.path_extension(.)”Str.path_extension(path : String) : StringGet the extension of a path pointing to a file.
Str.path_extensionless(.)
Section titled “Str.path_extensionless(.)”Str.path_extensionless(path : String) : StringGet the filename (excluding extension) of a path pointing to a file.
Str.bytes_formatted(.)
Section titled “Str.bytes_formatted(.)”Str.bytes_formatted(byte_count : Num) : StringGet a byte size as bytes/KB/MB/GB/TB (whichever is the biggest unit that is at least 1) with 3 digits after the decimal place.
Str.bytes_formatted(..)
Section titled “Str.bytes_formatted(..)”Str.bytes_formatted(byte_count : Num, precision : Num) : StringGet a byte size as bytes/KB/MB/GB/TB (whichever is the biggest unit that is at least 1) with
precisiondigits after the decimal place.
Str.upper(.)
Section titled “Str.upper(.)”Str.upper(string : String) : StringConverts a string to all uppercase.
Str.lower(.)
Section titled “Str.lower(.)”Str.lower(string : String) : StringConverts a string to all lowercase.
Str.wrap(..)
Section titled “Str.wrap(..)”Str.wrap(string : String, column : Num) : StringWraps text on spaces to keep line length within column width. Does not break words that are longer than column width.
Str.path(.)
Section titled “Str.path(.)”Str.path(path : String) : StringNormalize a path.
Str.strip_markup(.)
Section titled “Str.strip_markup(.)”Str.strip_markup(string : String) : StringStrips the luxe markup formatting from the given string, returning the raw value
Str.path_normalize(.)
Section titled “Str.path_normalize(.)”Str.path_normalize(string : String) : StringNormalizes the path also resolving ../ and ./ and so on
Str.format(..)
Section titled “Str.format(..)”Str.format(string : String, arg0 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any, arg7 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any, arg7 : Any, arg8 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any, arg7 : Any, arg8 : Any, arg9 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any, arg7 : Any, arg8 : Any, arg9 : Any, arg10 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any, arg7 : Any, arg8 : Any, arg9 : Any, arg10 : Any, arg11 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any, arg7 : Any, arg8 : Any, arg9 : Any, arg10 : Any, arg11 : Any, arg12 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any, arg7 : Any, arg8 : Any, arg9 : Any, arg10 : Any, arg11 : Any, arg12 : Any, arg13 : Any) : Stringno docs found
Str.format(…)
Section titled “Str.format(…)”Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any, arg7 : Any, arg8 : Any, arg9 : Any, arg10 : Any, arg11 : Any, arg12 : Any, arg13 : Any, arg14 : Any) : Stringno docs found
Str.format_list(..)
Section titled “Str.format_list(..)”Str.format_list(string : String, args : List) : StringFormat the string, replacing placeholder with other text. Placeholders are in the format
{x}, wherexis an index into the arguments list offormat_list, or a numbered argument in theformatfunction. Placeholders can appear multiple times and do not need to appear in order.Log.print(Str.format("{0} {1} {2}", "Crown", "Trunk", "Roots")) //Crown Trunk RootsLog.print(Str.format("{2} {1} {0}", "Crown", "Trunk", "Roots")) //Roots Trunk CrownLog.print(Str.format("{0} {0} {1}", "Duck", "Goose")) //Duck Duck Goose
Str.valid(.)
Section titled “Str.valid(.)”Str.valid(string : String) : BoolCheck if string is null or empty
Str.template(..)
Section titled “Str.template(..)”Str.template(string : String, key_value_context : Map) : unknownA simple templating helper. Replace parts of the text with data from a given context map, by simple (non nested) string keys. For example, given the string
"hello <[user.name]>"we can doStr.template(string, {"user.name": name}). The keys are delimited with<[and ended with]>in the string. Any not matched, won’t be replaced. If you have a wren map with nested values,LX.flatten()can convert to simple key values for you. Values in the map are converted withtoStringif not a string.Log.print(Str.template("hello <[user.name]>", {"user.name" : "luxe"})) //hello luxe