gettext Prepares php's built-in gettext extension

Yii extension: php-gettext initializer

  2. USAGE

Prepares php gettext extension


*. Clone this package into protected/extensions/

$ git clone git:// protected/extensions/gettext

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





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

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



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


	<?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:
Read more about php's gettext functions:

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

This can be done automatically using poedit ( ) 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
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Developed by: acerix
Created on: Apr 30, 2012
Last updated: 10 years ago


show all

Related Extensions