Configuring Poedit for Zend Framework Projects

This entry is part 1 of 4 in the series Work­ing with Zend_Translate and Poedit

There are a few steps you need to take to con­fig­ure poedit to work with a Zend Frame­work project prop­erly. I will take you through the con­fig­u­ra­tion process step by step, and in the end you should have a work­ing installation.

In this tuto­r­ial we are on Win­dows, but the process is the same on Mac & Linux based sys­tems, and poedit even looks much the same on all platforms.

Install poedit and start it, if it’s the first time you run it you should now see a Pref­er­ences dialog.

Your name & email — Fill these in
You can leave all the options as their defaults, includ­ing the Line end­ings for­mat [Unix]
Trans­la­tion Memory:
Leave this as is for now.
Select PHP and click Edit.

PHP Language settings

Make sure your dia­log matches the one above exactly!

Now click OK twice and you are done with the preferences.

The main poedit win­dow will now come up,  click File -> New Cat­a­log, you should now see a set­tings window.

Project Info:

Fill in your Project name and ver­sion and the rest of the fields mak­ing sure you select Charset and Source code charset to UTF8 and select­ing the lan­guage and coun­try of the trans­la­tion you are going to cre­ate, in my case Lan­guage: Swedish and Coun­try: SWEDEN.

Project Info

Now select the Paths tab, and add your projects base path. In my case C:\Zend\Apache2\htdocs\testbench then click the New item tool and add; appli­ca­tion

Project Base and application path

Now select the Key­words tab and click the New item tool and add;

  • trans­late
  • _
  • set­La­bel
  • set­Value
  • setMes­sage
  • setLe­gend
  • _refresh
  • append
  • prepend

(Note: If you have any other key­words that come to mind, feel free to com­ment and I’ll add them to this tutorial)

Now you click OK and the Save as dia­log comes up move to your project appli­ca­tion direc­tory and select or cre­ate the lan­guages direc­tory the path should look some­thing like C:\Zend\Apache2\htdocs\testbench\application\languages and save the file as sv_SE.po (replace this with the language/locale code that you have choosen.)

Now your source code will be scanned after the key­words you spec­i­fied ear­lier and the Update Sum­mary dia­log will be show­ing all the strings it detected;

Update Summary

In this exam­ple the strings where caught from;

$this->headTitle()->prepend($this->translate('TestBench Application -'));
<?php echo $this->translate("Welcome %s, your last login was %s",$this->user['name'],$this->user['active']); ?>

in my layouts/scripts/layout.phtml file.

When you click OK on the Update Sum­mary Dia­log you will be taken to the main poedit win­dow where you can trans­late the strings.

Main window

As you can see it’s very easy to work with sim­ply enter your trans­la­tions in the bot­tom text box.

Now after you are done you sim­ply click File -> Save and two files will be writ­ten to your lan­guages direc­tory, in my case sv_SE.po and where the .mo file is the com­piled ver­sion that Zend_Translate uses.

Now if you add new strings to your source code you sim­ply load poedit and open your sv_SE.po file and select Cat­a­log -> Update from sources and it will again show you the Update Sum­mary dia­log with all new string as well as changed strings and removed (Obso­lete) strings.

There are a ton of good Zend_Translate ref­er­ences out there, google is your friend!

Hope this helps, enjoy!

Series Nav­i­ga­tionBoot­strap Zend_Translate

Tags: , ,

26 Responses to "Configuring Poedit for Zend Framework Projects"

Leave a Comment


Get Adobe Flash player