gettext Prepares php's built-in gettext extension

Yii extension: php-gettext initializer

  1. INSTALLATION
  2. USAGE

Prepares php gettext extension

http://php.net/gettext

http://www.gnu.org/software/gettext/

http://github.com/acerix/yii-gettext

INSTALLATION

*. Clone this package into protected/extensions/

$ git clone git://github.com/acerix/yii-gettext.git protected/extensions/gettext

*. Define component and preload in protected/config/main.php:

...

'preload'=>array('gettext','log'),

...

'components'=>array(

	'gettext'=>array(
		'class' => 'ext.gettext.components.GetText',

		// specify language_locale (could be based on domain name, URI, cookie, etc.)
		'language' => 'fr_ca', // eg. french_canada
	),

	...

USAGE

*. Use gettext functions such as _($message) whenever displaying or defining a message.

Examples:

	<?php echo _('All Rights Reserved.') ?>

	<?php echo CHtml::submitButton(_('Login')); ?>

	<?php printf(_('Copyright &copy; %d %s.'), date('Y'), Yii::app()->name) ?>

Use ngettext() to handle plurals:

            <?php $n = rand(0,2); printf(ngettext('%s die', '%s dice', $n), $n); ?>

And strftime() for dates/times:

            <?php echo strftime(_('Generated on %A, %B %e, %Y at %l:%M:%S %P %Z')); ?>

php 5.4+ or shorttags allows this shorthand:

	<?=_('All Rights Reserved.')?>
Read about gettext and how to write messages that are easy to translate:

	http://www.gnu.org/software/gettext/manual/gettext.html
Read more about php's gettext functions:

	http://php.net/gettext

*. Scan your .php files for _() messages, and add them to a translation files

This can be done automatically using poedit ( http://www.poedit.net/ ) or other gettext tools

Using poedit:

	Add a 'new translation project', then add the directory: protected/extensions/gettext/locale/

	The example translation (fr_CA...yii.po) should now be listed in the catalog, double-click it

	Use 'Catalog > Update Sources' to scan for new messages

	Use 'Save As' to create a copy of the template for each desired translation (each needs the same directory structure as the example)

	poedit automatically generates the .mo files in the same folder when saving

NOTE: Translations should be saved as UTF-8
2 0
1 follower
506 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Developed by: acerix
Created on: Apr 30, 2012
Last updated: 4 years ago

Downloads

show all

Related Extensions