phpwiki-talk

A few thoughts -
1) The language of the interface should be user-selectable. Just because
the [web|wiki]master has decided to set the locale as Italian, doesn't mean
that everyone wants to see Italian links/instructions.
2) Is gettext the best solution for Multi-languages? It requires php to
be complied in a particular way. Not everyone can specify how php is
compiled. What about a file with defined constants, eg:
define ('_MUST_BE_AUTH', 'You must be authorised to do that');
We could then translate the file for each language, and include the
appropriate one, depending on the user's selection. Another problem with
gettext is that if you mistype the original language in the code (and some
of the phrases are quite long), gettext is unable to find the
translation. Perhaps the answer is that I should type more carefully!
3) It seems to me to be asking for trouble to have to translate the
templates for each language. Each time the template changed, the
translations would have to be updated. Wouldn't it be better to have
language defines (as above), or even template variables in the template,
which are replaced by the Template munger appropriately, eg:
<a href=blah.blah>{GETTEXT: _EDITLINK}</a>
Lawrence Akka
-------------------------------------------------
FROM: nada.kth.se
DATE: 11/27/2001 10:09:21
SUBJECT: RE: [Phpwiki-talk] About languages
--azLHFNyN32YCQGCU
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by my.nada.kth.se id
TAA14304
On Tue, Nov 27, 2001 at 09:29:45AM -0800, Jeff Dairiki wrote:
> Yes, all the non-english templates are currently broken in PhpWiki 1.3.
I've just made a small update (po, pgrsc, and templates) to the
Swedish translation of 1.2 (attached, I hope it's ok?) and I'll fix it
for the 1.3 line as well, but not tonight.
==========NOTICE==========
Internet e-mail is not necessarily secure or reliable. Please let us know if you would like to establish a secure channel of communication.
This e-mail and any attachments are confidential and may be legally privileged. They are intended only for the use of the named recipient. If you are not the named or intended recipient, please notify us immediately. In such an event, you should not disclose the contents of this e-mail or any attachments to any other person, nor copy, print, store or use them in any manner whatsoever. Thank you for your co-operation.
Although we have taken precautions to minimize the risk of transmitting software viruses, you are advised to carry out your own virus checks on any attachments to this message.
Tel: +44 (0)207 842 1200
http://www.20essexst.com
postmaster@...

On Wed, 28 Nov 2001 10:08:36 +0000
"Lawrence Akka" <lakka@...> wrote:
> A few thoughts -
>
> 1) The language of the interface should be user-selectable. Just
because
> the [web|wiki]master has decided to set the locale as Italian, doesn't
mean
> that everyone wants to see Italian links/instructions.
Yes, once we have real users and user preferences, that's probably a fine
idea.
> 2) Is gettext the best solution for Multi-languages? It requires php
to
> be complied in a particular way. Not everyone can specify how php is
> compiled.
One of the big advantages of using gettext is the development tools that
are available for it. (I.e. there is a program which scans through all
the source code and pulls out strings which are used as arguments to
gettext; another program merges any changes in that set of strings with
the editable translation map (.po) files; and there's a po-mode for
emacs.)
PhpWiki does not require gettext support to be compiled in to PHP. It
provides a pure PHP replacement if it's not. (I haven't tested that in
awhile, so it may well be broken...)
The only downside I see is that one is required to have the gettext tools
installed (and have some idea of how to use them) to be able to edit or
customize the translations.
We need to use the standard setlocale() stuff anyway to get date formats
right. Gettext is the natural way to handle translated strings.
> define ('_MUST_BE_AUTH', 'You must be authorised to do that');
This is a nightmare to maintain. Imagine:
In somefile.php:
$msg = sprintf(_MUST_BE_AUTH_TO_EDIT, $pagename);
In somelang.php:
define ('_MUST_BE_AUTH_TO_EDIT', "Ogg frrble MOTU erg '%s' frk.");
In deflang.php:
if (! defined('_MUST_BE_AUTH_TO_EDIT'))
define ('_MUST_BE_AUTH_TO_EDIT', "You must be god to edit
'%s'.");
The gettext development tools handle all this for you.
> Another problem with gettext is that if you mistype the original
> language in the code (and some of the phrases are quite long),
> gettext is unable to find the translation.
If/when the language becomes user selectable, I think the selection will
be made via a <select> field in a <form>. (The local admin will have to
make sure the the choices presented are all valid on the local system.)
On the administration side: it is very confusing to figure out which LANG
settings work on a particular system. We should probably code in a list
of alternatives to try for each language which PhpWiki supports. I.e. in
the config file, the admin sets $LANG='german'; the php code then tries
LANG='de_DE.ISO-8859-1', LANG='de_DE', LANG='de', LANG='deutsch',
LANG='german' until it finds one which works.
> 3) It seems to me to be asking for trouble to have to translate the
> templates for each language. Each time the template changed, the
> translations would have to be updated. Wouldn't it be better to have
> language defines (as above), or even template variables in the template,
> which are replaced by the Template munger appropriately, eg:
Yes. Good idea.
This can more-or-less be done now (in 1.3), in an ugly fashion, as
follows:
<a href="http://..."><?php echo gettext("Some text."); ?></a>
Perhaps we could support a more compact syntax...
And while on the subject, my one nit about gettext is:
For it's compactness, I much prefer
$msg = _("string");
to
$msg = gettext("string");
The _() abbreviation is standard usage --- the gettext tools support it by
default. (PHP, if gettext support is compiled in, supports the _() syntax
already. We'd have to define the '_' replacement function when there's no
PHP gettext support if we were to start using it in PhpWiki code.)
Does anyone have objections to the abbreviated syntax?

