A Sui Move package providing validated ISO 639-1 language codes as on-chain types.
Formerly published as
gengo. Renamed tolanguage_codefor a literal, standard-named pairing withcountry_code.
language_code provides a LanguageCode struct that wraps a validated
two-letter ISO 639-1 language code string. All 184 standard codes are supported.
Invalid codes are rejected at construction time, so any LanguageCode value in
your program is always valid.
[dependencies]
language_code = { git = "https://github.com/unconfirmedlabs/language_code.git", rev = "main" }module example::my_module;
use language_code::language_code::{Self, LanguageCode};
public struct Post has key, store {
id: UID,
content: String,
language: LanguageCode,
}
public fun create_post(content: String, lang: String, ctx: &mut TxContext): Post {
Post {
id: object::new(ctx),
content,
language: language_code::new(lang), // aborts if invalid
}
}| Function | Signature | Description |
|---|---|---|
new |
public fun new(code: String): LanguageCode |
Creates a LanguageCode from a string. Aborts with EInvalidLanguageCode if the code is not a valid ISO 639-1 code. |
code |
public fun code(language_code: &LanguageCode): String |
Returns the underlying two-letter code string. |
LanguageCode— A wrapper struct withcopy,drop, andstoreabilities. Can be a field in other structs, stored in tables, and passed by value.
| Code | Name | Description |
|---|---|---|
| 0 | EInvalidLanguageCode |
The provided string is not a valid ISO 639-1 language code. |
All 184 ISO 639-1 two-letter codes, from aa (Afar) to zu (Zulu). See
the full ISO 639-1 list.
MIT