Review › Language: Serbian in Cyrillic and Latin, each with its own dictionary (#1619)

The Language list offers Serbian (Cyrillic) sr-Cyrl-RS and Serbian (Latin) sr-Latn-RS. A dictionary is used only for text in its own script (LibreOffice's sr and sr-Latn, Hunspell's sr_RS and sr_Latn_RS, Fedora's sr_RS@latin), Serbian dictionaries are tried before the Serbo-Croatian sh alias, and only Latin and Cyrillic subtags or modifiers are read as a dictionary's script.

Co-authored-by: aiongg <67543387+aiongg@users.noreply.github.com>
This commit is contained in:
VladimirCericandaiongg authored and GitHub committed 2026-11-18 16:29:25 +07:00
1 parent 9a8e8227ff
commit e419262c4c
4 files changed
+183 -19

No files matched your search

+138 -15
View File
@@ -538,7 +538,57 @@ fn valid_lang(lang: &str) -> bool {
(1..=16).contains(&lang.len()) && lang.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_')
}
/// The `.aff`/`.dic` pair for `lang` in `dirs`: the exact locale first, then any of its language.
/// The script a language tag or a dictionary's name states, lowercased: a script subtag
/// (`sr-Latn`, `sr_Latn_RS`) or a `@latin`/`@cyrillic` modifier (Fedora's `sr_RS@latin`). Only
/// the scripts a dictionary is chosen by are read (Latin and Cyrillic), so another part of a name
/// (a variant such as `de-1996`, a suffix such as `en_US-wiki`) is never taken for one.
fn named_script(name: &str) -> Option<String> {
name.split(['-', '_', '@']).skip(1).find_map(|p| match p.to_ascii_lowercase().as_str() {
"latn" | "latin" => Some("latn".to_string()),
"cyrl" | "cyrillic" => Some("cyrl".to_string()),
_ => None,
})
}
/// The script of a language written in more than one, when a tag or a dictionary's name doesn't
/// state it: Serbian is Cyrillic (`sr-RS`, and LibreOffice's and Hunspell's `sr` dictionary), its
/// Latin dictionary says so (`sr-Latn`, `sr_Latn_RS`, `sr_RS@latin`).
fn default_script(base: &str) -> Option<&'static str> {
match base {
"sr" => Some("cyrl"),
_ => None,
}
}
/// Another language code a language's dictionaries are filed under, and their script: Serbian
/// Latin dictionaries are often Serbo-Croatian ones (Hunspell's `sh_RS`, `sh_YU`).
fn alias(base: &str) -> Option<(&'static str, &'static str)> {
match base {
"sr" => Some(("sh", "latn")),
_ => None,
}
}
/// The language code a dictionary is named for (`sr_Latn_RS`, `sr-Latn` → `sr`), lowercased.
fn stem_language(stem: &str) -> String {
stem.split(['-', '_', '@']).next().unwrap_or("").to_ascii_lowercase()
}
/// Is the dictionary named `stem` for text in the script of `lang` (language `base`)? A Cyrillic
/// dictionary would flag every word of Latin text, and the other way round. The run's language tag
/// decides, not the letters of the text. When either side's script is unknown, any dictionary of
/// the language fits, as before.
fn same_script(lang: &str, stem: &str, base: &str) -> bool {
let default = || default_script(base).map(str::to_string);
let aliased = alias(base).filter(|(code, _)| stem_language(stem) == *code).map(|(_, script)| script.to_string());
match (named_script(lang).or_else(default), named_script(stem).or(aliased).or_else(default)) {
(Some(want), Some(have)) => want == have,
_ => true,
}
}
/// The `.aff`/`.dic` pair for `lang` in `dirs`: the exact locale first, then any of its language
/// (or the language its dictionaries are also filed under, [`alias`]) in the same script.
pub fn find_in(dirs: &[PathBuf], lang: &str) -> Option<(PathBuf, PathBuf)> {
// A language tag names a file in the dictionary folders and nothing else: no `..`, no separators.
if !valid_lang(lang) {
@@ -550,23 +600,33 @@ pub fn find_in(dirs: &[PathBuf], lang: &str) -> Option<(PathBuf, PathBuf)> {
(a.is_file() && b.is_file()).then_some((a, b))
};
for d in dirs {
if let Some(p) = pair(d, &full) {
if let Some(p) = pair(d, &full).or_else(|| pair(d, lang)) {
return Some(p);
}
}
for d in dirs {
if let Some(p) = pair(d, &base) {
return Some(p);
}
let Ok(rd) = std::fs::read_dir(d) else { continue };
let mut stems: Vec<String> = rd
.filter_map(|e| e.ok()?.file_name().into_string().ok())
.filter_map(|n| n.strip_suffix(".aff").map(str::to_string))
.filter(|n| n.to_lowercase().starts_with(&format!("{base}_")))
.collect();
stems.sort();
if let Some(p) = stems.iter().find_map(|s| pair(d, s)) {
return Some(p);
// The language's own dictionaries first, in every folder; then those filed under its alias
// (a Serbian Latin dictionary before a Serbo-Croatian one).
let codes = std::iter::once(base.as_str()).chain(alias(&base).map(|(code, _)| code));
for code in codes {
for d in dirs {
if same_script(lang, code, &base)
&& let Some(p) = pair(d, code)
{
return Some(p);
}
let Ok(rd) = std::fs::read_dir(d) else { continue };
// `sr_Latn_RS`, LibreOffice's `sr-Latn` and Fedora's `sr_RS@latin` all name a Serbian
// dictionary.
let mut stems: Vec<String> = rd
.filter_map(|e| e.ok()?.file_name().into_string().ok())
.filter_map(|n| n.strip_suffix(".aff").map(str::to_string))
.filter(|n| stem_language(n) == code && !n.eq_ignore_ascii_case(code))
.filter(|n| same_script(lang, n, &base))
.collect();
stems.sort();
if let Some(p) = stems.iter().find_map(|s| pair(d, s)) {
return Some(p);
}
}
}
None
@@ -1078,4 +1138,67 @@ SFX D Y 1\nSFX D 0 ed/S .\n";
assert_eq!(stem("fr-FR"), None);
let _ = std::fs::remove_dir_all(&dir);
}
/// Serbian is written in two scripts, and each finds its own dictionary: LibreOffice names
/// the Cyrillic one `sr` and the Latin one `sr-Latn`, Hunspell packages `sr_RS` and
/// `sr_Latn_RS`, Fedora `sr_RS` and `sr_RS@latin`, and Latin ones may be Serbo-Croatian
/// (`sh_RS`, `sh_YU`). A dictionary of the other script is never used: it would flag every word.
#[test]
fn serbian_finds_the_dictionary_of_its_script() {
let dir = std::env::temp_dir().join(format!("deckcraft-dict-sr-{}", std::process::id()));
let stem = |names: &[&str], l: &str| {
let _ = std::fs::remove_dir_all(&dir);
let _ = std::fs::create_dir_all(&dir);
for n in names {
let _ = std::fs::write(dir.join(format!("{n}.aff")), "");
let _ = std::fs::write(dir.join(format!("{n}.dic")), "");
}
find_in(std::slice::from_ref(&dir), l).and_then(|(a, _)| a.file_stem().map(|s| s.to_string_lossy().into_owned()))
};
let libreoffice = ["sr", "sr-Latn"];
assert_eq!(stem(&libreoffice, "sr-Cyrl-RS").as_deref(), Some("sr"));
assert_eq!(stem(&libreoffice, "sr-RS").as_deref(), Some("sr"));
assert_eq!(stem(&libreoffice, "sr-Latn-RS").as_deref(), Some("sr-Latn"));
let hunspell = ["sr_Latn_RS", "sr_RS"];
assert_eq!(stem(&hunspell, "sr-Cyrl-RS").as_deref(), Some("sr_RS"));
assert_eq!(stem(&hunspell, "sr-Latn-RS").as_deref(), Some("sr_Latn_RS"));
let fedora = ["sr_RS", "sr_RS@latin"];
assert_eq!(stem(&fedora, "sr-Cyrl-RS").as_deref(), Some("sr_RS"));
assert_eq!(stem(&fedora, "sr-Latn-RS").as_deref(), Some("sr_RS@latin"));
assert_eq!(stem(&["sr_RS@latin"], "sr-Cyrl-RS"), None);
// Serbo-Croatian dictionaries are Latin: they serve Serbian Latin, never Cyrillic.
assert_eq!(stem(&["sh_RS"], "sr-Latn-RS").as_deref(), Some("sh_RS"));
assert_eq!(stem(&["sh_YU"], "sr-Latn-RS").as_deref(), Some("sh_YU"));
assert_eq!(stem(&["sh"], "sr-Latn-RS").as_deref(), Some("sh"));
assert_eq!(stem(&["sh_RS"], "sr-Cyrl-RS"), None);
assert_eq!(stem(&["sh_RS", "sr"], "sr-RS").as_deref(), Some("sr"));
// A Serbian Latin dictionary comes before a Serbo-Croatian one.
assert_eq!(stem(&["sh_RS", "sr-Latn"], "sr-Latn-RS").as_deref(), Some("sr-Latn"));
assert_eq!(stem(&["sh", "sr_RS@latin"], "sr-Latn-RS").as_deref(), Some("sr_RS@latin"));
// Only the other script installed: no dictionary, so no marks, rather than every word.
assert_eq!(stem(&["sr"], "sr-Latn-RS"), None);
assert_eq!(stem(&["sr-Latn"], "sr-Cyrl-RS"), None);
// Languages in one script are unchanged.
assert_eq!(stem(&["de_DE"], "de-AT").as_deref(), Some("de_DE"));
let _ = std::fs::remove_dir_all(&dir);
}
/// The script is read from a script subtag or a `@latin`/`@cyrillic` modifier, in tags and
/// dictionary names alike; a variant, a region or another suffix is not a script.
#[test]
fn a_script_is_read_only_from_a_script_subtag() {
let script = |n| named_script(n);
assert_eq!(script("sr-Cyrl").as_deref(), Some("cyrl"));
assert_eq!(script("sr-Cyrl-RS").as_deref(), Some("cyrl"));
assert_eq!(script("sr-Latn").as_deref(), Some("latn"));
assert_eq!(script("sr_Latn_RS").as_deref(), Some("latn"));
assert_eq!(script("sr_RS@latin").as_deref(), Some("latn"));
assert_eq!(script("sr_RS@cyrillic").as_deref(), Some("cyrl"));
for none in ["sr", "sr-RS", "sr_RS", "de-1996", "de_DE", "en_US-wiki", "en-GB-oxendict", "zh-Hans"] {
assert_eq!(script(none), None, "{none}");
}
// Plain Serbian, with no script, is Cyrillic.
assert!(same_script("sr", "sr", "sr") && same_script("sr-RS", "sr_Cyrl_RS", "sr"));
assert!(!same_script("sr", "sr-Latn", "sr"));
}
}
+31
View File
@@ -1992,3 +1992,34 @@ fn signed_insets_are_preserved_when_they_fit() {
assert_eq!(l.lines.len(), 1);
assert_eq!(l.inner.x0, -10.0);
}
/// Each run is shaped in its own language (Review › Language), so a font's forms for that language
/// (OpenType `locl`) are drawn: the Serbian б, not the Russian one, in a Serbian run beside a
/// Russian run of the same word.
#[test]
fn serbian_runs_draw_the_fonts_serbian_forms() {
let b = |f: &FontFace, lang: &str| {
let params = deckcraft_fonts::ShapeParams { language: Some(lang), ..Default::default() };
deckcraft_fonts::shape_range(f, "б", 0.."б".len(), &params, |c| c).first().map(|g| g.gid)
};
let serbian_form = |f: &FontFace| b(f, "sr-Cyrl-RS") != b(f, "ru-RU");
let Some(family) = first_family(&["DejaVu Sans", "DejaVu Serif", "Source Sans 3", "Source Serif 4", "Noto Sans", "Noto Serif"], serbian_form)
else {
eprintln!("skipped: no font with a Serbian б");
return;
};
let run = |text: &str, lang: &str| {
let mut r = Run::new(text);
r.props.lang = Some(lang.into());
r.props.font = Some(family.clone());
r
};
let (p, sh) = bidi_setup(vec![run("грб ", "sr-Cyrl-RS"), run("грб", "ru-RU")], 2000.0, false, Align::Left);
let l = lay(&p, &sh, 2000.0, 300.0);
// Glyph of each paragraph character.
let at = |i: usize| l.runs.iter().find_map(|r| r.cells.iter().position(|&(k, _)| k == i).and_then(|g| r.glyphs.get(g)).map(|g| g.0));
// г р б, space, г р б: each б is the one its language gives.
let face = FontDb::global().face(&family, "Regular");
assert_eq!(at(2), b(&face, "sr-Cyrl-RS"), "{family}: the Serbian б");
assert_eq!(at(6), b(&face, "ru-RU"), "{family}: the Russian б");
}
+2
View File
@@ -230,6 +230,8 @@ pub const LANGS: &[(&str, &str)] = &[
("Українська", "uk-UA"),
("Русский", "ru-RU"),
("Беларуская", "be-BY"),
("Српски (ћирилица)", "sr-Cyrl-RS"),
("Srpski (latinica)", "sr-Latn-RS"),
("Türkçe", "tr-TR"),
("Ελληνικά", "el-GR"),
("日本語", "ja-JP"),
+12 -4
View File
@@ -1,6 +1,6 @@
# Localization parity with PowerPoint
> **Last reviewed:** 2026-10-14 · **Last updated:** 2026-10-24 · **Change:** minor (opt-in native LXGW WenKai Lite fallback and interface CJK tests; local implementation only, managed validation pending; previous: minor, IME composition underlined in table cells; previous: minor, IME composition and CJK interface text, #101; previous: major, created) · **Target:** Microsoft PowerPoint for Mac 16.113 (Microsoft 365)
> **Last reviewed:** 2026-10-14 · **Last updated:** 2026-10-31 · **Change:** minor (Review › Language offers Serbian in Cyrillic and Latin, each with its own dictionary; previous: minor, opt-in native LXGW WenKai Lite fallback and interface CJK tests; local implementation only, managed validation pending; previous: minor, IME composition underlined in table cells; previous: minor, IME composition and CJK interface text, #101; previous: major, created) · **Target:** Microsoft PowerPoint for Mac 16.113 (Microsoft 365)
DeckCraft's interface is English only today: strings are literals in the UI and engine code, with
no catalog and no language switch. Requests: #15 (follow the system language), #30 and PR #34
@@ -51,15 +51,23 @@ the next re-measure.
## Proofing languages
PowerPoint checks spelling in dozens of languages and lets each run carry a proofing language.
DeckCraft keeps `a:rPr/@lang` on round trip but its spelling check is a small English list of
common misspellings (`crates/engine/src/cmd/review.rs`); see [gaps.md](gaps.md#proofing-spelling-thesaurus-autocorrect).
DeckCraft keeps `a:rPr/@lang` on round trip and checks each run in its own language against the
Hunspell dictionaries installed on the system (`crates/engine/src/spell.rs`), falling back to a
built-in list of common English misspellings when there is none (`review.spelling`); see
[gaps.md](gaps.md#proofing-spelling-thesaurus-autocorrect).
Review › Language sets the proofing language of the selected text or, with *Whole presentation*,
of every text in the file and the default for new text (`format.languageAll`).
of every text in the file and the default for new text (`format.languageAll`). Each run is shaped
in its language, so fonts draw their forms for it (OpenType `locl`: the Serbian б, г, д, п, т).
Serbian is offered in both scripts (`sr-Cyrl-RS`, `sr-Latn-RS`). The run's language tag picks the
dictionary, and only one in the script the tag names: LibreOffice's `sr` and `sr-Latn`, Hunspell's
`sr_RS` and `sr_Latn_RS`, Fedora's `sr_RS@latin`, and the Serbo-Croatian `sh_RS`/`sh_YU` for Latin.
A dictionary of the other script would flag every word, so it is never used.
## Revision history
| Date | Change | Summary |
|---|---|---|
| 2026-10-31 | minor | Review › Language offers Serbian (Cyrillic and Latin); each run's language tag picks a dictionary in the script it names |
| 2026-10-24 | minor | Local 0.37 candidate adds an opt-in native LXGW WenKai Lite glyph fallback and CJK interface-test coverage. This records local implementation only: managed tests, formatting, clippy, wasm-size and native GUI qualification remain pending. Browser font budget and uniform Chinese typography are unchanged. |
| 2026-10-21 | minor | Review › Language can set the proofing language of the whole presentation |
| 2026-10-14 | minor | IME composition in a table cell is underlined in place; the candidate window sits on that cell's caret |