summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/core-con.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2021-04-18 19:27:46 +0200
committerContext Git Mirror Bot <phg@phi-gamma.net>2021-04-18 19:27:46 +0200
commit4831ec8b98dbd0b637271f601c288960f9259bfc (patch)
tree9163b423a7b6f23b0249e923cab8e4a1f2ca18b0 /tex/context/base/mkiv/core-con.lua
parent113a26a2838ace27514f6348ed0d41bf87724472 (diff)
downloadcontext-4831ec8b98dbd0b637271f601c288960f9259bfc.tar.gz
2021-04-18 18:07:00
Diffstat (limited to 'tex/context/base/mkiv/core-con.lua')
-rw-r--r--tex/context/base/mkiv/core-con.lua105
1 files changed, 105 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/core-con.lua b/tex/context/base/mkiv/core-con.lua
index 4bf1424bc..f1aa37a7c 100644
--- a/tex/context/base/mkiv/core-con.lua
+++ b/tex/context/base/mkiv/core-con.lua
@@ -1415,6 +1415,111 @@ data.es = data.spanish
-- print(translate(101))
-- print(translate(199))
+-- verbose swedish by Peter Kvillegard
+
+do
+
+ local words = {
+ [0] = "noll",
+ [1] = "ett",
+ [2] = "två",
+ [3] = "tre",
+ [4] = "fyra",
+ [5] = "fem",
+ [6] = "sex",
+ [7] = "sju",
+ [8] = "åtta",
+ [9] = "nio",
+ [10] = "tio",
+ [11] = "elva",
+ [12] = "tolv",
+ [13] = "tretton",
+ [14] = "fjorton",
+ [15] = "femton",
+ [16] = "sexton",
+ [17] = "sjutton",
+ [18] = "arton",
+ [19] = "nitton",
+ [20] = "tjugo",
+ [30] = "trettio",
+ [40] = "fyrtio",
+ [50] = "femtio",
+ [60] = "sextio",
+ [70] = "sjuttio",
+ [80] = "åttio",
+ [90] = "nittio",
+ [100] = "hundra",
+ [10^3] = "tusen",
+ [10^6] = "miljon",
+ [10^9] = "miljard",
+ [10^12] = "biljon",
+ [10^15] = "biljard",
+ }
+
+ local function translate(n,connector)
+ local w = words[n]
+ if w then
+ return w
+ else
+ local t = { }
+ local l = 0
+ -- group of three digits to words, e.g. 123 -> etthundratjugotre
+ local function triplets(n)
+ if floor(n/100) > 0 then
+ l = l + 1 ; t[l] = words[floor(n/100)]
+ l = l + 1 ; t[l] = words[100]
+ end
+ if n%100 > 20 then
+ l = l + 1 ; t[l] = words[n%100-n%10]
+ if n%10 > 0 then
+ l = l + 1 ; t[l] = words[n%10]
+ end
+ elseif n%100 > 0 then
+ l = l + 1 ; t[l] = words[n%100]
+ end
+ end
+ -- loops through 10^15,10^12,...10^3, extracting groups of three digits
+ -- to make words from, then adding names for order of magnitude
+ for i=15,3,-3 do
+ local triplet = floor(n/10^i)%10^3
+ if triplet > 0 then
+ -- grammar: "en" instead of "ett"
+ if i > 3 and triplet == 1 then
+ l = l + 1 ; t[l] = "en"
+ else
+ triplets(triplet)
+ end
+ -- grammar: plural form of "millions" etc
+ l = l + 1 ; t[l] = words[10^i]
+ if i > 3 and triplet > 1 then
+ l = l + 1 ; t[l] = "er"
+ end
+ end
+ end
+ -- add last group of three numbers (no word for magnitude)
+ n = n%1000
+ if n > 0 then
+ triplets(n)
+ end
+ t = concat(t," ")
+ -- grammar: spacing for numbers < 10^6 and repeated letters
+ if n < 10^6 then
+ t = gsub(t,"%stusen%s","tusen")
+ t = gsub(t,"etttusen","ettusen")
+ end
+ return t
+ end
+ end
+
+ data.swedish = {
+ words = words,
+ translate = translate,
+ }
+
+ data.sv = data.swedish
+
+end
+
-- verbose handler:
function converters.verbose.translate(n,language,connector)