Today while I was adding a few more German translations to the
template/Edit.html I realized a small problem in using the _("text")
function to translate localized text, has this already been discussed?
Different languages have different word ordering. When a key word needs to
be added to the end of a sentence in english, it might need to be inserted
into the middle of the sentence in another language.
For example:
English:
$_("Author will be logged as") <i>${USERID}</i>.
German:
$_("Der Autor wird als") <i>${USERID}</i> aufgenommen.
Is there an existing way around this? Without a code-based solution Wiki
may be stuck with individual localized templates.
Carsten
On Thursday, November 29, 2001, at 12:42 am, Reini Urban wrote:
> Reini Urban schrieb:
>> <a href="http://..."><?=_("Some text.")_?></a>
> ^
>
> oops:
> <a href="http://..."><?=_("Some text.")?></a>
>

Carsten Klapp schrieb:
> Today while I was adding a few more German translations to the
> template/Edit.html I realized a small problem in using the _("text")
> function to translate localized text, has this already been discussed?
>
> Different languages have different word ordering. When a key word needs to
> be added to the end of a sentence in english, it might need to be inserted
> into the middle of the sentence in another language.
>
> For example:
>
> English:
> $_("Author will be logged as") <i>${USERID}</i>.
>
> German:
> $_("Der Autor wird als") <i>${USERID}</i> aufgenommen.
>
> Is there an existing way around this? Without a code-based solution Wiki
> may be stuck with individual localized templates.
The standard answer is sprintf.
sprintf(_("Der Autor wird als %s aufgenommen"), "<i>$USERID</i>")
But this imposes problems to at least my hord of inexperienced translators.
(they don't know about %s or %d, they don't know what value will be inserted,
which variable, and how many % vars need to be inserted)
So I use a limited set of variables which get expanded at run-time from
the definitions strings.
something like:
register_gettext_expansion('USERID');
echo x_('Der Autor wird als $USERID aufgenommen');
writing this from scratch... (totally untested. I use a completely
different translation scheme on my current project. translators do it online).
I register only uppercase vars for this.
function register_gettext_expansion ($var) {
if (!is_array($GLOBALS['GETTEXT_VARS']))
$GLOBALS['GETTEXT_VARS'] = array();
$GLOBALS['GETTEXT_VARS'][] = $var;
}
function x_($msg) {
$msg = gettext($msg);
// this could be improved to expand on all vars in the msg,
// not on all existing vars...
if (!(($i = strpos($msg, '$')) === false) and
(substr($msg,$i-1,1) != '\\')) {
foreach ($GLOBALS['GETTEXT_VARS'] as $s) {
if (!empty($GLOBALS[$s]))
$msg = str_replace('$' . $s, $GLOBALS[$s], $msg);
}
}
return $msg;
}
The problem is that $ must be quoted and that I did't check for that in
my old version. Luckily I don't have us money in my strings :)
Another problem is that the gettext extraction tools only recognize
_("") and not _(''). so we must use
echo x_("Der Autor wird als \$USERID aufgenommen");
--
Reini Urban
http://xarch.tu-graz.ac.at/home/rurban/

