Struct ::exo::Language

Overview

Multilanguage text value

This value is capable of storing texts for multiple languages.

Methods

fn new() -> Language

Creates a new empty Language.

Example:

let lang = exo::Language::new();
assert!(lang is exo::Language);
fn new_en(en: String) -> Language

Creates a new Language with an englisch entry.

Example:

let lang = exo::Language::new_en("Hello");
assert_eq!(lang.get("en"), Some("Hello"));
fn new_de(en: String) -> Language

Creates a new Language with an german entry.

Example:

let lang = exo::Language::new_de("Hallo");
assert_eq!(lang.get("de"), Some("Hallo"));
fn new_multi(langs: Object) -> Language

Creates a new Language with multiple translations.

Example:

let lang = exo::Language::new_multi(#{"en": "Hello", "de": "Hallo"});
assert_eq!(lang.get("en"), Some("Hello"));
assert_eq!(lang.get("de"), Some("Hallo"));
fn try_from(inp) -> Result

Tries to creates a new Language from a generic value.

fn show(self, lang: String) -> String

Shows the text for the given langauge.

This function falls back to english if the text was not found. If english was also not found, it falls back to any language available.

Example:

let lang = exo::Language::new_multi(#{"en": "Hello", "de": "Hallo"});
assert_eq!(lang.show("en"), "Hello");
assert_eq!(lang.show("de"), "Hallo");
assert_eq!(lang.show("it"), "Hello");

let lang = exo::Language::new_multi(#{"it": "Ciao"});
assert_eq!(lang.show("en"), "Ciao");
assert_eq!(lang.show("de"), "Ciao");
assert_eq!(lang.show("it"), "Ciao");
fn get(self, lang: String) -> Option

Returns the text for a specific language when available.

Example:

let lang = exo::Language::new_multi(#{"en": "Hello", "de": "Hallo"});
assert_eq!(lang.get("en"), Some("Hello"));
assert_eq!(lang.get("de"), Some("Hallo"));
fn set(self, lang: String, text: String) -> Tuple

Sets the text for a specific language when available.

Example:

let lang = exo::Language::new();
lang.set("de", "Hallo");
assert_eq!(lang.get("de"), Some("Hallo"));

Protocols

protocol index_get
let output = value[index]

Try to get the text for a specific language by it's index string.

Example:

let lang = exo::Language::new_de("Hallo");
assert_eq!(lang["de"], "Hallo");
protocol index_set
value[index] = input

Sets the text for a specific language by it's index string.

Example:

let lang = exo::Language::new();
lang["de"] = "Hallo";
assert_eq!(lang["de"], "Hallo");
protocol partial_eq
if value == b { }

Allows for partial equality operations to work.

protocol string_debug
println("{:?}", value)

Allows the value to be debug printed.

protocol string_display
println("{}", value)

Allows the value to be display printed.