Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Jan 2012 23:50:38 +0100
From:      Jilles Tjoelker <jilles@stack.nl>
To:        Ron McDowell <rcm@fuzzwad.org>
Cc:        freebsd-current <freebsd-current@freebsd.org>
Subject:   Re: i18n and shell scripts
Message-ID:  <20120122225037.GC33235@stack.nl>
In-Reply-To: <4F1C8816.5030104@fuzzwad.org>
References:  <4F1C8816.5030104@fuzzwad.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120122225037.GC33235>