glugify/unicode
Values
pub fn transliterate_text(
text: String,
) -> Result(String, errors.SlugifyError)
Transliterates Unicode text to ASCII equivalents.
This function converts accented characters, Cyrillic, Greek, typographic punctuation and common symbols to their ASCII equivalents. Decomposed (NFD) characters are handled by stripping combining marks and mapping the base character. Characters with no known mapping (such as emoji) are stripped from the output.
Examples
transliterate_text("café")
// -> Ok("cafe")
transliterate_text("naïve")
// -> Ok("naive")
transliterate_text("Résumé 🚀")
// -> Ok("Resume ")
pub fn transliterate_text_with(
text: String,
locale: locale.Locale,
ignore: List(String),
) -> Result(String, errors.SlugifyError)
Transliterates Unicode text to ASCII using locale-specific rules,
keeping the graphemes in ignore verbatim.
Locale rules take precedence over the general tables, so with
locale.German the text “Über” becomes “Ueber” rather than “Uber”.
Examples
import glugify/locale
transliterate_text_with("Über München", locale.German, [])
// -> Ok("Ueber Muenchen")
transliterate_text_with("嗨 hello", locale.Default, ["嗨"])
// -> Ok("嗨 hello")
pub fn validate_ascii_only(
text: String,
) -> Result(String, errors.SlugifyError)
Validates that text contains only ASCII characters.
This function checks that all characters in the input are within the printable ASCII range (32-126). Non-ASCII characters will cause an error to be returned.
Examples
validate_ascii_only("hello world")
// -> Ok("hello world")
validate_ascii_only("café")
// -> Error(TransliterationFailed("é"))
pub fn validate_ascii_or_unicode(
text: String,
allow_unicode: Bool,
ignore: List(String),
) -> Result(String, errors.SlugifyError)
Validates text based on Unicode allowance settings.
If allow_unicode is True, all text is accepted.
If allow_unicode is False, only ASCII text and graphemes listed
in ignore are accepted.
Examples
validate_ascii_or_unicode("café", True, [])
// -> Ok("café")
validate_ascii_or_unicode("café", False, [])
// -> Error(TransliterationFailed("é"))
validate_ascii_or_unicode("café", False, ["é"])
// -> Ok("café")