Zend_Translate en & en_US

9 messages Options
Embed this post
Permalink
Simon Corless

Zend_Translate en & en_US

Reply Threaded More More options
Print post
Permalink
I am just starting with Zend_Translate, it works, I think I get the principle!

I am starting with something I thought would be easy... I'm struggling! I want to have a default English translation. In this case it's British English, however I want that as the base English. I assumed  en. I also want a US version, I assumed en_US.

How do I name my files correctly so this works, I am using gettext and poedit and I just can't seem to name the files in the right way. The manual implies this is possible...

$translate = new Zend_Translate('gettext', DOC_MODULES . 'admin/languages/', null, array('scan' => Zend_Translate::LOCALE_FILENAME));

$translate->setLocale('en');
// $translate->setLocale('en_US');

Files are currently names:
admin_en_GB OR admin_en
admin_en_us

Any pointers? I want the language to be specified rather than automatically guessed, but I can't get that working either. I'm 100% sure my translation files are overwriting each other but I don't know what to name them to make it work, unless it's not possible?

Also if I have a translation file per module and one for the application how do I merge them? Does this cause things to slow down?

Thanks for any pointers.

Simon
Thomas Weidner

Re: Zend_Translate en & en_US

Reply Threaded More More options
Print post
Permalink
Hy Simon,

> I am just starting with Zend_Translate, it works, I think I get the
> principle!
>
> I am starting with something I thought would be easy... I'm struggling! I
> want to have a default English translation. In this case it's British
> English, however I want that as the base English. I assumed  en. I also
> want
> a US version, I assumed en_US.
>
> How do I name my files correctly so this works, I am using gettext and
> poedit and I just can't seem to name the files in the right way. The
> manual
> implies this is possible...
>
> $translate = new Zend_Translate('gettext', DOC_MODULES .
> 'admin/languages/',
> null, array('scan' => Zend_Translate::LOCALE_FILENAME));
>
> $translate->setLocale('en');
> // $translate->setLocale('en_US');
>
> Files are currently names:
> admin_en_GB OR admin_en
> admin_en_us
>
> Any pointers? I want the language to be specified rather than
> automatically
> guessed, but I can't get that working either. I'm 100% sure my translation
> files are overwriting each other but I don't know what to name them to
> make
> it work, unless it's not possible?

Question:
You define a file language english with region brittish. (name it "en" to be
default for all english dialects).
Then you define a file language english with a unknown language which could
be interpreted as usbekistan. Wouldn't it be better to define a file english
with region united states ?

> Also if I have a translation file per module and one for the application
> how
> do I merge them? Does this cause things to slow down?

Why merge them manually ?
You already said with the scan option that Zend_Translate should do this for
you.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com 

Simon Corless

Re: Zend_Translate en & en_US

Reply Threaded More More options
Print post
Permalink
thomasW wrote:
Question:
You define a file language english with region brittish. (name it "en" to be
default for all english dialects).
Then you define a file language english with a unknown language which could
be interpreted as usbekistan. Wouldn't it be better to define a file english
with region united states ?
Hi Thomas thanks...

Yes it would but this is where I am struggling, I don't see how to do it!

If I create two files, file_en_GB and file_en_US - Is that right for a US region and GB region? Or are you saying have one file file_en and one file_en_us? - One always just seems to override the other.

I can't seem to force one or the other to display. Do I set the language and country in poedit or are these ignored in gettext, the ZF manual makes mention of them being set in a different format but not gettext.

Ideally I'd like my strings to be key id's rather than the full string therefore having an English and US translation. i.e. $translate->translate('admin_welcome'); - Which is working I am just letting you know how I'm using it for the sake of completeness.

I am thinking it's simple I'm just not getting there!

Thank You

Simon
Thomas Weidner

Re: Zend_Translate en & en_US

Reply Threaded More More options
Print post
Permalink
>> Question:
>> You define a file language english with region brittish. (name it "en" to
>> be
>> default for all english dialects).
>> Then you define a file language english with a unknown language which
>> could
>> be interpreted as usbekistan. Wouldn't it be better to define a file
>> english
>> with region united states ?
>>
> Hi Thomas thanks...
>
> Yes it would but this is where I am struggling, I don't see how to do it!
>
> If I create two files, file_en_GB and file_en_US - Is that right for a US
> region and GB region? Or are you saying have one file file_en and one
> file_en_us? - One always just seems to override the other.

