i18n(he): add complete Hebrew UI catalog, RTL chrome polish, and web font guard

This commit is contained in:
HagaiBA committed 2026-11-19 07:54:13 +02:00
1 parent b45255bb6f
commit 2eabc8ea8a
6 files changed
+2865 -32

No files matched your search

File diff suppressed because it is too large. Load diff
+14
View File
@@ -131,6 +131,11 @@ fn shows(code: &str, web: bool) -> bool {
// Arabic; keep the catalog out until an embedded Arabic fallback is supplied.
return figcraft_text::face_with_char('ع', &["Noto Sans Arabic"]).is_some();
}
if code.split(['-', '_']).next().is_some_and(|b| b.eq_ignore_ascii_case("he") || b.eq_ignore_ascii_case("iw")) {
// Desktop draws Hebrew with a system face (or bundled craft-fonts); the web leaves it out
// unless Noto Sans Hebrew is embedded (FIGCRAFT_EMBED_SCRIPTS=Hebr).
return figcraft_text::face_with_char('א', &["Noto Sans Hebrew"]).is_some();
}
if code.split('-').next() == Some("ta") {
// Desktop draws Tamil with a system face (#2018); the web has none until craft-fonts
// carries Noto Sans Tamil.
@@ -233,6 +238,15 @@ mod tests {
assert_eq!(shows("ar-SA", true), face);
}
#[test]
fn the_web_offers_hebrew_only_with_its_face() {
assert!(shows("he", false), "desktop always lists Hebrew");
let face = figcraft_text::face_with_char('א', &["Noto Sans Hebrew"]).is_some();
assert_eq!(shows("he", true), face);
assert_eq!(shows("he-IL", true), face);
assert_eq!(shows("iw-IL", true), face);
}
#[test]
fn the_web_offers_tamil_only_with_its_face() {
assert!(shows("ta", false), "desktop always lists Tamil");
+52 -24
View File
@@ -102,9 +102,6 @@ pub(crate) fn file_row(ui: &Ui, t: &Tokens, r: Rect, resp: &Response, row: &File
if resp.hovered() {
ui.painter().rect_filled(r, CornerRadius::same(5), t.hover);
}
if let Some((icon, tint)) = row.mark {
icons::paint(ui.painter(), Rect::from_min_size(pos2(r.min.x + 8.0, r.center().y - 8.0), vec2(16.0, 16.0)), icon, tint);
}
let (name_font, detail_font) = (regular(12.0), regular(row.detail_size));
let width = |s: &str, font: &egui::FontId| ui.painter().layout_no_wrap(s.to_string(), font.clone(), Color32::WHITE).size().x;
let room = (r.width() - 40.0).max(0.0);
@@ -120,8 +117,19 @@ pub(crate) fn file_row(ui: &Ui, t: &Tokens, r: Rect, resp: &Response, row: &File
widgets::elide_start_font(ui, row.detail, detail_room, detail_font.clone())
};
let cut = name != row.name || detail != row.detail;
ui.painter().text(pos2(r.min.x + 32.0, r.center().y), Align2::LEFT_CENTER, name, name_font, row.ink);
ui.painter().text(pos2(r.max.x - 8.0, r.center().y), Align2::RIGHT_CENTER, detail, detail_font, row.detail_ink);
if crate::i18n::right_to_left() {
if let Some((icon, tint)) = row.mark {
icons::paint(ui.painter(), Rect::from_min_size(pos2(r.max.x - 24.0, r.center().y - 8.0), vec2(16.0, 16.0)), icon, tint);
}
ui.painter().text(pos2(r.max.x - 32.0, r.center().y), Align2::RIGHT_CENTER, name, name_font, row.ink);
ui.painter().text(pos2(r.min.x + 8.0, r.center().y), Align2::LEFT_CENTER, detail, detail_font, row.detail_ink);
} else {
if let Some((icon, tint)) = row.mark {
icons::paint(ui.painter(), Rect::from_min_size(pos2(r.min.x + 8.0, r.center().y - 8.0), vec2(16.0, 16.0)), icon, tint);
}
ui.painter().text(pos2(r.min.x + 32.0, r.center().y), Align2::LEFT_CENTER, name, name_font, row.ink);
ui.painter().text(pos2(r.max.x - 8.0, r.center().y), Align2::RIGHT_CENTER, detail, detail_font, row.detail_ink);
}
cut
}
@@ -144,30 +152,39 @@ pub fn show(app: &mut FigApp, ui: &mut Ui) {
dropped(app, ui.ctx());
egui::CentralPanel::default().frame(egui::Frame::NONE.fill(t.panel)).show(ui, |ui| {
let rect = ui.max_rect();
let left = Rect::from_min_size(rect.min, vec2(SIDEBAR, rect.height()));
ui.painter().line_segment([left.right_top(), left.right_bottom()], Stroke::new(1.0, t.border));
sidebar(app, ui, &t, left);
let rtl = crate::i18n::right_to_left();
let side = if rtl {
Rect::from_min_size(pos2(rect.max.x - SIDEBAR, rect.min.y), vec2(SIDEBAR, rect.height()))
} else {
Rect::from_min_size(rect.min, vec2(SIDEBAR, rect.height()))
};
let border_x = if rtl { side.left() } else { side.right() };
ui.painter().line_segment([pos2(border_x, side.top()), pos2(border_x, side.bottom())], Stroke::new(1.0, t.border));
sidebar(app, ui, &t, side);
let main = if rtl { Rect::from_min_max(rect.min, pos2(side.min.x, rect.max.y)) } else { Rect::from_min_max(pos2(side.max.x, rect.min.y), rect.max) };
if app.ui.home_view.file_query.trim().is_empty() && app.ui.home_view.section == Section::Online {
// Your online files lay themselves out in the area (and scroll their own list).
let area = Rect::from_min_max(pos2(left.max.x + 40.0, rect.min.y + 24.0), rect.max - vec2(40.0, 24.0));
let area = main.shrink2(vec2(40.0, 24.0));
crate::online::section(app, ui, area, &t);
opened_join(app);
return;
}
let main = Rect::from_min_max(pos2(left.max.x, rect.min.y), rect.max);
ui.scope_builder(egui::UiBuilder::new().max_rect(main), |ui| {
egui::ScrollArea::vertical().id_salt("home").auto_shrink([false, false]).show(ui, |ui| {
egui::Frame::NONE.inner_margin(egui::Margin::symmetric(40, 24)).show(ui, |ui| {
ui.spacing_mut().item_spacing = vec2(GAP, 0.0);
if app.ui.home_view.file_query.trim().is_empty() {
match app.ui.home_view.section {
Section::Templates => templates(app, ui, &t),
_ => recents(app, ui, &t),
let align = if rtl { egui::Align::Max } else { egui::Align::Min };
ui.with_layout(egui::Layout::top_down(align), |ui| {
ui.spacing_mut().item_spacing = vec2(GAP, 0.0);
if app.ui.home_view.file_query.trim().is_empty() {
match app.ui.home_view.section {
Section::Templates => templates(app, ui, &t),
_ => recents(app, ui, &t),
}
} else {
search_results(app, ui, &t);
opened_join(app);
}
} else {
search_results(app, ui, &t);
opened_join(app);
}
});
});
});
});
@@ -221,8 +238,13 @@ fn sidebar(app: &mut FigApp, ui: &mut Ui, t: &Tokens, left: Rect) {
ui.painter().rect_filled(r, CornerRadius::same(5), if current { t.selected_row } else { t.hover });
}
focus_ring(ui, t, r, &resp, 5);
icons::paint(ui.painter(), Rect::from_min_size(pos2(r.min.x + 10.0, r.center().y - 8.0), vec2(16.0, 16.0)), icon, t.icon);
ui.painter().text(pos2(r.min.x + 36.0, r.center().y), Align2::LEFT_CENTER, tr(label), regular(12.0), t.text);
if crate::i18n::right_to_left() {
icons::paint(ui.painter(), Rect::from_min_size(pos2(r.max.x - 26.0, r.center().y - 8.0), vec2(16.0, 16.0)), icon, t.icon);
ui.painter().text(pos2(r.max.x - 36.0, r.center().y), Align2::RIGHT_CENTER, tr(label), regular(12.0), t.text);
} else {
icons::paint(ui.painter(), Rect::from_min_size(pos2(r.min.x + 10.0, r.center().y - 8.0), vec2(16.0, 16.0)), icon, t.icon);
ui.painter().text(pos2(r.min.x + 36.0, r.center().y), Align2::LEFT_CENTER, tr(label), regular(12.0), t.text);
}
if resp.clicked() {
app.ui.home_view.section = section;
app.ui.home_view.file_query.clear();
@@ -241,10 +263,16 @@ fn sidebar(app: &mut FigApp, ui: &mut Ui, t: &Tokens, left: Rect) {
ui.painter().rect_filled(r, CornerRadius::same(5), if current { t.selected_row } else { t.hover });
}
focus_ring(ui, t, r, &resp, 5);
icons::paint(ui.painter(), Rect::from_min_size(pos2(r.min.x + 10.0, r.center().y - 8.0), vec2(16.0, 16.0)), Icon::Adjust, t.icon);
ui.painter().text(pos2(r.min.x + 36.0, r.center().y), Align2::LEFT_CENTER, tr("Preferences"), regular(12.0), t.text);
let key_label = figcraft_engine::keymap::display("Cmd+,", crate::shortcuts::platform());
ui.painter().text(pos2(r.max.x - 8.0, r.center().y), Align2::RIGHT_CENTER, &key_label, regular(11.0), t.text_secondary);
if crate::i18n::right_to_left() {
icons::paint(ui.painter(), Rect::from_min_size(pos2(r.max.x - 26.0, r.center().y - 8.0), vec2(16.0, 16.0)), Icon::Adjust, t.icon);
ui.painter().text(pos2(r.max.x - 36.0, r.center().y), Align2::RIGHT_CENTER, tr("Preferences"), regular(12.0), t.text);
ui.painter().text(pos2(r.min.x + 8.0, r.center().y), Align2::LEFT_CENTER, &key_label, regular(11.0), t.text_secondary);
} else {
icons::paint(ui.painter(), Rect::from_min_size(pos2(r.min.x + 10.0, r.center().y - 8.0), vec2(16.0, 16.0)), Icon::Adjust, t.icon);
ui.painter().text(pos2(r.min.x + 36.0, r.center().y), Align2::LEFT_CENTER, tr("Preferences"), regular(12.0), t.text);
ui.painter().text(pos2(r.max.x - 8.0, r.center().y), Align2::RIGHT_CENTER, &key_label, regular(11.0), t.text_secondary);
}
resp = resp.on_hover_text(format!("{} ({})", tr("Preferences"), key_label));
if resp.clicked() {
app.ui.preferences = !app.ui.preferences;
+3 -1
View File
@@ -95,7 +95,9 @@ const LATIN_AMERICA: &[&str] =
/// language the UI can't draw (CJK on the web without CJK faces built in) doesn't count.
fn resolve_one(want: &str) -> Option<usize> {
let tag = want.trim().split(['.', '@']).next().unwrap_or("").replace('_', "-");
let base = tag.split('-').next().unwrap_or("");
let raw_base = tag.split('-').next().unwrap_or("");
// Map the obsolete ISO 639-1 tag `iw` (still emitted by older Java/Android locales) to `he`.
let base = if raw_base.eq_ignore_ascii_case("iw") { "he" } else { raw_base };
let has = |subtags: &[&str]| tag.split('-').skip(1).any(|t| subtags.iter().any(|s| s.eq_ignore_ascii_case(t)));
let zh = |code: &str| {
LANGS.iter().position(|l| l.code.eq_ignore_ascii_case(code)).filter(|i| LANGS.get(*i).is_some_and(|l| crate::cjk::can_show(l.code)))
+41 -1
View File
@@ -584,11 +584,51 @@ fn right_to_left_languages_mirror_the_window() {
for code in ["en", "", "es-419", "zh-Hans", "tr", "ru", "arn", "hey"] {
assert!(!writes_right_to_left(code), "{code}");
}
// Every catalog that mirrors is one of them, and the Arabic one does.
// Every catalog that mirrors is one of them, and the Arabic and Hebrew ones do.
assert!(LANGS.iter().any(|l| l.code == "ar" && writes_right_to_left(l.code)));
assert!(LANGS.iter().any(|l| l.code == "he" && writes_right_to_left(l.code)));
assert!(!writes_right_to_left(LANGS[0].code), "English reads left to right");
}
#[test]
fn hebrew_tags_and_plurals() {
let he = LANGS.iter().position(|l| l.code == "he").expect("locales/he.toml is baked in");
assert_eq!(LANGS[he].name, "עברית");
for tag in ["he", "he-IL", "he_IL.UTF-8", "iw", "iw-IL", "iw_IL.UTF-8"] {
assert_eq!(resolve(tag, None), he, "{tag}");
assert_eq!(resolve("system", Some(tag)), he, "{tag}");
}
assert!(!plural_one(he, 0) && plural_one(he, 1) && !plural_one(he, 2) && !plural_one(he, 5));
let singular = fill(counted(he, "{n} layers", 1), &[("n", &1)]);
let dual = fill(counted(he, "{n} layers", 2), &[("n", &2)]);
assert_eq!(singular, "שכבה 1");
assert_eq!(dual, "2 שכבות");
}
#[test]
fn the_built_in_hebrew_face_draws_the_hebrew_catalog() {
if !figcraft_text::CRAFT_FONTS.iter().any(|f| f.family == "Noto Sans Hebrew" && f.style == "Regular") {
eprintln!("built without craft-fonts' Noto Sans Hebrew; skipping");
return;
}
let Some(face) = figcraft_text::face_with_char('א', &["Noto Sans Hebrew"]) else {
panic!("the supplied Noto Sans Hebrew face must draw Hebrew");
};
let he = &LANGS[LANGS.iter().position(|l| l.code == "he").unwrap()];
let letters: BTreeSet<char> = he
.ui
.iter()
.chain(he.commands)
.chain(he.menu)
.flat_map(|(_, t)| forms(t))
.flat_map(str::chars)
.filter(|c| matches!(u32::from(*c), 0x05D0..=0x05EA))
.collect();
assert!(letters.len() >= 27);
let missing: String = letters.iter().filter(|c| !face.has_char(**c)).collect();
assert!(missing.is_empty(), "Hebrew catalog glyphs missing from the embedded face: {missing:?}");
}
#[test]
fn the_built_in_arabic_face_draws_the_arabic_catalog() {
if !figcraft_text::CRAFT_FONTS.iter().any(|f| f.family == "Noto Sans Arabic" && f.style == "Regular") {
+18 -6
View File
@@ -116,10 +116,19 @@ fn lit_row(
// These menus sit on the theme's popup fill (white in the light theme), not on the dark
// `t.menu` of the menu bar: the theme's text, white only on the green highlight (#972).
let col = if hovered { t.menu_text } else { t.text };
ui.painter().galley(pos2(r.min.x + MENU_PAD + lead, r.center().y - text.size().y / 2.0), text, col);
if let Some(k) = keys {
let at = pos2(r.max.x - MENU_PAD - k.size().x, r.center().y - k.size().y / 2.0);
ui.painter().galley(at, k, if hovered { t.menu_text } else { t.text_secondary });
let rtl = crate::widgets::rtl(ui);
if rtl {
ui.painter().galley(pos2(r.max.x - MENU_PAD - lead - text.size().x, r.center().y - text.size().y / 2.0), text, col);
if let Some(k) = keys {
let at = pos2(r.min.x + MENU_PAD, r.center().y - k.size().y / 2.0);
ui.painter().galley(at, k, if hovered { t.menu_text } else { t.text_secondary });
}
} else {
ui.painter().galley(pos2(r.min.x + MENU_PAD + lead, r.center().y - text.size().y / 2.0), text, col);
if let Some(k) = keys {
let at = pos2(r.max.x - MENU_PAD - k.size().x, r.center().y - k.size().y / 2.0);
ui.painter().galley(at, k, if hovered { t.menu_text } else { t.text_secondary });
}
}
art(ui.painter(), r, col);
resp
@@ -196,13 +205,16 @@ const CHECK_COL: f32 = 14.0;
/// `Some(true)`) is drawn in its own column ahead of the icon, so a checked entry's label does
/// not move against the unchecked ones.
pub fn menu_icon_item(ui: &mut Ui, icon: Option<crate::icons::Icon>, on: Option<bool>, label: &str, shortcut: &str) -> bool {
let rtl = crate::widgets::rtl(ui);
let paint = |p: &egui::Painter, r: Rect, col: Color32| {
if on == Some(true) {
let mark = p.layout_no_wrap("✓".to_owned(), regular(11.5), col);
p.galley(pos2(r.min.x + MENU_PAD, r.center().y - mark.size().y / 2.0), mark, col);
let x = if rtl { r.max.x - MENU_PAD - mark.size().x } else { r.min.x + MENU_PAD };
p.galley(pos2(x, r.center().y - mark.size().y / 2.0), mark, col);
}
if let Some(icon) = icon {
crate::icons::paint(p, Rect::from_min_size(pos2(r.min.x + MENU_PAD + CHECK_COL, r.center().y - 8.0), vec2(16.0, 16.0)), icon, col);
let x = if rtl { r.max.x - MENU_PAD - CHECK_COL - 16.0 } else { r.min.x + MENU_PAD + CHECK_COL };
crate::icons::paint(p, Rect::from_min_size(pos2(x, r.center().y - 8.0), vec2(16.0, 16.0)), icon, col);
}
};
let resp = lit_row(ui, label, shortcut, 0.0, CHECK_COL + 22.0, paint, false);