Locale: numeric and unit fields read Devanagari, Gujarati and other Unicode digits

`vectorcraft_doc::units` writes every Unicode decimal digit as ASCII before
its unit and arithmetic parser, on craft-i18n's digit data (storytold/craft-libs#198
track 5). One number mixing digit sets is refused, as craft-i18n's
parse_number refuses it. ASCII input and display are unchanged.
This commit is contained in:
ruchirguitar committed 2026-12-02 22:45:34 +05:30
1 parent 2498ef4682
commit 613bab46c5
7 files changed
+120 -9

No files matched your search

Generated
+1
View File
@@ -8660,6 +8660,7 @@ name = "vectorcraft-doc"
version = "0.25.1"
dependencies = [
"chrono",
"craft-i18n",
"craft-image-codecs",
"craft-stream-codecs",
"flate2",
+2
View File
@@ -29,6 +29,8 @@ craft-cdr = { git = "https://github.com/storytold/craft-libs", rev = "77ade517ec
# SVG parsing, limits, SVGZ and writer (craft-libs#778).
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "77ade517ecb2a6ad86feb2f9983a098ad5738fc6", features = ["tree"] }
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "77ade517ecb2a6ad86feb2f9983a098ad5738fc6" }
# Digits typed in any script in numeric fields (`vectorcraft_doc::units`).
craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "77ade517ecb2a6ad86feb2f9983a098ad5738fc6" }
# EPS container, previews, ASCII85 and DSC comments (craft-libs#778).
craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "77ade517ecb2a6ad86feb2f9983a098ad5738fc6" }
# DXF tags, reader and writer (craft-libs#778, #926, #927).
+2
View File
@@ -32,6 +32,8 @@ serde_json = { workspace = true }
sha2 = { version = "0.10", default-features = false }
thiserror = { workspace = true }
chrono = { workspace = true }
# Field text in Devanagari, Gujarati and other Unicode digits (`units`).
craft-i18n = { workspace = true }
[dev-dependencies]
flate2 = { workspace = true }
+40
View File
@@ -303,3 +303,43 @@ fn format_area_formats_and_trims_cleanly() {
assert_eq!(Unit::Points.format_area(f64::NAN), "0 pt²");
assert_eq!(Unit::Points.format_area(f64::INFINITY), "0 pt²");
}
/// Typed in Devanagari or Gujarati digits, a field value reads as its ASCII spelling does:
/// plain numbers, units, picas, arithmetic, percentages and a decimal comma.
#[test]
fn hindi_and_gujarati_digits_read_as_ascii_digits_do() {
let ascii = ["12", "12.5 mm", "-3in", "2p6", "45*2", "10x2 mm", "100pt+25%", "1080/2 px", "13q"];
let hindi = ["१२", "१२.५ mm", "-३in", "२p६", "४५*२", "१०x२ mm", "१००pt+२५%", "१०८०/२ px", "१३q"];
let gujarati = ["૧૨", "૧૨.૫ mm", "-૩in", "૨p૬", "૪૫*૨", "૧૦x૨ mm", "૧૦૦pt+૨૫%", "૧૦૮૦/૨ px", "૧૩q"];
for ((a, h), g) in ascii.iter().zip(hindi).zip(gujarati) {
let want = Unit::Millimeters.parse(a);
assert!(want.is_some(), "`{a}` should read");
assert_eq!(Unit::Millimeters.parse(h), want, "`{h}` vs `{a}`");
assert_eq!(Unit::Millimeters.parse(g), want, "`{g}` vs `{a}`");
}
assert_eq!(crate::parse_number("४५*२"), crate::parse_number("45*2"));
assert_eq!(crate::parse_number("૪૫x૨"), crate::parse_number("45x2"));
assert_eq!(Unit::Millimeters.parse_with_decimal_comma("०,५ mm"), Unit::Millimeters.parse("0.5 mm"));
assert_eq!(Unit::Millimeters.parse_with_decimal_comma("૦,૫"), Unit::Millimeters.parse("0.5"));
}
/// A grouped thousand is refused in any digits, as `1,000` is, rather than read as 1.
#[test]
fn a_native_digit_thousand_is_refused_like_an_ascii_one() {
assert_eq!(Unit::Millimeters.parse_with_decimal_comma("1,000 mm"), None);
assert_eq!(Unit::Millimeters.parse_with_decimal_comma("१,००० mm"), None);
assert_eq!(Unit::Millimeters.parse_with_decimal_comma("૧,૦૦૦"), None);
assert_eq!(crate::decimal_point("१,०००"), crate::decimal_point("1,000"));
}
/// One number mixing digit sets is refused, as craft-i18n's `parse_number` refuses it; separate
/// numbers of a sum may each use their own.
#[test]
fn a_number_mixing_digit_sets_reads_as_nothing() {
for text in ["1२", "૧२", "१.5", "૧२.૫ mm", "1,२"] {
assert_eq!(Unit::Points.parse(text), None, "`{text}`");
assert_eq!(Unit::Points.parse_with_decimal_comma(text), None, "`{text}`");
assert_eq!(crate::parse_number(text), None, "`{text}`");
}
assert_eq!(Unit::Points.parse("१२+3"), Unit::Points.parse("12+3"));
}
+64 -8
View File
@@ -1,3 +1,6 @@
use std::borrow::Cow;
use std::sync::OnceLock;
use super::{Deserialize, Serialize};
/// Measurement units (display only; the model is always in points).
@@ -203,20 +206,24 @@ impl Unit {
///
/// Text with more than 128 `+ - * /` signs ([`arithmetic_signs`], a multiplication sign counted
/// as `*`) reads as nothing.
///
/// Digits may be in any script ([`ascii_digits`]): `१२ mm` is `12 mm`, `૪૫*૨` is `45*2`.
pub fn parse(self, s: &str) -> Option<f64> {
if arithmetic_signs(s) > MAX_MEASURE_OPERATORS {
return None;
}
parse_measure(&times_as_asterisks(s), self).filter(|v| v.is_finite())
let s = ascii_digits(s)?;
parse_measure(&times_as_asterisks(&s), self).filter(|v| v.is_finite())
}
/// Parse a measurement with decimal points or commas and no input locale. Refuse a
/// number that looks like a grouped integer, even when it is part of an expression.
pub fn parse_with_decimal_comma(self, text: &str) -> Option<f64> {
if text.contains(',') && times_as_asterisks(text).split(['+', '-', '*', '/']).any(thousands_operand) {
let text = ascii_digits(text)?;
if text.contains(',') && times_as_asterisks(&text).split(['+', '-', '*', '/']).any(thousands_operand) {
return None;
}
self.parse(&decimal_point(text))
self.parse(&decimal_point(&text))
}
/// The value naming this unit in the Units preferences (`points`, `millimeters`,
/// `feetInches`).
@@ -414,9 +421,57 @@ fn percent(s: &str) -> Option<f64> {
/// (#3837), and each number of a sum reads its own separator, so `100.5 mm-0,5` (a comma typed
/// after the value the field shows) is 100 mm (#5684). A number written with both separators has
/// two points once read, so `1,000.5` and `1.234,5` are refused rather than guessed at; so is a
/// number that reads as thousands ([`thousands`]).
pub fn decimal_point(text: &str) -> std::borrow::Cow<'_, str> {
if text.contains(',') && !thousands(text) { text.replace(',', ".").into() } else { text.into() }
/// number that reads as thousands ([`thousands`]). Digits in other scripts come back as ASCII
/// ([`ascii_digits`]), so `१,०००` is refused as `1,000` is; text mixing digit sets in one number
/// comes back as it is, for the parser to refuse.
pub fn decimal_point(text: &str) -> Cow<'_, str> {
let Some(text) = ascii_digits(text) else { return text.into() };
if text.contains(',') && !thousands(&text) { text.replace(',', ".").into() } else { text }
}
/// `text` with every Unicode decimal digit (Devanagari `०-९`, Gujarati `૦-૯`, Bengali,
/// Arabic-Indic, full-width, …) written as its ASCII digit, so `१२.५ mm` reads as `12.5 mm`. ASCII
/// text is not copied. Each number (a run of digits, `.` and `,`) must use one digit set, as
/// `craft_i18n::parse_number` requires: `1२` and `૧२` are `None`. Operators, unit suffixes and
/// other characters are left as they are.
fn ascii_digits(text: &str) -> Option<Cow<'_, str>> {
if text.is_ascii() {
return Some(text.into());
}
let mut out = String::with_capacity(text.len());
// The zero of the digit set of the number being read.
let mut set = None;
for c in text.chars() {
if let Some((zero, value)) = decimal_digit(c) {
if *set.get_or_insert(zero) != zero {
return None;
}
out.push(char::from(b'0' + value));
} else {
if !matches!(c, '.' | ',') {
set = None;
}
out.push(c);
}
}
Some(out.into())
}
/// `c`'s digit set (the code point of its zero) and value, when it is a Unicode decimal digit.
/// Other than ASCII, read through craft-i18n, which knows every set (general category Nd).
fn decimal_digit(c: char) -> Option<(u32, u8)> {
if c.is_ascii_digit() {
return Some((u32::from('0'), (c as u8) - b'0'));
}
if c.is_ascii() {
return None;
}
// A lone character reads as a number only when it is a digit; the format's marks don't matter.
static FORMAT: OnceLock<craft_i18n::Format> = OnceLock::new();
let format = FORMAT.get_or_init(|| craft_i18n::Format::from_tag("und"));
let read = format.parse(c.encode_utf8(&mut [0; 4])).ok()?;
let value = (0..10u8).find(|&d| f64::from(d) == read)?;
Some((u32::from(c).checked_sub(u32::from(value))?, value))
}
/// Does the operand contain a thousands comma? Check both parts of a compact pica value and
@@ -455,9 +510,10 @@ pub fn finite_in_every_unit(pt: f64) -> bool {
}
/// A unitless field value (percent, degrees, counts) with the same `+ - * /` arithmetic as
/// [`Unit::parse`] (`45*2`, `45x2`, `100/3`); text other than digits, `.` and operators reads as
/// nothing.
/// [`Unit::parse`] (`45*2`, `45x2`, `100/3`, `४५*२`); text other than digits, `.` and operators
/// reads as nothing.
pub fn parse_number(s: &str) -> Option<f64> {
let s = ascii_digits(s)?;
if !s.chars().all(|c| c.is_ascii_digit() || " .+-*/xX×".contains(c)) {
return None;
}
+10 -1
View File
@@ -1,6 +1,6 @@
# Localization parity
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-25 · **Change:** patch (Arabic (`ar`): preparatory registration and 6-form CLDR plural routing; UI not exposed pending upstream `storytold/craft-i18n` catalog; Hindi catalog draft complete under the translation tests; contributor loanword terminology reviewed; wider proofreading welcome; Brazilian Portuguese: 154 rows for the strings the sibling catalogs translate — smart-filter and print presets, dimension lines, swatches, canvas messages; previously minor: Bosnian (`bs`): complete catalog; previously minor: Vietnamese text: stacked diacritics tested and attach in every form, #4491; previously: Catalan (`ca`) catalog added, complete under the tests)
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-12-02 · **Change:** minor (numeric and unit fields in dialogs and commands read Devanagari, Gujarati and other Unicode digits; previously patch: Arabic (`ar`): preparatory registration and 6-form CLDR plural routing; UI not exposed pending upstream `storytold/craft-i18n` catalog; Hindi catalog draft complete under the translation tests; contributor loanword terminology reviewed; wider proofreading welcome; Brazilian Portuguese: 154 rows for the strings the sibling catalogs translate — smart-filter and print presets, dimension lines, swatches, canvas messages; previously minor: Bosnian (`bs`): complete catalog; previously minor: Vietnamese text: stacked diacritics tested and attach in every form, #4491; previously: Catalan (`ca`) catalog added, complete under the tests)
Per-language status of VectorCraft's interface. How the catalogs work and how to add a language:
[`development.md` › Localisation](development.md#localisation). Part of
@@ -92,6 +92,14 @@ other mark style; the untranslated report lists a catalog that lacks one of them
Native review is still needed, and catalog coverage does not prove that every variable in the UI is
translated.
## Number input
Dialog number and unit fields, and command parameters given as text (MCP, the control channel), read digits in any
script (Devanagari `१२ mm`, Gujarati `૪૫*૨`, Bengali, Arabic-Indic, full-width), with the same units, arithmetic and
decimal comma as ASCII digits (`vectorcraft_doc::units`, on craft-i18n's digit data; storytold/craft-libs#198
track 5). One number mixing digit sets (`1२`) is refused. The panels' number fields read through the shared craft
reader, which reads Devanagari but not yet Gujarati or Bengali digits: that is a craft-libs change.
## Not done in any language
Locale-aware number and date formats, a right-to-left interface, translated help, and a Traditional Chinese UI
@@ -101,6 +109,7 @@ font for the web build.
| Date | Change | Summary |
|---|---|---|
| 2026-12-02 | minor | Number input: dialog and command number and unit fields read Devanagari, Gujarati and other Unicode digits; a number mixing digit sets is refused (storytold/craft-libs#198 track 5); panel number fields still need the shared craft reader to learn Gujarati and Bengali digits; scores and estimates unchanged |
| 2026-11-25 | patch | Arabic (`ar`): preparatory registration and 6-form CLDR plural routing; kept unavailable to users pending upstream `storytold/craft-i18n` catalog |
| 2026-11-14 | minor | Gujarati (#6613): contributor proofreading completed for all 387 additions, with 11 wording corrections; 4,673 reviewed catalog rows. Status/error messages remain partial; web selection requires a bundled Gujarati face. Scores and estimates unchanged. |
| 2026-11-12 | minor | Gujarati (`gu`): reviewed by a native speaker; zero/one singular plurals (CLDR); Gujarati craft-fonts faces join the UI fonts; strings added on main since branching translated (4,286 rows) |
+1
View File
@@ -18485,6 +18485,7 @@ Converter and in its panel (`window.panel {panel: "unitConverter"}`). Neither co
`addon.units.convert {value, unit?}` accepts a number, or text with a unit suffix and
`+ - * /` arithmetic, where `x`, `X` and `×` multiply as `*` does (`"10mm"`, `"1in/2"`, `"2p6"`, `"1080/2 px"`,
`"3cm*50%"`, `"2x3 mm"`, `"13q"`). The command reads an unambiguous decimal comma as a point (`"0,5 mm"`).
Digits may be in any script, one set per number (`"१२ mm"`, `"૪૫*૨"`); `"1२"` is refused.
It refuses numbers that look like grouped integers, whether alone (`"1,000 mm"`) or in arithmetic (`"1,500+2"`).
Text may contain at most 1024 bytes and 128 `+ - * /` signs (each multiplication sign counts).
A number without a suffix is in `unit` (a unit's name, suffix or key: `points`, `picas`, `inches`, `millimeters`,