Think of it...

en_us   -> english or usbekistan language ? unexpected behaviour as two
languages are included

versus

en_US -> english with region US.

> I can't seem to force one or the other to display. Do I set the language
> and
> country in poedit or are these ignored in gettext, the ZF manual makes
> mention of them being set in a different format but not gettext.
>
> Ideally I'd like my strings to be key id's rather than the full string
> therefore having an English and US translation. i.e.
> $translate->translate('admin_welcome'); - Which is working I am just
> letting
> you know how I'm using it for the sake of completeness.
>
> I am thinking it's simple I'm just not getting there!

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com 

Simon Corless

Re: Zend_Translate en & en_US

Reply Threaded More More options
Print post
Permalink

thomasW wrote:
Think of it...

en_us   -> english or usbekistan language ? unexpected behaviour as two
languages are included

versus

en_US -> english with region US.
Ok that makes sense but how do I utilise it? This is driving me nuts I must have something wrong it seems so simple!

How would you setup one string to translate and with what files for GB and US? How would you name them?

$translate = new Zend_Translate(
'gettext',
DOC_MODULES . 'admin/languages/',
null,
array('scan' => Zend_Translate::LOCALE_FILENAME)
);
$translate->setLocale('en_US');
print $translate->_("home_intro") . "\n";

If I set the locale to en_US or en_GB I want to see the changes!

home_intro is simply = Hello Friend, or Hello Buddy, I don't think you can get much simpler! It only ever picks up the en_GB file. Therefore I don't think I can be naming my files correctly or understanding what you are trying to tell me above!

Simon

Thomas Weidner

Re: Zend_Translate en & en_US

Reply Threaded More More options
Print post
Permalink

----- Original Message -----
From: "Simon Corless" <[hidden email]>
To: <[hidden email]>
Sent: Monday, June 08, 2009 3:35 PM
Subject: Re: [fw-i18n] Zend_Translate en & en_US


>
>
>
> thomasW wrote:
>>
>> Think of it...
>>
>> en_us   -> english or usbekistan language ? unexpected behaviour as two
>> languages are included
>>
>> versus
>>
>> en_US -> english with region US.
>>
>
> Ok that makes sense but how do I utilise it? This is driving me nuts I
> must
> have something wrong it seems so simple!
>
> How would you setup one string to translate and with what files for GB and
> US? How would you name them?
>
> $translate = new Zend_Translate(
> 'gettext',
> DOC_MODULES . 'admin/languages/',
> null,
> array('scan' => Zend_Translate::LOCALE_FILENAME)
> );
> $translate->setLocale('en_US');
> print $translate->_("home_intro") . "\n";
>
> If I set the locale to en_US or en_GB I want to see the changes!
>
> home_intro is simply = Hello Friend, or Hello Buddy, I don't think you can
> get much simpler! It only ever picks up the en_GB file. Therefore I don't
> think I can be naming my files correctly or understanding what you are
> trying to tell me above!

Please read the manual.
I can't teach you how translation works when you don't even know the
simplest things.

As I said... en_us is not en_US... according to the manual regions are
uppercased. Otherwise there would be no way to detect if you want to have
the language en or the language us as you use the same seperator for all
tokens.

Simply said... rename your files as mentioned in the last mail. When you
think that this will not do it, then translation will not work for you. :-)
Of course you can also add all needed files manually and set the locale to
use also manually. But this would negotate the advantage of directory
scanning.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com 

Simon Corless

Re: Zend_Translate en & en_US

Reply Threaded More More options
Print post
Permalink
thomasW wrote:
Please read the manual.
I can't teach you how translation works when you don't even know the
simplest things.

As I said... en_us is not en_US... according to the manual regions are
uppercased. Otherwise there would be no way to detect if you want to have
the language en or the language us as you use the same seperator for all
tokens.
Thank you for your 'kind' words! I have read the manual back to front, it really isn't the clearest thing when coming to translation from scratch. It never once clearly states how to name your files. The  chapter "56.3.9.2.3. Filename tokens" needs a simple statement "name your files name-en_US.mo" or equivalent. Everything works perfectly if I preface the locale with a - instead of an _ but this wasn't clear from the documentation or from the messages above.

