Skip to content

luxe API (2025.1.2)


luxe: string module


Loc

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 returns unknown

The default space for localisations, \"game\".

Loc.missing_string returns unknown

The missing string fallback for the engine, typically \"MISSING.STRING\".

Loc.set_primary(language: String) returns None

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

Loc.get_primary() returns unknown

Get the primary language.

Loc.set_language(language: String) returns None

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

Loc.get_language() returns unknown

Get the current language.

Loc.add_language(language: String, plural_form: String) returns 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) returns None

Add a string to the localisation system.

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

Add a plural string to the localisation system.

Loc.get(language: String, space: String, key: String) returns 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) returns 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) returns 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) returns 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) returns 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) returns 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) returns Bool

no docs found

Loc.load_language(asset_id: String) returns Bool

no docs found

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

no docs found

Str

import "luxe: string" for Str

Utility class for String functions.

  • split_lines(string: String)
  • split(string: String, delim: String)
  • indent_strip(string: String)
  • indent(string: String)
  • trim(string: String)
  • compare(a: String, b: String)
  • replace(string: String, sub: String, repl: String)
  • is_alphanumeric(str: String)
  • is_numeric(str: String)
  • increment_end(string: String)
  • vec(value: Vec)
  • vec(value: Vec, precision: Num)
  • vec(value: Vec, precision: Num, sep: String)
  • fixed(number: Num, precision: Num)
  • fixed(number: Num)
  • fixed(number: Num, precision: Num, padded: Bool)
  • hex(number: Num)
  • binary(number: Num)
  • binary(number: Num, bit_width: Num)
  • path_is_absolute(path: String)
  • path_directory(path: String)
  • path_filename(path: String)
  • path_extension(path: String)
  • path_extensionless(path: String)
  • bytes_formatted(byte_count: Num)
  • bytes_formatted(byte_count: Num, precision: Num)
  • upper(string: String)
  • lower(string: String)
  • wrap(string: String, column: Num)
  • path(path: String)
  • strip_markup(string: String)
  • path_normalize(string: String)
  • format(string: String, arg0: Any)
  • format(string: String, arg0: Any, arg1: Any)
  • format(string: String, arg0: Any, arg1: Any, arg2: Any)
  • format(string: String, arg0: Any, arg1: Any, arg2: Any, arg3: Any)
  • format(string: String, arg0: Any, arg1: Any, arg2: Any, arg3: Any, arg4: Any)
  • format(string: String, arg0: Any, arg1: Any, arg2: Any, arg3: Any, arg4: Any, arg5: Any)
  • format(string: String, arg0: Any, arg1: Any, arg2: Any, arg3: Any, arg4: Any, arg5: Any, arg6: Any)
  • format(string: String, arg0: Any, arg1: Any, arg2: Any, arg3: Any, arg4: Any, arg5: Any, arg6: Any, arg7: Any)
  • format(string: String, arg0: Any, arg1: Any, arg2: Any, arg3: Any, arg4: Any, arg5: Any, arg6: Any, arg7: Any, arg8: Any)
  • format(string: String, arg0: Any, arg1: Any, arg2: Any, arg3: Any, arg4: Any, arg5: Any, arg6: Any, arg7: Any, arg8: Any, arg9: Any)
  • 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)
  • 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)
  • 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)
  • 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)
  • 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)
  • format_list(string: String, args: List)
  • valid(string: String)
  • template(string: String, key_value_context: Map)

Str.split_lines(string: String) returns 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) returns 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) returns 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) returns 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) returns 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) returns 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) returns 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) returns 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) returns 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("3¾")) //false

Str.increment_end(string: String) returns String

no docs found

Str.vec(value: Vec) returns String

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

Str.vec(value: Vec, precision: Num) returns 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) returns 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) returns String

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

Str.fixed(number: Num) returns String

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

Str.fixed(number: Num, precision: Num, padded: Bool) returns 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.hex(number: Num) returns String

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

Str.binary(number: Num) returns String

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

Str.binary(number: Num, bit_width: Num) returns 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) returns Bool

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

Str.path_directory(path: String) returns String

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

Str.path_filename(path: String) returns String

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

Str.path_extension(path: String) returns String

Get the extension of a path pointing to a file.

Str.path_extensionless(path: String) returns String

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

Str.bytes_formatted(byte_count: Num) returns 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) returns 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) returns String

Converts a string to all uppercase.

Str.lower(string: String) returns String

Converts a string to all lowercase.

Str.wrap(string: String, column: Num) returns 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) returns String

Normalize a path.

Str.strip_markup(string: String) returns String

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

Str.path_normalize(string: String) returns String

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

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

no docs found

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

no docs found

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

no docs found

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

no docs found

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

no docs found

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

no docs found

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

no docs found

Str.format(string: String, arg0: Any, arg1: Any, arg2: Any, arg3: Any, arg4: Any, arg5: Any, arg6: Any, arg7: Any) returns 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) returns 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) returns 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) returns 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) returns 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) returns 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) returns 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) returns String

no docs found

Str.format_list(string: String, args: List) returns 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) returns Bool

Check if string is null or empty

Str.template(string: String, key_value_context: Map) returns 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