Wednesday
3
November
2010

How to install GIT under Windows for ZF

Hy interested ones,

actually I was changing my complete development environment to a new computer and switched from SVN to GIT.
Well… never change a running system.

I was very unhappy of GIT integration under Windows. Also the actual documentation is not really understandable.
So I thought that I write you a HowTo for ZF under Windows.

You are using Windows?
You want to contribute to ZF?

If the above assumtion fits to you, you should read further.

1.) Install GIT locally
Download “msysgit” (I used the latest full installer) and install it. You can find it under [http]http://code.google.com/p/msysgit/[\http].

At installation use the second option when you are asked for the command line option.

2.) Install TORTOISEGIT
You can find it under [http]http://code.google.com/p/tortoisegit/[\http].

3.) Create an account at GITHUB... [http://github.com[\http].
It should use the email you are also using for your contributions (which you have told Zend for your CLA)

4.) Create an SSH key to use for contribution…
Open GitBash (which was installed with GIT).

ssh-keygen -t rsa -C "youname@mail.com"

But change “yourname@mail.com” with the email address you have told when you requested your CLA at Zend.
Press “Enter”
Now give a passphrase… but you should remember it. Otherwise you would have to recreate your SSH key from time to time.

5.) Copy your public key into the pastebin
Within Step 4 you will see the exact path and file where your SSH key is stored.

6.) Add the public key to your Github account
Open your GitHub account and go to “Account Settings” and within there to “SSH Public keys”.
Press the “Add another public key” button”.
Leave the title blank and paste your key file into the key textfield.
Press “Add key”.

Now you’ve added a key to your github account and should be able to commit to your github account.

7.) Fork ZF with your own Github repository
Go to the ZF projects page within github… [http]http://github.com/zendframework/zf2[\http]
Press the “Fork” Button (you can find it in the upper right side).

8.) Configure TortoiseGIT
Open it by right clicking within your explorer
Go to “TortoiseGit” -> “Git” -> “Config”
“Name” should be your Git username
“Email” should be the email you registered within Github and which should also be equal to your CLA email.

9.) Add remote connections
Go to “Git” -> “Remote”
Add a new connection
“Remote” should be “origin”
“URL” should be “git@github.com:/zf2.git” where username is again your github username

Add a second remote conection
“Remote” should be “zf2”
“URL” should be “git://github.com/zendframework/zf2.git”

10.) Clone your fork locally
Open your Explorer
Go to the directory under which you want to have your repository.
-> Right click
-> GitClone
-> URL = “git@github.com:/zf2.git”
should be your git username
-> Repository = The new directory where you want to have your repository locally
Click OK

Now you’re ready to go…
But before working on an issue you should update your repository… do the following:
Update your local repository by
-> Right click on it within your explorer
-> Git-Sync
-> Local branch = “master”
-> Remote branch = “remote/zf2/master”… click on the “…” button and select the base ZF2 repository and the master branch
-> Pull … click the Pull button

All you need now is the “Git-Sync” command.
It enables you to create a new branch locally, on github, delete it locally or remote, pull, push and so on.

And now go and help on ZF :-)

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top
Friday
30
July
2010

How to add missing translations

Hy interested ones.

Today I want to get you informed about translation logging.

A site is always a living place. Existing content is changed, new content is available.

But when you have a multilingual site then this can create problems. You have to keep the translations up to date, otherwise your visitors will not see what you want them to see. So how can this be archived?

Zend_Translate contains all to handle this situation. First let’s create the wished translation adapter.

$translate = new Zend_Translate(array(
    'adapter' => Zend_Translate::AN_CSV,
    'content' => 'C:\www\translations\',
    'locale'    => 'en',
    'scan'      => Zend_Translate::LOCALE_DIRECTORY,
));

Our translation file for en should contain the following content:

Untranslated message;Untranslated message (EN)

Translation itself works from this point on.

Next we need to keep aware of untranslated messages. This is done by using a log. So let’s create a log to write to.

$writer = new Zend_Log_Writer_Stream('C:\www\translations\untranslated.txt');
$logger = new Zend_Log($writer);

Now let’s attach the log to the translation adapter.

$translate->setOptions(array(
    'log'   => $logger;
));

