(This is drifting off topic but what the heck)
This is OK for a one-off, but it breaks internationalization. As
the GNU gettext manual says: [much snippage]
... For example, Rafal Maszkowski `<
[email protected]>' reports:
In Polish we use e.g. plik (file) this way:
1 plik
2,3,4 pliki
5-21 pliko'w
22-24 pliki
25-31 pliko'w
and so on (o' means 8859-2 oacute which should be rather okreska,
similar to aogonek).
Clearly what is needed is something akin to terminfo, in which the
text translations have access to the numeric parameter(s) and can
perform arithmetic. For instance, something like this might work:
found %p1%d %{p1 1 = if text "plik" else {
p1 10 % 4 < if text "pliki" else text "pliko'w" } }
Here "%" introduces some kind of access or conversion, and %{ ... }
encloses "long form" or "readable" versions that require using the
"text" keyword to emit text. This might be equivalent to the
"short form" version:
found %p1%d %p1%1%=%?plik%:%p1%10%m%4%<%?pliki%
liko'w
In either case, the C code call would be something like:
emit("found %d files", nfiles);
where the string literal ("found %d files") is also the key into
the database, and the number of parameters is probably limited to
some smallish constant (no more than 50, say). The string literal
can only contain "simple" conversion specifiers -- which need not
match one-for-one with print conversions -- that serve to identify
the variadic arguments for storage, for later access via the "pN"
parameter access strings. (The string literal could also serve
as a backup "emergency" string in case the translation database
is not available.)
(Not everyone likes RPN-like stack-y languages, of course, and the
use of %m for mod above is just to allow %% to represent a literal
percent sign. This is not intended to be a fully-thought-out proposal.)
(I suspect some will object to "inefficiency" in having to turn the
literal into a database search key. There is also some possibility
that multiple different replacement strings might map to one single
source string in English.)