-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add textInfo / script metadata API to determine directionality of locale #3172
Comments
I did this for the meanwhile: /// Represents a language's reading direction.
#[derive(Copy, Clone, PartialEq)]
pub enum TextDirection {
Ltr,
Rtl,
}
pub trait HasTextDirection {
fn text_direction(&self) -> TextDirection;
}
impl HasTextDirection for locale::Locale {
fn text_direction(&self) -> TextDirection {
self.id.text_direction()
}
}
impl HasTextDirection for locale::LanguageIdentifier {
fn text_direction(&self) -> TextDirection {
self.language.text_direction()
}
}
impl HasTextDirection for locale::subtags::Language {
fn text_direction(&self) -> TextDirection {
match self.as_str() {
| "ar" | "ara"
| "arc"
| "az" | "aze"
| "dv" | "div"
| "he" | "heb"
| "ku" | "kur"
| "fa" | "per" | "fas"
| "ur" | "urd"
=> TextDirection::Rtl,
_ => TextDirection::Ltr,
}
}
} |
This is not currently available in ICU4X. Note that the text direction is a property of the script, not the language. Hence your implementation should look more like: impl HasTextDirection for locale::Locale {
fn text_direction(&self) -> TextDirection {
let maximized = self.clone();
LocaleExpander::try_new_unstable(...).unwrap().maximize(&mut maximized);
self.id.script.unwrap().text_direction()
}
}
impl HasTextDirection for locale::subtags::Script {
fn text_direction(&self) -> TextDirection {
match self.as_str() {
"Adlm" | "Arab" | "Armi" | "Avst" | "Chrs" | "Cprt" | "Elym" | "Hatr" | "Hebr" | "Hung" | "Khar" | "Lydi" | "Mand" | "Mani" | "Mend" | "Merc" | "Mero" | "Narb" | "Nbat" | "Nkoo" | "Orkh" | "Ougr" | "Palm" | "Phli" | "Phlp" | "Phnx" | "Prti" | "Rohg" | "Samr" | "Sarb" | "Sogd" | "Sogo" | "Syrc" | "Thaa" | "Yezi"
=> TextDirection::Rtl,
_ => TextDirection::Ltr,
}
}
} The list of scripts is looked up in https://github.com/unicode-org/cldr-json/blob/main/cldr-json/cldr-core/scriptMetadata.json |
In It looks through all locales and finds languages that consistently have the same script and marks them for RTL, and then Scripts that are always RTL. |
The way to do this properly:
|
Thanks @hydroper for raising this issue and everyone in this thread for the pointers. I changed the title of this issue to focus on the feature we don't currently have (map from script to text direction). |
Discuss with: |
Need to discuss location:
|
^ I think because it's tightly coupled with likely subtags, |
Previous discussion on the crate naming: #2214 (comment) "transform" doesn't describe this functionality, but it fits in with the "locale with data" nature of the crate. Names like In addition to directionality, here are some other locale-centric data operations that will need a home:
I lean toward putting this in its own new experimental crate. Even if we put it in icu_locid_transform, we should let it incubate behind an experimental Cargo feature for a while. |
Given that we currently need private methods of |
Conclusion:
|
I searched for "dir", "direction", "ltr" and "rtl" in the
icu
crate docs and found nothing. I'm looking for something like EcmaScript'sIntl.Locale.prototype.textInfo.direction
. Is it available anywhere?The text was updated successfully, but these errors were encountered: