You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Torsten Curdt <tc...@dff.st> on 2001/10/25 14:39:44 UTC

[RTl] i18n transformer

I'd like to propose some changes to the i18n transformer...
...but they are still more RT - so here we go:

We need the i18n transformer to be more pluggable in
aspects of the key lookup.
Right now only the XMLResourceBundle is supported.
But what if you want your resource strings to reside
in a database?

 a)We could have an AbstractI18nTransformer
   that can be extended from SqlI18nTransformer and
   XMLResourceBundleI18nTransformer.
   But this would mean to have different component
   for quite the same task. Don't know

 b)Maybe a bit nicer sollution could be to have an

    interface I18nDictonary {
       public String lookup( String key );
       public long getLastModified();
    }

   A helper class could delegate the lookup to the original
   XMLResourceBundle. If the getLastModified() is available
   making the I18nTransformer cacheable should be really easy,
   too. Cacheability would only depend on the features of
   the dictonary then.

I'd be happy to implement this stuff.
Just wanted to make sure I get a "ok" first ;)
--
Torsten


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


[OT] [RTl] i18n transformer

Posted by Vadim Gritsenko <va...@verizon.net>.
> -----Original Message-----
> From: Martin Man [mailto:Martin.Man@seznam.cz]
> Sent: Thursday, November 01, 2001 7:32 AM
> To: cocoon-dev@xml.apache.org
> Subject: Re: [RTl] i18n transformer
> 
> On Thu, Nov 01, 2001 at 09:04:25AM +0100, Enke Michael wrote:
> >
> > I have for column description very often the same words. E.g.:
> > employee
> > employee number
> > employee group
> > employee name
> > employee address
> > If somebody has the task to generate translations for other
languages
> > it would be very useful to only translate a word one time.
> 
> yep, that would be, but the assumption that you can shorten the
translation
> applies only for certain languages (english for ex.) that don't use
> declination (?? not sure about the name here), in czech, slovak,
polak, and
> others your examples with employee won't work you,
> 
> zamestnanec
> zamestnancovo cislo
> zamestnancova skupina
> zamestnancovo jmeno
> zamestnancova adresa
> 
> you see what a beautiful lang we have :-))

I almost understand it ;)))
(Mine native is Russian)

Regards,
Vadim

> 
> >
> > It is not so. Look at line 352 in XMLResourceBundle.java:
> >             itemValue = itemValue.trim();
> >             if(itemValue.length() == 0)
> >                 return null;
> >
> > But I wouldn't change this because it can be a hint that this item
> > was forgotten to translate. I would prefer an extra attribute for
> > real empty items.
> 
> yep I agree here also, the same way gettext and other translation
tools work,
> if no translation is present, original text is printed out, possibly
with some
> notice like "TRANSLATE: " prepended..
> 
> >
> > Michael
> >
> 
> martin
> --
> 2CC0 4AF6 92DA 5CBF 5F09  7BCB 6202 7024 6E06 0223
> http://mman.dyndns.org/mman.gpg



---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [RTl] i18n transformer

Posted by Martin Man <Ma...@seznam.cz>.
On Thu, Nov 01, 2001 at 09:04:25AM +0100, Enke Michael wrote:
> 
> I have for column description very often the same words. E.g.:
> employee
> employee number
> employee group
> employee name
> employee address
> If somebody has the task to generate translations for other languages
> it would be very useful to only translate a word one time.

yep, that would be, but the assumption that you can shorten the translation
applies only for certain languages (english for ex.) that don't use
declination (?? not sure about the name here), in czech, slovak, polak, and
others your examples with employee won't work you, 

zamestnanec
zamestnancovo cislo
zamestnancova skupina
zamestnancovo jmeno
zamestnancova adresa

you see what a beautiful lang we have :-))

> 
> It is not so. Look at line 352 in XMLResourceBundle.java:
>             itemValue = itemValue.trim();
>             if(itemValue.length() == 0)
>                 return null;
> 
> But I wouldn't change this because it can be a hint that this item
> was forgotten to translate. I would prefer an extra attribute for
> real empty items.

