Zend Framework Documentation Now Version Specific

This is VERY good news!!!

The Zend Framework has updated their documentation site with a very handy feature for those that may not be working with the latest version of the framework – the ability to select a version of the framework to view the documentation for.

As of the time of this post, they have versions 1.10 back through the original 1.0 of the documentation as well as having them in six different languages. The site’s search can also be limited to a certain version as well, making it super simple to find just what you’re looking for.

Check out their updated documentation site to see these new features in action.

via Community News.

Translate Toolkit & Pootle

This entry is part 1 of 1 in the series Translation Tools

I’ve got a whole lot of questions about what tools other than poedit that exists especially for teams, so I’ll start going through and try to review tools available and add them to the new Translation Tools article series.

I hope you’ll find this useful.

The Translate project provides tools to make it easier for you to localize. Tools that work with standards based file formats like PO and XLIFF because you deserve the best. Our goal is to make your life as a localizer easier, help you work faster and keep your work at a high quality.

Virtaal – Standalone CAT Tool

Demonstration of new features in the latest Virtaal release. Virtaal is an open source computer aided translation and localisation tool. You can read more about it at Virtaal. Virtaal aims to be simple to use for first time localisers yet powerful for experienced localisers. Features include translation memory from many sources, sophisticated searching, a simple and powerful navigation interface and more. The developers are aiming to include terminology support in the next release and make it easier to configure the translation memory and terminology plugins.

Pootle web-based translation tool

If you require team based the Pootle web-based translation tool and translation management solution might be what you want.

Check out:  Translate Toolkit & Pootle website.

Zend_Image_Deepzoom by Nicolas Fabre

Nicolas Fabre asks for help in reviewing his new component proposal:

Deep Zoom is an implementation of the Seadragon technology for use in Microsoft Silverlight or Seadragon viewing library. It allows users to pan around and zoom in a large, high resolution image or a large collection of images. It reduces the time required for initial load by downloading only the region being viewed and/or only at the resolution it is displayed at. Subsequent regions are downloaded as the user pans to (or zooms into them); animations are used to hide any jerkiness in the transition.

read more Zend_Image_Deepzoom – Nicolas Fabre – Zend Framework Wiki.

Test Results on Memory Usage of Zend Framework and Doctrine with APC

A few interesting observations made by rvdavid; After investigating a recommendation to use Doctrine by a fellow blogger, Brian at Real of Zod, I have decided to run with Doctrine as my Domain Model in Zend Framework projects. The thing is, if I’m going to commit to this, I need to know that applications I build in the future with the Zend Framework while using Doctrine as an integral part of the Model layer will not take performance hits from things like memory usage.

With Doctrine doing a _lot_ of magic, I thought that this would be something that I wanted to see for myself.

4MB Memory to execute a simple Query?!?! Ffffff#$#!!!!

A quick google search took me to a Question posted on StackOverflow about Doctrine Memory Usage. The concerned OP was asking if he had a server misconfiguration or if this was normal for Doctrine to be using so much memory for a simple query. He posted a 4MB difference in Peak Memory Usage between the start of the request before the Doctrine Query was executed and after the Doctrine Query was executed. After reading that, I was a little nervous.

Use Opcode Caching to reduce Memory Usage.

via » rvdavid: A Web Developer’s Blog.

10 X Zend Amf Performance enhancements — please test!

Wade Arnold comes with some very good news for us that use Zend_Amf, he writes; Mark Reidenbach from everytruckjob.com has submitted a awesome patch for Zend Amf that creates a huge performance increase. Thanks so much Mark! I have also added a reference check optimization that uses SPL_object_hash to quickly see if an object has been seen before or not. Overall you should see a big performance increase. The test case I used was the James Ward’s census data from my ZendCon talk which consists of random people objects ranging from 1 – 100 duplicates totaling 5k total rows.  Xdebug profiling analyzed by  KCacheGrind showed roughly a 10X increase in performance!

