Skip to content

luxe: string


import "luxe: string" for Loc

Interface 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 strings
Log.print(Strings.get(Loc.get_language())) //null
Log.print(Strings.get(Loc.get_primary())) //en
Loc.set_language("en")
Log.print(Loc.get("start_game")) //MISSING.STRING
//as soon as we add a line, we can query it
Loc.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 language
Log.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 returned
Loc.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 get
Loc.set_language("tp")
Log.print(Loc.get("start_game")) //o open e musi!

Loc.default_space : unknown

The default space for localisations, “game”.

Loc.missing_string : unknown

The missing string fallback for the engine, typically “MISSING.STRING”.

Loc.set_primary(language : String) : None

Set the primary language that is used as fallback if a key can’t be found in another language.

Loc.get_primary() : unknown

Get the primary language.

Loc.set_language(language : String) : None

Set the current language that strings are gotten for unless specified otherwise.

Loc.get_language() : unknown

Get the current language.

Loc.add_language(language : String, plural_form : String) : unknown

Add a language with the given id and plural_form expression string (just the expression part, not the whole header).

Loc.add(language : String, space : String, key : String, string : String) : None

Add a string to the localisation system.

Loc.add_plural(language : String, space : String, key : String, strings : List) : None

Add a plural string to the localisation system.

Loc.get(language : String, space : String, key : String) : String

Get the string for a key (or fallback in primary language) from the localisation system for a specific language/space.

Loc.has(language : String, space : String, key : String) : Bool

Check if the string for a key exists in the localisation system for a specific language/space.

Loc.get_plural(language : String, space : String, key : String, count : Num) : String

Get the string for a key from the localisation system for a specific language/space, with the plural count.

Loc.get(space : String, key : String) : String

Get 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(key : String) : String

Get 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(key : String) : Bool

Check if the string for a key exists in the localisation system for the current language and default space

Loc.load_primary(asset_id : String) : Bool

no docs found

Loc.load_language(asset_id : String) : Bool

no docs found

Loc.load_language(asset_id : String, primary : Bool) : Bool

no docs found

import "luxe: string" for Str

Utility class for String functions.

Str.split_lines(string : String) : List

Split a string into its lines. Returns [""] for empty strings.

var multiline_string = \"\"\"
leaf
tree
fruit
mushroom
\"\"\"
var split_string = Str.split_lines(multiline_string)
Log.print(split_string) //[leaf, tree, fruit, mushroom]

Str.split(string : String, delim : String) : List

Deprecated 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(string : String) : String

Removes 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 = \"\"\"
Sparrow
Pidgeon
Crow
\"\"\"
var unindented = Str.indent_strip(input)
Log.print(unindented) //Sparrow\nPidgeon\n Crow

Str.indent(string : String) : Num

returns 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(string : String) : String

Trims whitespace characters (” ”, “\n”, “\t”) from front and end of an string. Calls wren core String.trim internally.

var input = " \n\t Pallas's cat \n\t "
var trimmed = Str.trim(input)
Log.print(trimmed) //Pallas's cat

Str.compare(a : String, b : String) : Num

Comparison function for strings. Order is based on the unicode number of the first non-equal codepoint or length. Returns 1 when a > b Returns -1 when a < b returns 0 when theyre equal

Log.print(Str.compare("a", "b")) // -1
Log.print(Str.compare("a", "Z")) // 1
Log.print(Str.compare("abc", "abc")) // 0
Log.print(Str.compare("abc", "abcd")) // -1
Log.print(Str.compare("ö", "ä")) // 1

Str.replace(string : String, sub : String, repl : String) : String

Replace all occurances of one substring with another. Call wren core String.replace internally.

var input = "Hello World"
var replaced = Str.replace(input, "o", "ø")
Log.print(replaced) //Hellø Wørld

Str.is_alphanumeric(str : String) : Bool

Get whether all characters in a string are alphanumeric (uppercase or lowercase latin characters or arabic numerals)

Log.print(Str.is_alphanumeric("Leaf")) //true
Log.print(Str.is_alphanumeric("4Leaf")) //true
Log.print(Str.is_alphanumeric("4-leaf")) //false
Log.print(Str.is_alphanumeric("Wørld")) //false

