Skip to content
yii component to initialize php's builtin gettext extension
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Yii extension: php-gettext initializer

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

Something went wrong with that request. Please try again.