现在的位置: 首页 > 综合 > 正文

Configuring Poedit for Zend Framework Projects

2013年11月10日 ⁄ 综合 ⁄ 共 2741字 ⁄ 字号 评论关闭

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.

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

.

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.

.

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

.

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;

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.

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 sv_SE.mo 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!

抱歉!评论已关闭.