Str.is_numeric(str : String) : Bool

Get whether all characters in a string are numeric (arabic numerals)

Log.print(Str.is_alphanumeric("Leaf")) //false
Log.print(Str.is_alphanumeric("4")) //true
Log.print(Str.is_alphanumeric("4-leaf")) //false
Log.print(Str.is_alphanumeric("")) //false

Str.increment_end(string : String) : String

no docs found

Str.vec(value : Vec) : String

Get the string representation of a vector. (uses 6 digits after decimal point and spaces between numbers)

Str.vec(value : Vec, precision : Num) : String

Get the string representation of a vector with the specified digits after the decimal point. (puts spaces between numbers)

Str.vec(value : Vec, precision : Num, sep : String) : String

Get 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.141593
Log.print(Str.print(vector, 2)) //1 2 3.14
Log.print(Str.print(vector, 1, ", ")) //1, 2, 3.1

Str.fixed(number : Num, precision : Num) : String

Get the string representation of a number with a specified amount of digits after the decimal point.

Str.fixed(number : Num) : String

Get the string representation of a number with 6 digits after the decimal points.

Str.fixed(number : Num, precision : Num, padded : Bool) : String

Get 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(string : String) : String

no docs found

Str.hex(number : Num) : String

Get string representation of number in base-16/hexadecimal.

Str.binary(number : Num) : String

Get string representation of number in base-2/binary.

Str.binary(number : Num, bit_width : Num) : String

Get string representation of (positive integer) number in base-2/binary. bit_width declares to how many digits the number should be expanded (adds zeroes to left of it).

Str.path_is_absolute(path : String) : Bool

Get whether a path is absolute (instead of relative).

Str.path_directory(path : String) : String

Get the directory path of a path pointing to a file.

Str.path_filename(path : String) : String

Get the filename (including extension) of a path pointing to a file.

Str.path_extension(path : String) : String

Get the extension of a path pointing to a file.

Str.path_extensionless(path : String) : String

Get the filename (excluding extension) of a path pointing to a file.

Str.bytes_formatted(byte_count : Num) : String

Get 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(byte_count : Num, precision : Num) : String

Get a byte size as bytes/KB/MB/GB/TB (whichever is the biggest unit that is at least 1) with precision digits after the decimal place.

Str.upper(string : String) : String

Converts a string to all uppercase.

Str.lower(string : String) : String

Converts a string to all lowercase.

Str.wrap(string : String, column : Num) : String

Wraps text on spaces to keep line length within column width. Does not break words that are longer than column width.

Str.path(path : String) : String

Normalize a path.

Str.strip_markup(string : String) : String

Strips the luxe markup formatting from the given string, returning the raw value

Str.path_normalize(string : String) : String

Normalizes the path also resolving ../ and ./ and so on

Str.format(string : String, arg0 : Any) : String

no docs found

Str.format(string : String, arg0 : Any, arg1 : Any) : String

no docs found

Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any) : String

no docs found

Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any) : String

no docs found

Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any) : String

no docs found

Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any) : String

no docs found

Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any) : String

no docs found

Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any, arg7 : Any) : String

no docs found

Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any, arg7 : Any, arg8 : Any) : String

no docs found

Str.format(string : String, arg0 : Any, arg1 : Any, arg2 : Any, arg3 : Any, arg4 : Any, arg5 : Any, arg6 : Any, arg7 : Any, arg8 : Any, arg9 : Any) : String

no docs found

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) : String

no docs found

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) : String

no docs found

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) : String

no docs found

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) : String

no docs found

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) : String

no docs found

Str.format_list(string : String, args : List) : String

Format the string, replacing placeholder with other text. Placeholders are in the format {x}, where x is an index into the arguments list of format_list, or a numbered argument in the format function. 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 Roots
Log.print(Str.format("{2} {1} {0}", "Crown", "Trunk", "Roots")) //Roots Trunk Crown
Log.print(Str.format("{0} {0} {1}", "Duck", "Goose")) //Duck Duck Goose

Str.valid(string : String) : Bool

Check if string is null or empty

Str.template(string : String, key_value_context : Map) : unknown

A 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 do Str.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 with toString if not a string.

Log.print(Str.template("hello <[user.name]>", {"user.name" : "luxe"})) //hello luxe