Re: i18n and shell scripts

2012-01-22 Thread Jilles Tjoelker
On Sun, Jan 22, 2012 at 04:05:10PM -0600, Ron McDowell wrote:
> I'm working on the new bsdconfig, and looking for some good examples of 
> how to incorporate internationalization into the scripts.  I'm not 
> finding much love in this area. :-(

> Any pointers appreciated.

Yes, this is not very easy, and particularly not if you only want to use
base system functionality.

An important thing is printf(1) as it will let you put placeholders for
variables in translatable strings rather than build strings from hard to
understand pieces. (Our printf(1) does not support changing the order of
variables like the printf(3) function does.)

With GNU gettext (which is in ports, not in base), you can translate
messages in a shell script much like in a C program, although you will
be invoking the gettext(1) tool rather frequently, which may be slow.
It has many features to help the programmer and the translator. This
also means that it can be fairly complicated to use.

Alternatively, you could do it yourself. One way would be to define a
variable for each translatable string with the default language's value,
then source a file for the appropriate language
(mylang=${LC_ALL-${LC_MESSAGES-${LANG}}}). Supporting multiple character
sets is going to be ugly because we do not have any form of iconv
(character set conversion) in base. This is particularly bad because
syscons does not support UTF-8 while many users want to use UTF-8 in X
instead of language-specific character sets.

The base catgets(3) facility does not provide a utility for use from
shell scripts, and is also harder to use than gettext.

-- 
Jilles Tjoelker
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


Re: i18n and shell scripts

2012-01-22 Thread Tim Kientzle

On Jan 22, 2012, at 2:05 PM, Ron McDowell wrote:

> I'm working on the new bsdconfig, and looking for some good examples of how 
> to incorporate internationalization into the scripts.  I'm not finding much 
> love in this area. :-(
> 
> Any pointers appreciated.


GNU gettext may not be an option here, but the documentation at

   http://www.gnu.org/software/gettext/manual/gettext.html#sh

outlines how this can be done.

The general model used by gettext and lots of other translation systems is:
   * There's a distinctive function name or source code pattern wrapping the 
English text strings.
   * So you can run a simple program that identifies and extracts these 
strings.  (Simple sed or awk scripts often suffice.)
   * Translation files map English text ==> translated text.  (There are many 
more-or-less standard formats used for translation files; the .po format used 
by gettext is widely supported by translation tools.  In particular, there are 
a number of commercial translation management interfaces that allow free use by 
open-source projects and can directly upload/download po files.)
   * Translation files can be compiled into some dictionary structure that can 
be used efficiently at run time.
   * The "distinctive source code pattern" above is typically a function name.  
At run-time, that function looks up the English text string from the source 
file and emits the result.

Nothing here is difficult to just build from scratch.  The complex part is the 
process for actually keeping track of what has and hasn't been translated 
across a large number of languages.  Fortunately, there are some pretty good 
translation management systems on the web where you can upload .po files, 
invite people to contribute translations and then download constructed .po 
files for each language.  At work, we've started using getLocalization.com, 
which looks pretty promising, but there are many others.

Warning:  Translating quantities (e.g., "$x bytes") is complicated (why does 
'zero' take a plural in English?).  You can sometimes just avoid it ("size in 
bytes: $x") and sometimes get by with stilted language (e.g., "1 bytes" or "$x 
byte(s)").  If you require high-quality handling of phrases that include 
variable numbers, then you'll need something more complex than just a lookup 
table.

Cheers,

Tim

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


i18n and shell scripts

2012-01-22 Thread Ron McDowell
I'm working on the new bsdconfig, and looking for some good examples of 
how to incorporate internationalization into the scripts.  I'm not 
finding much love in this area. :-(


Any pointers appreciated.

--
Ron McDowell
San Antonio TX

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"