All messages which are untranslated will now be written into the file untranslated.txt as soon as the translation should occur. Of course this is only the simplest example. You can do much more things.

When someone wants to get a translation for our message in a language which is not translated you will have a new entry within the log file. Let’s expect someone wants to have a translation for german. He will get Untranslated message in return, which is the source message… this is correct behaviour from the users point of view. But our log file will now look like this:

2010-07-30T12:10:18+02:00 NOTICE (5): Untranslated message within 'de': Untranslated message

The message looks confusing? Then let’s change the output for our log:

$translate->setOptions(array(
    'logMessage'   => '%locale%;%message%';
));

Now our log will like like this:

2010-07-30T12:10:18+02:00 NOTICE (5): de;Untranslated message

Ok… but this is still no proper csv file. We want to have locale and message, and nothing more. Well, then let’s change the log formatter. Because timestamp and severity are created by Zend_Log. To change this you need to attach a formatter to your log.

$formatter = new Zend_Log_Formatter_Simple('%message%' . PHP_EOL);
$writer = new Zend_Log_Writer_Stream('C:\www\translations\untranslated.txt');
$writer->setFormatter($formatter);
 
$logger = new Zend_Log($writer);

Ok… that’s it. Now your log will look like this:

de;Untranslated message

Our full example looks like this:

$formatter = new Zend_Log_Formatter_Simple('%message%' . PHP_EOL);
$writer = new Zend_Log_Writer_Stream('C:\www\translations\untranslated.txt');
$writer->setFormatter($formatter);
	
$logger = new Zend_Log($writer);
	
$translate = new Zend_Translate(array(
    'adapter' => Zend_Translate::AN_CSV,
    'content' => 'C:\www\translations\',
    'locale'    => 'en',
    'log'   => $logger,
    'logMessage'   => '%locale%;%message%',
    'scan'      => Zend_Translate::LOCALE_DIRECTORY,
));

Zend_Log can also be used to add those “log” messages into a database. There is just one thing which can not be done this way.

It is not possible to recognise if a message has already been written or not. This means in the worst case that many messages will be duplicated into our log. On the other hand can you see which translations are requested many times and should be translated sooner than others. Anyhow… the above described features can be very usefull when your site is bigger or contains more than one translation file.

Have a nice frameworking

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top
Sunday
16
May
2010

Routing translations

Hy fellows,

sometimes a message can not be translated. In this case the original message id will be returned.
But it could be useful to return the translation for another language instead of the message id.

This is called “translation routing” and supported with the next minor release.

Let’s see an example:

$translate = new Zend_Translate(array(
    'adapter' => Zend_Translate::AN_ARRAY,
    'content' => $mytranslations,
    'route' => array('de' => 'en')
));

Now we have a message id of “HEAD”… a user requesting german would expect to get “Meine Überschrift”.
But when there is no translation for this message id he would see “HEAD”.

With the set routing Zend_Translate will internally change the language to the new route and try to translate the message id with the other language.
So he would get “My Header” instead “HEAD”.

This feature seems to solve all problems for those who have no complete translations. But there are also some negs which should be thought of:
1.) You can not route a language to two others.
2.) When Zend_Translate is routing you will still get an “untranslated notice” for every message id and language which can not be translated
3.) When you route users to a language which they don’t understand you are irritating them

You can also build a translation chain by routing from several languages in a sort of priority:
Let’s see an example:

$translate = new Zend_Translate(array(
    'adapter' => Zend_Translate::AN_ARRAY,
    'content' => $mytranslations,
    'route' => array('de' => 'en', 'en' => 'fr')
));

This creates the following chain:

GERMAN => ENGLISH => FRENCH

So german could return english when there is no translation. And when there is no translation for english it would even return french.

Now you could say: Let’s break translation and add a circle routing, something like this:

$translate = new Zend_Translate(array(
    'adapter' => Zend_Translate::AN_ARRAY,
    'content' => $mytranslations,
    'route' => array('de' => 'en', 'en' => 'de')
));
GERMAN => ENGLISH => GERMAN

What now happens is that german returns english, and english returns german when there is no translation. But when there is no english translation it does not try to return german again, instead it returns the message id itself.

So you will always have a translation.

Further informations can be retrieved within the official mailing lists and within IRC.
I hope you find this feature useful. More to come soon…

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top