Re: internationalization
Derek Robert Price <[email protected]> Tue, 09 Sep 2003 11:38:26 -0400
| Newsgroups | gmane.comp.tex.texi2html.devel |
|---|---|
| Organization | Ximbiot <http://ximbiot.com> |
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dumas Patrice wrote:
|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.
Except that you've now excluded constructs such as %{section_name}word.
%section_nameword would specify a new variable to the parser.
Regardless, % doesn't really need to be escaped, and neither does `{' or
`}'. Even if these appear together or with words in the middle, they
will only be substituted by the above code if they mention one of the
hash keys passed in. i.e. %{}, %{{{{{{}, %{something_undefined}, and so
on would all be treated as literals by the code above. The only
constructs a user could not get at would be ones where the variable was
defined (the user could not pass through a literal `%{section_name}' and
we would have to allow an escape for that case in either situation.
|>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 was thinking about something along these lines too. I hadn't decided
yet that it was reasonable to exclude variables (i.e. require only
quoted strings there) from the first argument to get_message, but it
sounds right.
|>|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.
The last figure I heard for a count of spoken languages in the world was
over 9000, but I don't recall where I heard it. I think the number of
written languages is smaller.
<http://www.unicode.org/onlinedat/languages.html> lists c. 162 languages
with ISO codes and another 16 that have windows or macintosh codes and
no ISO code.
|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.
This is true. It does require a translator, but I was thinking that
installed as I mentioned, a user could override the translations or
provide new ones simply by adding or replacing files in
TEXI2HTML_LIB/i18n/* or `dirname $0`/i18n/*. Perhaps a combination of
the methods would be in order? If a file can be found in the above
dirs, source it and allow its contents to override the internal variables?
Derek
- --
~ *8^)
Email: [email protected]
Get CVS support at <http://ximbiot.com>!
- --
What is this talk of "release?" We do not make software
"releases." Our software "escapes," leaving a bloody trail of
designers and quality assurance people in its wake.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Using GnuPG with Netscape - http://enigmail.mozdev.org
iD8DBQE/XfPuLD1OTBfyMaQRAso5AJ9CBqlBwcnnUTjl0FxNKmu1r/sh6QCg/qMz
XT+pmp8kzaFQ8SLxJ3crLNc=
=4YlA
-----END PGP SIGNATURE-----