yep I agree here also, the same way gettext and other translation tools work,
if no translation is present, original text is printed out, possibly with some
notice like "TRANSLATE: " prepended..

> 
> Michael
> 

martin
-- 
2CC0 4AF6 92DA 5CBF 5F09  7BCB 6202 7024 6E06 0223
http://mman.dyndns.org/mman.gpg

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [RTl] i18n transformer

Posted by Enke Michael <Mi...@wincor-nixdorf.com>.
"Piroumian, Konstantin" wrote:
> ...
> >
> > 1) I'd like to have in the catalogue an attribute called "alias", e.g.
> >    <message key="abc">ABC</message>
> >    <message key="xyz" alias="abc"/>
> >    If called <i18n:text>xyz</i18n:text> it will be transformed to "ABC".
> 
> Where this can be used?


I generate tables from DB. And the column description comes from the
DB-column name. Some tables have different column names for the same
real expression. And why we should have the same translation
more than one time?

 
> >
> > 2) It would be nice to have an "adding feature", e.g.
> >    <message key="hello">Hello</message>
> >    <message key="world">World</message>
> >    <message key="hi all" result="'hello' 'world'"/>
> >    So "<i18n:text>hi all</i18n:text>" will result in "Hello World".
> 
> You can use:
> <i18n:translate>
>     <i18n:text>{0} {1}</i18n:text>
>     <i18n:param>hi</i18n:param>
>     <i18n:param>all</i18n:param>
> </i18n:translate>
> 
> I think, that this is the task of the transformer to perform such operations
> and not the dictionary's.


I have for column description very often the same words. E.g.:
employee
employee number
employee group
employee name
employee address
If somebody has the task to generate translations for other languages
it would be very useful to only translate a word one time.


> >
> > 3) It would be good to have an "empty" translation.
> >    Actually if we define <message key="rst"></message> this will result
> > in
> >    "untranslated text" or whatever is configured. Even if we put space
> >    between the tags the behaviour is like that.
> 
> Hm... It's not correct. If there is a key in the dictionary then the result
> must be whatever is its value.

It is not so. Look at line 352 in XMLResourceBundle.java:
            itemValue = itemValue.trim();
            if(itemValue.length() == 0)
                return null;

But I wouldn't change this because it can be a hint that this item
was forgotten to translate. I would prefer an extra attribute for
real empty items.


> Btw, have seen the recent changes in Avalon's i18n support?

No, I will have a look.

Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [RTl] i18n transformer

Posted by "Piroumian, Konstantin" <KP...@flagship.ru>.
Hi!

> Peter Royal wrote:
> > ...
> > I agree that this is definitely the way to go. I'm offering up the work
> > I've done thus far as another, somewhat orthogonal change, to what
you've
> > proposed. Since we were talking about the I18nTransformer, I figured I'd
> > pipe up :)
> > ...
>
> Hi,
> as i follow this discussion and from experience of using the
> I18nTransformer
> I have some functional points it should be easy (for you? ;-) to add.
> I would make it self but I don't want to interfere with your plans.
>
> 1) I'd like to have in the catalogue an attribute called "alias", e.g.
>    <message key="abc">ABC</message>
>    <message key="xyz" alias="abc"/>
>    If called <i18n:text>xyz</i18n:text> it will be transformed to "ABC".

Where this can be used?

>
> 2) It would be nice to have an "adding feature", e.g.
>    <message key="hello">Hello</message>
>    <message key="world">World</message>
>    <message key="hi all" result="'hello' 'world'"/>
>    So "<i18n:text>hi all</i18n:text>" will result in "Hello World".

You can use:
<i18n:translate>
    <i18n:text>{0} {1}</i18n:text>
    <i18n:param>hi</i18n:param>
    <i18n:param>all</i18n:param>
</i18n:translate>

I think, that this is the task of the transformer to perform such operations
and not the dictionary's.

>
> 3) It would be good to have an "empty" translation.
>    Actually if we define <message key="rst"></message> this will result
> in
>    "untranslated text" or whatever is configured. Even if we put space
>    between the tags the behaviour is like that.

