sea_orm_sluggable/transliterate.rs
1/// Turns text in any script into ASCII before it becomes a slug.
2///
3/// Implement it to support a language with its own romanization rules:
4///
5/// ```
6/// use sea_orm_sluggable::Transliterator;
7///
8/// struct Shouting;
9///
10/// impl Transliterator for Shouting {
11/// fn transliterate(&self, text: &str) -> String {
12/// text.to_uppercase()
13/// }
14/// }
15/// ```
16pub trait Transliterator: Send + Sync {
17 /// Returns `text` written with ASCII characters only.
18 fn transliterate(&self, text: &str) -> String;
19}
20
21/// Generic transliteration for every script, via the `any_ascii` crate.
22///
23/// Good enough for most text, but it does not know national rules:
24/// Ukrainian "Юрій" becomes "Yuriy" here and "Yurii" officially.
25#[derive(Debug, Clone, Copy, Default)]
26pub struct AnyAscii;
27
28impl Transliterator for AnyAscii {
29 fn transliterate(&self, text: &str) -> String {
30 any_ascii::any_ascii(text)
31 }
32}