Re: i18n and shell scripts

From: Jilles Tjoelker <jilles_at_stack.nl>
Date: Sun, 22 Jan 2012 23:50:38 +0100
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
Received on Sun Jan 22 2012 - 21:50:39 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:23 UTC