Hm... It's not correct. If there is a key in the dictionary then the result
must be whatever is its value.

Btw, have seen the recent changes in Avalon's i18n support?

Regards,
    Konstantin

>    We should define an attribute like 'empty="true"'
>    e.g. <message key="rst" empty="true"/> - this sould result in no
> output.
>
> Regards,
> Michael
>


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [RTl] i18n transformer

Posted by Enke Michael <Mi...@wincor-nixdorf.com>.
Peter Royal wrote:
> ...
> I agree that this is definitely the way to go. I'm offering up the work
> I've done thus far as another, somewhat orthogonal change, to what you've
> proposed. Since we were talking about the I18nTransformer, I figured I'd
> pipe up :)
> ...

Hi,
as i follow this discussion and from experience of using the
I18nTransformer
I have some functional points it should be easy (for you? ;-) to add.
I would make it self but I don't want to interfere with your plans.

1) I'd like to have in the catalogue an attribute called "alias", e.g.
   <message key="abc">ABC</message>
   <message key="xyz" alias="abc"/>
   If called <i18n:text>xyz</i18n:text> it will be transformed to "ABC".

2) It would be nice to have an "adding feature", e.g.
   <message key="hello">Hello</message>
   <message key="world">World</message>
   <message key="hi all" result="'hello' 'world'"/>
   So "<i18n:text>hi all</i18n:text>" will result in "Hello World".

3) It would be good to have an "empty" translation.
   Actually if we define <message key="rst"></message> this will result
in
   "untranslated text" or whatever is configured. Even if we put space
   between the tags the behaviour is like that.
   We should define an attribute like 'empty="true"'
   e.g. <message key="rst" empty="true"/> - this sould result in no
output.

Regards,
Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


RE: [RTl] i18n transformer

Posted by Peter Royal <pr...@managingpartners.com>.
>Hm.. on the first glance this looks more like a DictionarySelector/Factory 
>to me.
>(Did I get this wrong?) But there is already a XMLResourceBundleFactory
>used in the current i18n transformer implementation.

Yes, but the current I18nTransformer creates a private instance of the 
XMLResourceBundleFactory. Since I18nTransformers are pooled, you get 
multiple copies of the XMLResoruceBundle's in memory.

I created a wrapper around the XMLResourceBundleFactory so that when it is 
configured, it can use the Cocoon URLFactory to locate the catalogue 
directory. Since the XMLResourceBundleFactory was an Excalibur component, I 
didn't think it should be polluted with cocoon-specific code.

Also with the current I18nTransformer, each transformer instance is fixed 
to a specific catalogue.


>What I'd like to see is to decouple the i18n transformer from the
>XMLResourceBundle. I'd like to introduce an interface meaning "provides 
>i18n lookups".
>So the XMLResourceBundle would need to implement this interface (or better
>a delegation should do so). It should be quite easy to support other resources
>(like e.g. a SQL database) by creating some Components implementing this
>interface then.

I agree that this is definitely the way to go. I'm offering up the work 
I've done thus far as another, somewhat orthogonal change, to what you've 
proposed. Since we were talking about the I18nTransformer, I figured I'd 
pipe up :)
-pete

-- 
peter royal -> proyal@managingpartners.com
managing partners, inc. -> http://www.managingpartners.com


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


RE: [RTl] i18n transformer

Posted by Neeme Praks <ne...@one.ee>.
> -----Original Message-----
> From: Torsten Curdt [mailto:tcurdt@dff.st]
> Sent: Saturday, October 27, 2001 6:10 AM
> Subject: RE: [RTl] i18n transformer

[snip]

> Hm.. on the first glance this looks more like a
> DictionarySelector/Factory to me.
> (Did I get this wrong?) But there is already a XMLResourceBundleFactory
> used in the current i18n transformer implementation.

Seems to me also that it duplicates XMLResourceBundleFactory...

> What I'd like to see is to decouple the i18n transformer from the
> XMLResourceBundle. I'd like to introduce an interface meaning
> "provides i18n lookups".
> So the XMLResourceBundle would need to implement this interface (or better
> a delegation should do so). It should be quite easy to support
> other resources
> (like e.g. a SQL database) by creating some Components implementing this
> interface then.