The question is did all of these changes introduce any bugs? I have not been able to find anything and all of the tests pass. However with such a major change I would really appreciate you downloading the attached file and overwriting Zend/Amf/* with it’s contents. Please report any issues in the comments here or better yet on the actual bug ZF-7493 If all goes well we will try and get this into the 1.10 release.

via 10X Zend Amf Performance enhancements — please test! | Wade Arnold.

Bootstrapping Zend_Translate with a LangSelector Plugin

This entry is part 4 of 4 in the series Working with Zend_Translate and Poedit

As an update to the method of having everything related to Zend_Translate and Zend_Locale in the Bootstrap, here is an alternative using an Controller Plugin that does the grunt work of validating, selecting and updating the Zend_Locale, Zend_Registry & Zend_Session using Zend_Session_Namespace. And we are using poedit .po & .mo files as the source as usual.

Please comment as usual if you have a neater way of doing it 🙂

Bootstrap.php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

protected function _initTranslate()
{
// Get current registry
$registry = Zend_Registry::getInstance();
/**
* Set application wide source Locale
* This is usually your source string language;
* i.e. $this->translate('Hi I am an English String');
*/
$locale = new Zend_Locale('en_US');

/**
* Set up and load the translations (all of them!)
* resources.translate.options.disableNotices = true
* resources.translate.options.logUntranslated = true
*/
$translate = new Zend_Translate('gettext',
APPLICATION_PATH . DIRECTORY_SEPARATOR .'languages', 'auto',
array(
'disableNotices' => true, // This is a very good idea!
'logUntranslated' => false, // Change this if you debug
)
);
/**
* Both of these registry keys are magical and makes
* ZF 1.7+ do automagical things.
*/
$registry->set('Zend_Locale', $locale);
$registry->set('Zend_Translate', $translate);
return $registry;
}
}

This little plugin will check every request for a lang paramenter and act on it.
It does not matter if you set the lang parameter using a custom route :lang/:controller/:action
or via a get/post ?lang= etc. one or all of them will work.

library/App/Controller/Plugin/LangSelector.php


* @name App_Controller_Plugin_LangSelector
* @filesource library/App/Controller/Plugin/LangSelector.php
* @tutorial Instantiate in application.ini with;
* resources.frontController.plugins.LangSelector =
* "App_Controller_Plugin_LangSelector"
* @desc Takes the lang parameneter when set either via a
* route or get/post and switches Locale, This depends
* on the main initTranslate function in Bootstrap.php
* to set the initial Zend_Translate object.
* Inspiration from ZendCasts LangSelector.
*/
class App_Controller_Plugin_LangSelector extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$registry = Zend_Registry::getInstance();
// Get our translate object from registry.
$translate = $registry->get('Zend_Translate');
$currLocale = $translate->getLocale();
// Create Session block and save the locale
$session = new Zend_Session_Namespace('session');

$lang = $request->getParam('lang','');
// Register all your "approved" locales below.
switch($lang) {
case "sv":
$langLocale = 'sv_SE'; break;
case "fr":
$langLocale = 'fr_FR'; break;
case "en":
$langLocale = 'en_US'; break;
default:
/**
* Get a previously set locale from session or set
* the current application wide locale (set in
* Bootstrap)if not.
*/
$langLocale = isset($session->lang) ? $session->lang : $currLocale;
}

$newLocale = new Zend_Locale();
$newLocale->setLocale($langLocale);
$registry->set('Zend_Locale', $newLocale);

$translate->setLocale($langLocale);
$session->lang = $langLocale;

// Save the modified translate back to registry
$registry->set('Zend_Translate', $translate);
}
}

Big thanks to Zend Cast for the inspiration!

How to make POEdit detect source strings in Zend Framework

This entry is part 3 of 4 in the series Working with Zend_Translate and Poedit

You will notice that once you have started translating an application using poedit it’s quite a smooth process, what hampers the experience a little bit is the mutitude of ways you can write code in Zend Framework, this is great in every way for developers, but requires a bit of thinking when you need to also translate all the UI strings.
So how do we make poedit detect the strings while making our code pretty?

(And guys PLEASE comment on this article with your own hints, tips & quirks!)

For example;
This is a simple login form using Zend_Form;
Zend_Form is completely Zend_Translate i18n compatable, and will read in all strings from your translation sources without the use of specific $this->translate() calls, which makes the code ALOT prettier, see below;


class Form_Login extends Zend_Form {
public function init() {
$this->setAttrib('id', 'LoginForm');
$this->addElement('text', 'username', array(
'label' => $this->getView()->translate('Username'),
'description' => $this->getView()->translate('Please enter valid username'),
));
$this->addElement('password', 'password', array(
'label' => $this->getView()->translate('Password'),
'description' => $this->getView()->translate('Please enter valid password'),
));
$this->addElement('submit', 'submit', array(
'label' => $this->getView()->translate('Login'),
));
}
}

