lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great John Hind once stated:
> >Coda Highland <chighland@...> Fri, 21 Aug 2015 07:25:50 -0700
> 
> >Yes, internationalization is more complicated than that (in practice,
> >%s is insufficient and you need named or positional parameters, and
> >then plurals and gender make a mess of things) but format strings are
> >utterly fundamental to doing it right.
> 
> So wrap "message.syslog" as a function, put it and the other message
> formatters in a language file and give that to the translator. Your whole
> case depends on a kind of coder's snobbery that says a translator cannot
> cope with some simple Lua, but can internalise a complex and arbitrary
> formatting syntax (plus you are admitting that the current Lua system is
> not complex and arbitrary enough for this use case!)

  I'll give "complex" a pass (given the the modifiers you can add), but
where do you get "arbitrary" from?

	%d - decimal output of a number
	%o - octal output of a number
	%x - hexidecimal output of a number
	%s - string
	%f - float
	%q - quoted string

  Also, a format string does make it easier to handle translations. 
Granted, this is geared more for compiled languages like C where (depending
on the platform) it might be impossible to load variations on code (like a
shared library [1]) but it can also be applied to languages like Perl, Lua,
Ruby or Python.

  First, the programmers will have to write strings wrapped in a function:

	display(T"%d piggies were frightened by %d wolves",numpigs,numwolves)

  This serves two purposes, the first one is that a special tool can be used
to extract all the "tranlatable" strings from the source code into a file
(say, called "English"):

	%d piggies were frightened by %d wolves

  Then the translators can go to work, trying their best to translate the
string with positional data [2]:

	%d iggiespay ereway ightenedfray ybay %d olvesway

These can be put into a file (say, called "PigLatin").  Then the program
can select, at runtime, which language file to use.  This is where the
second purpose of the T() comes into play.  The source code is not changed, so
when running, T() will get the original string ("%d piggies were frightened
by %d wolves") which is can then use as a key to lookup the translated
string ("%d iggiespay ereway ightenedfray ybay %d olvesway") and return
that.

  So there's more to this than just "coder's snobbery," unless you mean
making everybody's (programmers, translators, testers) lives easier "coder's
snobbery."
  
  -spc (Why the hate for format strings?  Did printf() bite you as a kid?)

[1]	There's still quite a bit of work in the embedded space using C/C++
	where dynamically loading code isn't possible or desired.

[2]	Python has an alternative format specification where you can specify
	which parameter (either by name or position in the argument list) to
	use.  This makes it a bit easier to translate messages.