Actually I also have some pending commits to i18n stuff in Avalon
(XMLResourceBundle*) that would address some of your concerns. Especially I
would like to add an interface/abstract class that would make the i18n
services more pluggable and extendable and less XMLResourceBundle dependent.

Also... XMLResouceBundle right now extends java.util.ResourceBundle and I
find that quite limiting (it has some final methods that cannot be
overridden, etc). I would like to remove that dependancy and instead make
XMLResourceBundle extend/implement an Avalon interface that I already
mentioned above (org.apache.avalon.i18n.ResourceBundle?)...

For some more ideas about stuff on my TODO list, see also the posting in
Avalon list:
http://marc.theaimsgroup.com/?l=avalon-dev&m=100181440612979&w=2

Neeme


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


RE: [RTl] i18n transformer

Posted by Torsten Curdt <tc...@dff.st>.
> At 02:39 PM 10/25/2001 +0200, you wrote:
> >  b)Maybe a bit nicer sollution could be to have an
> >
> >     interface I18nDictonary {
> >        public String lookup( String key );
> >        public long getLastModified();
> >     }
> >
> >    A helper class could delegate the lookup to the original
> >    XMLResourceBundle. If the getLastModified() is available
> >    making the I18nTransformer cacheable should be really easy,
> >    too. Cacheability would only depend on the features of
> >    the dictonary then.
> 
> I've already implemented something like that locally here, I just haven't 
> had a chance to port it back to the C2 tree and send a patch. Looks like 
> its needed tho :)
> 
> What I did:
> 
> I made an I18nResourceFactory component that returns XMLResourceBundles's :
> 
> XMLResourceBundle select(String name, Locale locale) throws ComponentException;

Hm.. on the first glance this looks more like a DictionarySelector/Factory to me.
(Did I get this wrong?) But there is already a XMLResourceBundleFactory
used in the current i18n transformer implementation.

What I'd like to see is to decouple the i18n transformer from the
XMLResourceBundle. I'd like to introduce an interface meaning "provides i18n lookups".
So the XMLResourceBundle would need to implement this interface (or better
a delegation should do so). It should be quite easy to support other resources
(like e.g. a SQL database) by creating some Components implementing this
interface then.
--
Torsten


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: [RTl] i18n transformer

Posted by Peter Royal <pr...@managingpartners.com>.
At 02:39 PM 10/25/2001 +0200, you wrote:
>  b)Maybe a bit nicer sollution could be to have an
>
>     interface I18nDictonary {
>        public String lookup( String key );
>        public long getLastModified();
>     }
>
>    A helper class could delegate the lookup to the original
>    XMLResourceBundle. If the getLastModified() is available
>    making the I18nTransformer cacheable should be really easy,
>    too. Cacheability would only depend on the features of
>    the dictonary then.

I've already implemented something like that locally here, I just haven't 
had a chance to port it back to the C2 tree and send a patch. Looks like 
its needed tho :)

What I did:

I made an I18nResourceFactory component that returns XMLResourceBundles's :

XMLResourceBundle select(String name, Locale locale) throws ComponentException;

That component can be configured in cocoon.xconf with 2 parameters:
         catalogue-location - the base directory to search for catalogues
         cache-at-startup - same as XmlResourceBundle option

The I18nTransformer then uses the I18nResourceFactory to load its 
XMLResouceBundles, thus having a single instance of each XMLResourceBundle 
in memory.

I also gave the transformer some new options:
         untranslated-text - set the text to insert if no translation is 
found and no default. Can be an expression such as "[ut: $key]" where $key 
was the attempted lookup key.
         catalogue - this specifies which catalogue to request from the 
I18nResourceFactory
         ignore-no-catalogue - If the specified catalog cannot be found, 
supress the error.

This is all against the 2.0 branch, as that is what we've been tracking 
here. If interest is high I'll make a patch quicker :)
-pete


-- 
peter royal -> proyal@managingpartners.com
managing partners, inc. -> http://www.managingpartners.com


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org