16.9. Managing Localization Resources

Problem

You need to keep track of your various message catalogs and images.

Solution

Two techniques simplify the management of your localization resources. The first is making a new language’s object, for example Canadian English, extend from a similar existing language, such as American English. You only have to change the words and phrases in the new object that differ from the original language.

The second technique: to track what phrases still need to be translated in new languages, put stubs in the new language object that have the same value as in your base language. By finding which values are the same in the base language and the new language, you can then generate a list of words and phrases to translate.

Discussion

The catalog-compare.php program shown in Example 16-2 prints out messages that are the same in two catalogs, as well as messages that are missing from one catalog but present in another.

Example 16-2. catalog-compare.php

$base = 'pc_MC_'.$_SERVER['argv'][1]; $other = 'pc_MC_'.$_SERVER['argv'][2]; require 'pc_MC_Base.php'; require "$base.php"; require "$other.php"; $base_obj = new $base; $other_obj = new $other; /* Check for messages in the other class that * are the same as the base class or are in * the base class but missing from the other class */ foreach ($base_obj->messages as $k => $v) { if (isset($other_obj->messages[$k])) { if ($v == $other_obj->messages[$k]) { print "SAME: $k\n"; } } else { print "MISSING: $k\n"; ...

Get PHP Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.