Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 60 additions & 51 deletions src/accessibility.typ
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@
V: "volt",
W: "watt",
Wb: "weber",
"%": "percent",
"‰": "permille",
),
de: (
// identical/similar units are inherited from English
Expand Down Expand Up @@ -270,6 +272,8 @@
V: "Volt",
W: "Watt",
Wb: "Weber",
"%": "Prozent",
"‰": "Promille",
),
fr: (
A: "ampère",
Expand All @@ -290,6 +294,8 @@
l: "litre",
Np: "néper",
sr: "stéradian",
"%": "pour cent",
"‰": "pour mille",
),
es: (
A: "amperio",
Expand Down Expand Up @@ -320,6 +326,8 @@
au: "unidad astronómica",
sym.prime.double: "segundo de arco",
sym.prime: "minuto de arco",
"%": "por ciento",
"‰": "por mil",
),
it: (
m: "metro",
Expand All @@ -337,6 +345,8 @@
au: "unità astronomica",
sym.prime.double: "secondo d'arco",
sym.prime: "minuto d'arco",
"%": "per cento",
"‰": "per mille",
),
fi: (
A: "ampeeria",
Expand Down Expand Up @@ -384,6 +394,8 @@
V: "volttia",
W: "wattia",
Wb: "weberiä",
"%": "prosentti",
"‰": "promille",
),
sl: (
/* inherits bel, dalton,
Expand Down Expand Up @@ -421,12 +433,14 @@
t: "tona",
W: "vat",
Wb: "veber",
"%": "odstotek",
"‰": "odtisoček",
),
)

// Register of the shorthands for special powers that a language has. This
// can be a string that is appended to the constituent unit (with a space)
// or a function that takes the translated constituent unit.
// can be a string that is appended to the constituent unit (with a space)
// or a function that takes the translated constituent unit.
#let power-shorthands = (
en: (
"2": "squared",
Expand Down Expand Up @@ -461,11 +475,11 @@
// How to form the plural of a constituent unit. For each language, this should
// be a function that takes a unit symbol string, e.g. "Hz",
// and a float `count` which is assumed to be of some plural amount,
// and a bool `is-in-denom` that specifies whether the unit is placed in the denominator.
// and a bool `is-in-denom` that specifies whether the unit is placed in the denominator.
#let pluralize = (
en: (unit, count, is-in-denom) => {
let singular = units.en.at(unit)
if unit in ("lx", "Hz", "S") {
if unit in ("lx", "Hz", "S", "%", "‰") {
return singular
}
if unit == sym.degree + "C" {
Expand All @@ -476,10 +490,10 @@
}
return singular + "s"
},

de: (unit, count, is-in-denom) => {
let singular = units.de.at(unit)
if unit in ("h", "min", "s", sym.prime.double, sym.prime, "t") {
if unit in ("h", "min", "s", sym.prime.double, sym.prime, "t", "%", "‰") {
return singular + "n"
}
if unit == "au" {
Expand All @@ -494,7 +508,7 @@

fr: (unit, count, is-in-denom) => {
let singular = units.fr.at(unit, default: units.en.at(unit))
if unit in ("lx", "Hz", "S") {
if unit in ("lx", "Hz", "S", "%", "‰") {
return singular
}
if unit == sym.degree + "C" { return "degrés Celsius" }
Expand All @@ -503,10 +517,10 @@
if unit == "au" { return "unités astronomique" }
return singular + "s"
},

es: (unit, count, is-in-denom) => {
let singular = units.es.at(unit, default: units.en.at(unit))
if unit in ("lx", "Hz", "S") {
if unit in ("lx", "Hz", "S", "%", "‰") {
return singular
}
if unit == sym.degree + "C" { return "grados Celsius" }
Expand All @@ -520,10 +534,10 @@
return singular + "es"
}
},

it: (unit, count, is-in-denom) => {
let singular = units.it.at(unit, default: units.en.at(unit))
if unit in ("J", "A", "T") { return singular }
if unit in ("J", "A", "T", "%", "‰") { return singular }
if unit == sym.degree + "C" { return "gradi Celsius" }
if unit.ends-with("o") or unit.ends-with("e") {
return singular.slice(0, -1) + "i"
Expand All @@ -541,8 +555,8 @@

// Easier keywords
let (dual, plural-3-4, is-float) = (
count == 2, // Dual
count in (3, 4), // Plural for 3 and 4
count == 2, // Dual
count in (3, 4), // Plural for 3 and 4

// A would-be `plural-5` for 5+ and 0
// Is simply an `else` branch instead
Expand Down Expand Up @@ -574,14 +588,13 @@

let masculine(word) = {
// Denominator rule with a hardcoded `return`
if is-in-denom and word == "tesla" { return word.slice(0, -1) + "o" }
else if is-in-denom { return word }
if is-in-denom and word == "tesla" { return word.slice(0, -1) + "o" } else if is-in-denom { return word }

// Different float rule with a hardcoded `return`
if word == "tesla" and is-float {
return "tesle"
}

if dual or is-float {
if word == "dan" {
"dneva"
Expand All @@ -591,6 +604,8 @@
"lumna"
} else if word == "tesla" {
"tesli"
} else if word.ends-with("ek") {
word.slice(0, -2) + "ka"
} else if word.ends-with(regex("ber|ter")) {
word.slice(0, -2) + "ra"
} else {
Expand All @@ -605,6 +620,8 @@
"lumni"
} else if word == "tesla" {
"tesle"
} else if word.ends-with("ek") {
word.slice(0, -2) + "ki"
} else if word.ends-with(regex("ber|ter")) {
word.slice(0, -2) + "ri"
} else {
Expand All @@ -619,6 +636,8 @@
"lumnov"
} else if word == "tesla" {
"tesel"
} else if word.ends-with("ek") {
word.slice(0, -2) + "kov"
} else if word.ends-with(regex("ber|ter")) {
word.slice(0, -2) + "rov"
} else if word.ends-with(regex("c|j")) {
Expand All @@ -628,14 +647,21 @@
}
}
}

// Feminine
if unit in ("cd", str(sym.degree), "h", "min", "s", "t") {
return feminine(singular)
}

// Masculine
if unit in ("A", "B", "Bq", "C", "d", "Da", "dB", "eV", "F", "g", "Gy", "H", "ha", "Hz", "J", "K", "kat", "kg", "L", "lm", "lx", "m", "mol", "N", "Np", str(sym.Omega), "Pa", "rad", "S", "sr", "Sv", "T", "V", "W", "Wb") {
if (
unit in (
"A", "B", "Bq", "C", "d", "Da", "dB", "eV", "F", "g", "Gy", "H", "ha",
"Hz", "J", "K", "kat", "kg", "L", "lm", "lx", "m", "mol", "N", "Np",
str(sym.Omega), "Pa", "rad", "S", "sr", "Sv", "T", "V", "W", "Wb",
"%", "‰",
)
) {
return masculine(singular)
}

Expand All @@ -644,8 +670,7 @@
return singular
.split(" ")
.map(word => {
if word == "Celzija" { word }
else { feminine(word) }
if word == "Celzija" { word } else { feminine(word) }
})
.join(" ")
}
Expand All @@ -660,15 +685,15 @@
#let join-prefix-unit(
/// The translated prefix, e.g. "milli"
/// -> str
prefix,
prefix,

/// The translated unit, e.g. "meter".
/// -> str
unit,
unit,

/// The language code.
/// -> str
lang
lang,
) = {
if lang == "de" {
prefix + lower(unit)
Expand All @@ -683,11 +708,11 @@
#let needs-plural(
/// The value of the quantity, e.g. `1.5`.
/// -> float
value,
value,

/// The language code.
/// -> str
lang
lang,
) = {
if lang == "fr" {
calc.abs(value) >= 2
Expand Down Expand Up @@ -743,33 +768,21 @@
)
} else {
alt += (
" "
+ translation.plus
+ " "
+ translation.minus
+ " "
+ format-comma-number(..info.pm)
" " + translation.plus + " " + translation.minus + " " + format-comma-number(..info.pm)
)
}
}
if info.e != none {
alt += (
" "
+ translation.times
+ " "
+ base-to-string(info.base)
+ " "
+ translation.power
+ " "
+ info.e
" " + translation.times + " " + base-to-string(info.base) + " " + translation.power + " " + info.e
)
}

alt
}




#let unit-component-description(
component,
Expand All @@ -778,21 +791,18 @@
is-in-denom: false,
) = {
if count == auto {
if not plural { count = 1 }
else { count = 99 }
if not plural { count = 1 } else { count = 99 }
}

let lang = text.lang
let units = units.en + units.at(lang, default: units.en)
let get-unit(unit-code) = {
if plural { (pluralize.at(lang))(unit-code, count, is-in-denom) }
// Add your language here to `pluralize` the denominator
if plural { (pluralize.at(lang))(unit-code, count, is-in-denom) } // Add your language here to `pluralize` the denominator
else if is-in-denom and lang == "sl" {
(pluralize.at(lang))(unit-code, count, is-in-denom)
}
else { units.at(unit-code) }
} else { units.at(unit-code) }
}

if type(component) in (symbol, str) {
component = str(component)
if component in units {
Expand Down Expand Up @@ -857,7 +867,6 @@
unit
}


let plural = needs-plural(value, lang)
if numerator.len() > 0 {
alt += (
Expand Down
12 changes: 5 additions & 7 deletions src/zi.typ
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#let ohm = declare(sym.Omega)
#let pascal = declare("Pa")
#let radian = declare("rad")
#let degree = declare(sym.degree)
#let percent = declare("%")
#let promille = declare("‰")
#let siemens = declare("S")
#let sievert = declare("Sv")
#let steradian = declare("sr")
Expand Down Expand Up @@ -81,14 +84,13 @@
#let dalton = declare("Da")
#let day = declare("d")
#let decibel = declare("dB")
#let degree = declare(sym.degree)
#let electronvolt = declare("eV")
#let hectare = declare("ha")
#let hour = declare("h")
#let liter = declare("L")
#let arcminute = declare(sym.prime)
#let minute = declare("min")
#let arcsecond = declare(sym.prime.double)
#let hour = declare("h")
#let minute = declare("min")
#let neper = declare("Np")
#let tonne = declare("t")
#let gram = declare("g")
Expand Down Expand Up @@ -117,7 +119,6 @@
#let µH = declare("µH")
#let uH = µH
#let nH = declare("nH")
#let pH = declare("pH")
#let mC = declare("mC")
#let nC = declare("nC")
#let µC = declare("µC")
Expand Down Expand Up @@ -198,6 +199,3 @@
#let N-A2 = declare("N/A^2")
#let F-m = declare("F/m")
#let kWh = declare("kW h")


#kWh()
2 changes: 2 additions & 0 deletions tests/accessibility/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@
H: ("henrijev", "henri", "henrija", "henrija", "henriji", "henrijev", "henrija", "henri"),
lm: ("lumnov", "lumen", "lumna", "lumna", "lumni", "lumnov", "lumna", "lumen"),
T: ("tesel", "tesla", "tesle", "tesli", "tesle", "tesel", "tesle", "teslo"),
"%": ("odstotkov", "odstotek", "odstotka", "odstotka", "odstotki", "odstotkov", "odstotka", "odstotek"),
"‰": ("odtisočkov", "odtisoček", "odtisočka", "odtisočka", "odtisočki", "odtisočkov", "odtisočka", "odtisoček"),

// Masculine, special rule for `*ber/*ter`
L: ("litrov", "liter", "litra", "litra", "litri", "litrov", "litra", "liter"),
Expand Down
Loading