Re: internationalization

Dumas Patrice <[email protected]> Tue, 9 Sep 2003 12:14:36 +0200
Newsgroups gmane.comp.tex.texi2html.devel
Message-ID <[email protected]>
Hi,

> |If yes, do you have an idea on how to do it practically ?
> 
> 
> ~    #! perl
> ~    sub
> ~    get_message {
> ~        my ($key, %input_hash) = @_;
> ~        $key =~ s/%\{(\w+)\}/$input_hash{$1} || $&/eg;
> ~        return $key;
> ~    }
> 
> print get_message("See section %{section_name} in %{book}", section_name
> => "5.6.19", book => "A Guide to Everything");

This seems pretty right. I will do that soon. I believe that 
get_message('See section %section_name in %book', { 'section_name'
 => "5.6.19", 'book' => "A Guide to Everything")
will be even more practical, as only % has to be escaped.

> The texi2html version would need some code which checked the current
> language and subbed into a translation from the appropriate translation
> file or $key if no translation was found, but the rest should be able to
> remain essentially unchanged.

Yes, this seems pretty straightforward.

> Yes.  I'd have to think a bit to come up with the parser - it's possible
> something simple would do but if not we might be able to leverage
> existing Perl parsers.  As a quick example:
> 
> ~    perl -e 'while (<>) { if (/\bget_message\s*\(.*\)/) {
> s/^.*\bget_message\s*\(\s*([^),]+).*$/$1/; print; } }' texi2html.pl
> 
> would print a list of the keys, one per line, if there were no more than
> one call to get_message per line, a single call to get_message never
> took up more than a single line, the key strings did not contain commas
> or spaces, and the declaration of get_message did not contain a prototype.

I think that it is possible to come up with something simpler, as
get_message is in reality Texi2HTML::I18n::get_message, thus there is near
the beginning of the code: $I = \Texi2HTML::I18n::get_message;
and in the code &$I('string'). Moreover we could agree to quote strings with
' thus te only issue is to detect \\ and \'. This should be easy, too.

> |I added that file because I wanted to use AC_SUBST_FILE in configure.in.
> |Maybe we could use another technic ?
> 
> 
> Ah.  Maybe.  I'm wondering if having a copy of all the strings in the
> executable file is really optimal anyhow?  Few programs fail to expect
> that they have been installed properly.  What if texi2html looked for
> the i18n files in TEXI2HTML_LIB/i18n/* or `dirname $0`/i18n/* and
> required only the ones it needed to use?

This could be possible, but I think we should try to make it possible to 
install texi2html and have everrything ok. I also think that the strings 
needed are finite. I don't know, however, how many languages there are.
Maybe we could keep on merging everything in the script until there are
too much languages used, but I don't think this will happen soon.

Pat