At 16:40 28/11/2001, Jeff Dairiki wrote:
> > 3) It seems to me to be asking for trouble to have to translate the
> > templates for each language. Each time the template changed, the
> > translations would have to be updated. Wouldn't it be better to have
> > language defines (as above), or even template variables in the template,
>
> > which are replaced by the Template munger appropriately, eg:
>
>Yes. Good idea.
>
>This can more-or-less be done now (in 1.3), in an ugly fashion, as
>follows:
>
> <a href="http://..."><?php echo gettext("Some text."); ?></a>
>
>Perhaps we could support a more compact syntax...
>
What about {_WhateverText}.
Template.php could then pick use a regexp to pick up {_(.*)} (or whatever
- not sure if that one works). and yank in the necessary translation.
WOuld only cause a problem if someone wanted to use {_ in their template.
>And while on the subject, my one nit about gettext is:
>
>For it's compactness, I much prefer
> $msg = _("string");
>to
> $msg = gettext("string");
>
>The _() abbreviation is standard usage --- the gettext tools support it by
>default. (PHP, if gettext support is compiled in, supports the _() syntax
>already. We'd have to define the '_' replacement function when there's no
>PHP gettext support if we were to start using it in PhpWiki code.)
>
>Does anyone have objections to the abbreviated syntax?
I agree.
Lawrence
==========NOTICE==========
Internet e-mail is not necessarily secure or reliable. Please let us know if you would like to establish a secure channel of communication.
This e-mail and any attachments are confidential and may be legally privileged. They are intended only for the use of the named recipient. If you are not the named or intended recipient, please notify us immediately. In such an event, you should not disclose the contents of this e-mail or any attachments to any other person, nor copy, print, store or use them in any manner whatsoever. Thank you for your co-operation.
Although we have taken precautions to minimize the risk of transmitting software viruses, you are advised to carry out your own virus checks on any attachments to this message.
Tel: +44 (0)207 842 1200
http://www.20essexst.com
postmaster@...

On Wed, 28 Nov 2001 17:19:37 +0000
"Lawrence Akka" <lakka@...> wrote:
> What about {_WhateverText}.
The one other thing to consider is that it would be nice to use a syntax
which can be grokked by xgettext (which is designed for picking gettext()
calls out of C code). Some options which work:
gettext("string")
$gettext("string")
_("Text string")
$_("string")
(The parentheses around a "-quoted string are the key.)
These are all somewhat ugly, but acceptable, I think. Of the above
choices, I like $_("this one").
(The other option would be to write our own replacement or pre-filter for
xgettext. :-/ )
> >The _() abbreviation is standard usage --- the gettext tools support it
by
> >default.
Correction: GNU xgettext doesn't support _() by default, you must include
the '-k_' command line argument. The _() is fairly standard usage
however, and stock PHP does define '_' as an alias for 'gettext'.