The examples shown are only now clear once I know what I'm looking for! Where does it state when discussing directory scanning that regions are upper-cased? I will post some suggestions for the manual to he Issue Tracker.

Still it's working now and I appreciate the pointers. :)

Simon
Thomas Weidner

Re: Zend_Translate en & en_US

Reply Threaded More More options
Print post
Permalink
>> Please read the manual.
>> I can't teach you how translation works when you don't even know the
>> simplest things.
>>
>> As I said... en_us is not en_US... according to the manual regions are
>> uppercased. Otherwise there would be no way to detect if you want to have
>> the language en or the language us as you use the same seperator for all
>> tokens.
>>
>
> Thank you for your 'kind' words! I have read the manual back to front, it
> really isn't the clearest thing when coming to translation from scratch.
> It
> never once clearly states how to name your files. The  chapter
> "56.3.9.2.3.
> Filename tokens" needs a simple statement "name your files name-en_US.mo"
> or
> equivalent. Everything works perfectly if I preface the locale with a -
> instead of an _ but this wasn't clear from the documentation or from the
> messages above.

How locales are named can be read in the documentation of Zend_Locale:
Chapter 31.1.3: How are locales represented:
http://framework.zend.com/manual/en/zend.locale.html#zend.locale.representation

How the detection of filenames is proceeded is described in Zend_Translate:
Chapter: 56.3.9.2.3: Filename tokens
http://framework.zend.com/manual/en/zend.translate.using.html#zend.translate.using.detection.filename.token

"The first found string delimited by a token which can be interpreted as a
locale will be used."
and
"When the filename contains multiple tokens, the first found token depends
on the order of the tokens which are used."

All paragraphs even contain examples to see how filenames should be written.
I would not know how to write it better than using some examples.

As you used the same token, as already described, the detection did not work
like expected by you.

name_en_us... detects only name, en, us
name-en_us... detects name, en_us, name-en, en_us
name_en-us... detects name, en-us, name_en, en-us
but
en_US would work

> The examples shown are only now clear once I know what I'm looking for!
> Where does it state when discussing directory scanning that regions are
> upper-cased?

Within Zend_Locale. As you said that your filenames are named like locales
we expect that you also know how locales are noted. ;-)

I don't think that they even need to be uppercased when you are using the
tokens as described.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com 

Simon Corless

Re: Zend_Translate en & en_US

Reply Threaded More More options
Print post
Permalink
This is the problem, I appreciate and fully understand what you say now but you are looking at the manual from the perspective of someone who is fluent in everything these components do. If you come to it fresh and read through it, it is very difficult to piece the bits together and actually get a working example.

All the examples start assuming you know what you are doing and don't generally combine everything necessary to get it to work. It's the same throughout the manual not just with translation. I would suggest that every component should have a quick start guide, I realise this is probably impractical though!

Each part of the manual needs to be looked at as if coming new to the framework, again it's only after you know the little bits you're looking for that it makes perfect sense.

Why should I have to read the Locale Manual when using translation, yes they are related but not necessarily coupled. As the constructor of translate allows the setting of a locale by string it could easily be bypassed. I have myself read it and am using locale to great results. I don't think the locale conventions are totally relevant to the style of file naming.

Had you mentioned in your second email that I should look at my token usage before the locale I would of fixed my problems and fully understood. Ultimately my problem was not with the en_US element of the name. Especially as you then mention "I don't think that they even need to be uppercased when you are using the tokens as described." Your example here is far more useful than that in the public docs.

Anyway in conclusion I believe all elements of the manual should be looked at as if coming to the framework from new. Or at least add each component to an element of the current, or a new quick start guide.

Anyway my comments are not meant to be personal they are my thoughts on the usefulness of the manual and the learning curve. Agreed that the framework is extremely easy to use once you get past the initial hurdles of the manual!

If I can help in this I will, please let me know and again thank you for your help.

Simon