Is the same thing as; but a LOT shorter and cleaner!

class Form_Login extends Zend_Form {
public function init() {
$this->setAttrib('id', 'LoginForm');
$this->addElement('text', 'username', array(
'label' => _('Username'),
'description' => _('Please enter valid username'),
));
$this->addElement('password', 'password', array(
'label' => _('Password'),
'description' => _('Please enter valid password'),
));
$this->addElement('submit', 'submit', array(
'label' => _('Login'),
));
}
}

Both are caught by the poedit keywords scanner that looks for translate() as well as the translate helper shotcode _().

Some notes (And I’ll keep this section updated while I find more tips & hints and quirks!)

But! It always seem to be a But in there;
These two are NOT the same!
translate("Welcome %s, your last login was %s",$this->user['name'],$this->user['active']); ?>
user['name'],$this->user['active']); ?>
The second one explodes with; “Warning: _() expects exactly 1 parameter, 3 given”

That tells us that;

or even (if you have short tag mode on;

should be ok to use. except that it’s not producing the translated output in an view.phtml or layout.phtml. so we are forced to use;
translate('Logout'); ?>

Proposal for Zend_Db_NestedSet – Hierarchical data as a nested set

Graham Anderson writes a very interesting proposal; If you are interested in an implementation of storing and retrieving hierarchical data as a nested set, please take a few minutes to review my new proposal[1].

I dusted off some old code and poked and prodded a little until it behaved somewhat as expected, there’s a functioning prototype on GitHub[2] with some basic instructions in the README.

As you probably guessed the algorithm is modified pre-order traversal, and the current working functionality is as follows

  • Store single trees or multiple trees in same table
  • Add, move & delete individual tree nodes or tree branches
  • operate on result set nodes(getPath(),getSiblings(),getDescendants(), etc )
  • Result-set as multi-dimensional associative array (Zend_Navigation)
  • Result-set as recursive iterator

Cheers the noo,
Graham

  1. http://framework.zend.com/wiki/display/ZFPROP/Zend_Db_NestedSet+-+Graham+Anderson
  2. http://github.com/gnanderson/ZF_NestedSet

Configuring Poedit for Zend Framework Projects

This entry is part 1 of 4 in the series Working with Zend_Translate and Poedit

There are a few steps you need to take to configure poedit to work with a Zend Framework project properly. I will take you through the configuration process step by step, and in the end you should have a working installation.

In this tutorial we are on Windows, but the process is the same on Mac & Linux based systems, 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 Preferences dialog.

Personalize:
Your name & email – Fill these in
Editor:
You can leave all the options as their defaults, including the Line endings format [Unix]
Translation Memory:
Leave this as is for now.
Parsers:
Select PHP and click Edit.

PHP Language settings

Make sure your dialog matches the one above exactly!

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

The main poedit window will now come up,  click File -> New Catalog, you should now see a settings window.

Project Info:

Fill in your Project name and version and the rest of the fields making sure you select Charset and Source code charset to UTF8 and selecting the language and country of the translation you are going to create, in my case Language: Swedish and Country: 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; application

Project Base and application path

Now select the Keywords tab and click the New item tool and add;

  • translate
  • _
  • setLabel
  • setValue
  • setMessage
  • setLegend
  • _refresh
  • append
  • prepend

(Note: If you have any other keywords that come to mind, feel free to comment and I’ll add them to this tutorial)

Now you click OK and the Save as dialog comes up move to your project application directory and select or create the languages directory the path should look something 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 keywords you specified earlier and the Update Summary dialog will be showing all the strings it detected;

Update Summary

In this example 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 Summary Dialog you will be taken to the main poedit window where you can translate the strings.

Main window

As you can see it’s very easy to work with simply enter your translations in the bottom text box.

Now after you are done you simply click File -> Save and two files will be written to your languages directory, in my case sv_SE.po and sv_SE.mo where the .mo file is the compiled version that Zend_Translate uses.

Now if you add new strings to your source code you simply load poedit and open your sv_SE.po file and select Catalog -> Update from sources and it will again show you the Update Summary dialog with all new string as well as changed strings and removed (Obsolete) strings.

There are a ton of good Zend_Translate references out there, google is your friend!

Hope this helps, enjoy!