oxedyne/fe2o3/fe2o3_austenite/src/eval/lib/model/local.rs
6.3 KiB, 1 run
created by r1870400018:63268, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Original work copyright (c) the Typst project authors (typst-library `text/lang.rs` and `translations/*.txt`, version 0.15.1). |
| 3 | // Modified for Austenite: the translation tables are Typst's own files, unchanged; the lookup is ported to Hematite's types. |
| 4 | // U5 owns this file: the words Typst puts in a document for the reader's language -- the default |
| 5 | // supplements (`Figure`, `Section`), titles (`Contents`, `Bibliography`) and link descriptions. |
| 6 | // |
| 7 | // The `translations/*.txt` tables are Typst 0.15.1's own (`typst-library/translations`, Apache-2.0, |
| 8 | // copyright the Typst project contributors), copied unchanged. Lookup follows `localized_str`: the |
| 9 | // language with its region, then the language alone, then English. |
| 10 | |
| 11 | use oxedyne_fe2o3_core::prelude::*; |
| 12 | |
| 13 | // Each bundle's name (`de`, `fr-CA`) and its `key = value` lines. |
| 14 | static BUNDLES: &[(&str, &str)] = &[ |
| 15 | ("af", include_str!("translations/af.txt")), |
| 16 | ("alt", include_str!("translations/alt.txt")), |
| 17 | ("am", include_str!("translations/am.txt")), |
| 18 | ("ar", include_str!("translations/ar.txt")), |
| 19 | ("ast", include_str!("translations/ast.txt")), |
| 20 | ("as", include_str!("translations/as.txt")), |
| 21 | ("az", include_str!("translations/az.txt")), |
| 22 | ("be", include_str!("translations/be.txt")), |
| 23 | ("bg", include_str!("translations/bg.txt")), |
| 24 | ("bn", include_str!("translations/bn.txt")), |
| 25 | ("bo", include_str!("translations/bo.txt")), |
| 26 | ("br", include_str!("translations/br.txt")), |
| 27 | ("bs", include_str!("translations/bs.txt")), |
| 28 | ("bua", include_str!("translations/bua.txt")), |
| 29 | ("ca", include_str!("translations/ca.txt")), |
| 30 | ("ckb", include_str!("translations/ckb.txt")), |
| 31 | ("cs", include_str!("translations/cs.txt")), |
| 32 | ("cu", include_str!("translations/cu.txt")), |
| 33 | ("cy", include_str!("translations/cy.txt")), |
| 34 | ("da", include_str!("translations/da.txt")), |
| 35 | ("de", include_str!("translations/de.txt")), |
| 36 | ("dsb", include_str!("translations/dsb.txt")), |
| 37 | ("el", include_str!("translations/el.txt")), |
| 38 | ("en", include_str!("translations/en.txt")), |
| 39 | ("eo", include_str!("translations/eo.txt")), |
| 40 | ("es", include_str!("translations/es.txt")), |
| 41 | ("et", include_str!("translations/et.txt")), |
| 42 | ("eu", include_str!("translations/eu.txt")), |
| 43 | ("fa", include_str!("translations/fa.txt")), |
| 44 | ("fil", include_str!("translations/fil.txt")), |
| 45 | ("fi", include_str!("translations/fi.txt")), |
| 46 | ("fr-CA", include_str!("translations/fr-CA.txt")), |
| 47 | ("fr", include_str!("translations/fr.txt")), |
| 48 | ("fur", include_str!("translations/fur.txt")), |
| 49 | ("ga", include_str!("translations/ga.txt")), |
| 50 | ("gd", include_str!("translations/gd.txt")), |
| 51 | ("gl", include_str!("translations/gl.txt")), |
| 52 | ("grc", include_str!("translations/grc.txt")), |
| 53 | ("gu", include_str!("translations/gu.txt")), |
| 54 | ("ha", include_str!("translations/ha.txt")), |
| 55 | ("he", include_str!("translations/he.txt")), |
| 56 | ("hi", include_str!("translations/hi.txt")), |
| 57 | ("hr", include_str!("translations/hr.txt")), |
| 58 | ("hsb", include_str!("translations/hsb.txt")), |
| 59 | ("hu", include_str!("translations/hu.txt")), |
| 60 | ("hy", include_str!("translations/hy.txt")), |
| 61 | ("ia", include_str!("translations/ia.txt")), |
| 62 | ("id", include_str!("translations/id.txt")), |
| 63 | ("is", include_str!("translations/is.txt")), |
| 64 | ("isv", include_str!("translations/isv.txt")), |
| 65 | ("it", include_str!("translations/it.txt")), |
| 66 | ("ja", include_str!("translations/ja.txt")), |
| 67 | ("ka", include_str!("translations/ka.txt")), |
| 68 | ("kmr", include_str!("translations/kmr.txt")), |
| 69 | ("km", include_str!("translations/km.txt")), |
| 70 | ("kn", include_str!("translations/kn.txt")), |
| 71 | ("ko", include_str!("translations/ko.txt")), |
| 72 | ("ku", include_str!("translations/ku.txt")), |
| 73 | ("la", include_str!("translations/la.txt")), |
| 74 | ("lb", include_str!("translations/lb.txt")), |
| 75 | ("lo", include_str!("translations/lo.txt")), |
| 76 | ("lt", include_str!("translations/lt.txt")), |
| 77 | ("lv", include_str!("translations/lv.txt")), |
| 78 | ("mk", include_str!("translations/mk.txt")), |
| 79 | ("ml", include_str!("translations/ml.txt")), |
| 80 | ("mr", include_str!("translations/mr.txt")), |
| 81 | ("ms", include_str!("translations/ms.txt")), |
| 82 | ("nb", include_str!("translations/nb.txt")), |
| 83 | ("nl", include_str!("translations/nl.txt")), |
| 84 | ("nn", include_str!("translations/nn.txt")), |
| 85 | ("no", include_str!("translations/no.txt")), |
| 86 | ("oc", include_str!("translations/oc.txt")), |
| 87 | ("or", include_str!("translations/or.txt")), |
| 88 | ("pa", include_str!("translations/pa.txt")), |
| 89 | ("pl", include_str!("translations/pl.txt")), |
| 90 | ("pms", include_str!("translations/pms.txt")), |
| 91 | ("pt-PT", include_str!("translations/pt-PT.txt")), |
| 92 | ("pt", include_str!("translations/pt.txt")), |
| 93 | ("rm", include_str!("translations/rm.txt")), |
| 94 | ("ro", include_str!("translations/ro.txt")), |
| 95 | ("ru", include_str!("translations/ru.txt")), |
| 96 | ("se", include_str!("translations/se.txt")), |
| 97 | ("si", include_str!("translations/si.txt")), |
| 98 | ("sk", include_str!("translations/sk.txt")), |
| 99 | ("sl", include_str!("translations/sl.txt")), |
| 100 | ("sq", include_str!("translations/sq.txt")), |
| 101 | ("sr", include_str!("translations/sr.txt")), |
| 102 | ("sv", include_str!("translations/sv.txt")), |
| 103 | ("ta", include_str!("translations/ta.txt")), |
| 104 | ("te", include_str!("translations/te.txt")), |
| 105 | ("th", include_str!("translations/th.txt")), |
| 106 | ("tk", include_str!("translations/tk.txt")), |
| 107 | ("tl", include_str!("translations/tl.txt")), |
| 108 | ("tr", include_str!("translations/tr.txt")), |
| 109 | ("ug", include_str!("translations/ug.txt")), |
| 110 | ("uk", include_str!("translations/uk.txt")), |
| 111 | ("ur", include_str!("translations/ur.txt")), |
| 112 | ("vi", include_str!("translations/vi.txt")), |
| 113 | ("zh-TW", include_str!("translations/zh-TW.txt")), |
| 114 | ("zh", include_str!("translations/zh.txt")), |
| 115 | ]; |
| 116 | |
| 117 | /// The word for `key` (`figure`, `heading`, `page`, ...) in `lang`, optionally narrowed by `region`. |
| 118 | pub fn local_name(key: &str, lang: &str, region: Option<&str>) -> &'static str { |
| 119 | if let Some(r) = region { |
| 120 | let name = fmt!("{}-{}", lang, r); |
| 121 | if let Some(v) = lookup(&name, key) { |
| 122 | return v; |
| 123 | } |
| 124 | } |
| 125 | if let Some(v) = lookup(lang, key) { |
| 126 | return v; |
| 127 | } |
| 128 | lookup("en", key).unwrap_or("") |
| 129 | } |
| 130 | |
| 131 | fn lookup(bundle: &str, key: &str) -> Option<&'static str> { |
| 132 | let text = BUNDLES.iter().find(|(n, _)| n.eq_ignore_ascii_case(bundle)).map(|(_, t)| *t); |
| 133 | let text = match text { |
| 134 | Some(t) => t, |
| 135 | None => return None, |
| 136 | }; |
| 137 | for line in text.lines() { |
| 138 | let line = line.trim(); |
| 139 | if line.is_empty() || line.starts_with('#') { |
| 140 | continue; |
| 141 | } |
| 142 | if let Some((k, v)) = line.split_once('=') { |
| 143 | if k.trim() == key { |
| 144 | return Some(v.trim()); |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | None |
| 149 | } |