From: Sietse Brouwer <sbbrouwer@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: ConTeXt: Page numbering in words for spanish
Date: Wed, 21 Nov 2012 12:25:03 +0100 [thread overview]
Message-ID: <CAF=dkzzbxuiv65W=GnVBXRUORiCtqsmw+qyHwO3_r+5rw3Vdrw@mail.gmail.com> (raw)
In-Reply-To: <50ACAC69.9060603@wxs.nl>
Hi Acidrums, hi Hans,
I worked up the code below,
put it in core-con.lua,
and recompiled ConTeXt with `context --make cont-en`.
It gives the following output. Does it look correct?
Hans: the `spanishwords` is a bit hacky; probably words should have
subtables words.english and words.spanish.
Cheers,
Sietse
11.111.111 once millón cien once mil cien once
2.221.101 dos millón doscientos veintiuno mil cien uno
1.111 uno mil cien once
1.218 uno mil doscientos dieciocho
1.234 uno mil doscientos treinta y cuatro
12.345 doce mil trescientos cuarenta y cinco
12.345.678.900.000 doce billón trescientos cuarenta y cinco mil
millones seiscientos
sietenta y ocho millón novecientos mil
local spanishwords = {
[0] = "zero",
[1] = "uno",
[2] = "dos",
[3] = "tres",
[4] = "cuatro",
[5] = "cinco",
[6] = "seis",
[7] = "siete",
[8] = "ocho",
[9] = "nueve",
[10] = "diez",
[11] = "once",
[12] = "doce",
[13] = "trece",
[14] = "catorce",
[15] = "quince",
[16] = "dieciséis",
[17] = "diecisiete",
[18] = "dieciocho",
[19] = "diecinueve",
[20] = "veinte",
[21] = "veintiuno",
[22] = "veintidós",
[23] = "veintitrés",
[24] = "veinticuatro",
[25] = "veinticinquo",
[26] = "veintiséis",
[27] = "veintisiete",
[28] = "veintiocho",
[29] = "veintinueve",
[30] = "treinta",
[40] = "cuarenta",
[50] = "cinquenta",
[60] = "sesenta",
[70] = "sietenta",
[80] = "ochenta",
[90] = "noventa",
[100] = "cien",
[200] = "doscientos",
[300] = "trescientos",
[400] = "cuatrocientos",
[500] = "quinientos",
[600] = "seiscientos",
[700] = "setecientos",
[800] = "ochocientos",
[900] = "novecientos",
[1000] = "mil",
[1000^2] = "millón",
[1000^3] = "mil millones",
[1000^4] = "billón",
}
function verbose.spanish(n)
local w = spanishwords[n]
if w then
return w
end
local t = { }
local function compose_one(n)
local w = spanishwords[n]
if w then
t[#t+1] = w
return
end
-- a, b = hundreds, remainder
local a, b = floor(n/100), n % 100
-- one thousand
if a == 10 then
t[#t+1] = spanishwords[1]
t[#t+1] = spanishwords[1000]
-- x hundred (n.b. this will not give thirteen hundred because
-- compose_one(n) is only called after
-- `n = compose(two(n, 1000^1))`.
elseif a > 0 then
t[#t+1] = spanishwords[a*100]
end
-- the remainder
if spanishwords[b] then
t[#t+1] = spanishwords[b]
else
-- a, b = tens, remainder
a, b = floor(b/10), n % 10
t[#t+1] = spanishwords[a*10]
t[#t+1] = "y"
t[#t+1] = spanishwords[b]
end
end
-- compose_two handles x billion, ... x thousand. When 1000 or less is
-- left, compose_one takes over.
local function compose_two(n,m)
if n > (m-1) then
local a, b = floor(n/m), n % m
if a > 0 then
compose_one(a)
end
t[#t+1] = spanishwords[m]
n = b
end
return n
end
n = compose_two(n,1000^4)
n = compose_two(n,1000^3)
n = compose_two(n,1000^2)
n = compose_two(n,1000^1)
if n > 0 then
compose_one(n)
end
return #t > 0 and concat(t," ") or tostring(n)
end
verbose.es = verbose.spanish
---- to test the code ---
\starttext
\def\vbes#1%
{#1\crlf
\ctxcommand{verbose(#1, "spanish")}}
\obeylines
\vbes{11111111}
\vbes{2221101}
\vbes{1111}
\vbes{1218}
\vbes{1234}
\vbes{12345}
\vbes{12345678900000}
\stopcode
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2012-11-21 11:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-21 9:08 Acidrums4
2012-11-21 10:26 ` Hans Hagen
2012-11-21 11:25 ` Sietse Brouwer [this message]
2012-11-21 11:52 ` Hans Hagen
2012-11-21 12:28 ` Sietse Brouwer
2012-11-21 21:05 ` Acidrums4
2012-11-21 23:47 ` Sietse Brouwer
2012-11-22 0:03 ` Acidrums4
2012-11-22 10:55 ` Mojca Miklavec
2012-11-22 12:11 ` Sietse Brouwer
2012-11-23 20:50 ` Marcin Borkowski
2012-11-23 22:46 ` Hans Hagen
2012-11-23 23:09 ` Alan BRASLAU
2012-11-22 10:04 ` Hans Hagen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAF=dkzzbxuiv65W=GnVBXRUORiCtqsmw+qyHwO3_r+5rw3Vdrw@mail.gmail.com' \
--to=sbbrouwer@gmail.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).