Home > centOS, Fedora 12, PHP, Unix/Linux, Zend > Zend internationalize

Zend internationalize


How to make it smart? So that we can translate any lanugage?

1. Checking tools

[root@www ~]# xgettext –version
xgettext (GNU gettext-tools) 0.14.6
Copyright (C) 1995-1998, 2000-2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Ulrich Drepper.

[root@www files]# msgfmt –version
msgfmt (GNU gettext-tools) 0.14.6
Copyright (C) 1995-1998, 2000-2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Ulrich Drepper.


2. Collect the texts which we will translate.

# How to xgettext?
# ================
# xgettext –no-location [do not write ’#: filename:line’ lines]
# xgettext -L PHP [use PHP language pattern]
# xgettext –from-code=ISO-8859-1 [encoded read pattern]
# xgettext `input option` [input files to use]
# xgettext -o [where to save file.po?]

[root@www index]# xgettext –no-location -L PHP –from-code=ISO-8859-1 `find /var/www/html/myzf/ | grep phtml` -o msg.po; cat msg.po;
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE’S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid “”
msgstr “”
“Project-Id-Version: PACKAGE VERSION\n”
“Report-Msgid-Bugs-To: \n”
“POT-Creation-Date: 2010-03-01 17:32+0100\n”
“PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n”
“Last-Translator: FULL NAME <EMAIL@ADDRESS>\n”
“Language-Team: LANGUAGE <LL@li.org>\n”
“MIME-Version: 1.0\n”
“Content-Type: text/plain; charset=CHARSET\n”
“Content-Transfer-Encoding: 8bit\n”

msgid “How are you zend?”
msgstr “”

msgid “Whats up zend delete?”
msgstr “”

msgid “Whats up zend add?”
msgstr “”

msgid “Whats up zend edit?”
msgstr “”
[root@www index]#

3. Send msg.po file to translator department (your boss/friend/pro etc), who can translate english international language TO french/dutch/bangla…….? And send back as following format (following file is english to dutch:
[root@www index]# cat msg.po
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE’S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid “”
msgstr “”
“Project-Id-Version: PACKAGE VERSION\n”
“Report-Msgid-Bugs-To: \n”
“POT-Creation-Date: 2010-03-01 17:32+0100\n”
“PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n”
“Last-Translator: FULL NAME <EMAIL@ADDRESS>\n”
“Language-Team: LANGUAGE <LL@li.org>\n”
“MIME-Version: 1.0\n”
“Content-Type: text/plain; charset=CHARSET\n”
“Content-Transfer-Encoding: 8bit\n”

msgid “How are you zend?”
msgstr “Hoe gaat het zend?”

msgid “Whats up zend delete?”
msgstr “Wat is er zend verwijderen?”

msgid “Whats up zend add?”
msgstr “Wat is er zend toevoegen?”

msgid “Whats up zend edit?”
msgstr “Wat is er zend wijzigen?”
[root@www index]#

4. Final msg.po translated file should be decoded as whaat_ever_filename.mo using msgfmt (GNU gettext-tools)
copy msg.po file to /var/www/html/myzf/language (en.po and nl.po)
[root@www language]# tree
.
|– en
| `– LC_MESSAGES
| `– en.po
|– fr
`– nl
`– LC_MESSAGES
`– nl.po

5 directories, 2 files
[root@www language]#
# check the charset and make en/nl.mo file
[root@www LC_MESSAGES]# msgfmt en.po -o en.mo
[root@www LC_MESSAGES]# msgfmt nl.po -o nl.mo

5. Now everything by Zend or pure php we can handle.
File: application/controllers/IndexController.php:

<?php

class IndexController extends Zend_Controller_Action

{

/**

* [test] – Before the index.phtml gets load

*

*

*/

public function init()

{

/**

* @Local settings

*/

$locale = new Zend_Locale();

Zend_Registry::set(‘Zend_Locale’, $locale);

/**

* Default language define

*

*/

$translate = new Zend_Translate(

‘gettext’,

‘/var/www/html/myzf/language/en/LC_MESSAGES/en.mo’,

‘en’);

/**

* @addLanguage

* – We can add many languages like this

*

*/

$translate->addTranslation(

‘/var/www/html/myzf/language/nl/LC_MESSAGES/nl.mo’,

‘nl’);

/**

* @whichlanguage

* – i am telling to use dutch now

* – depending on user input/language selection > this value we can change

*

*/

$translate->setLocale(‘nl’);

/**

* @view page:

* $this->translate(‘How are you zend?’); it will translate to nl > “Hoe gaat het zend?”

*

*

*

*/

Zend_Registry::set(‘Zend_Translate’, $translate);

// [debug] – not needed

print_r ($locale->getLanguage()); // output: en

}

public function indexAction()

{

}

public function addAction()

{

}

public function editAction()

{

}

public function delAction()

{

}

}

file: application/views/scripts/index/index.phtml:

<h1><?= _(“How are you zend?”) ?></h1>

<h2><?= $this->translate(‘How are you zend?’) ?>

6. Output:

done.


Advertisements
Categories: centOS, Fedora 12, PHP, Unix/Linux, Zend
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: