gettext

Prepares php's built-in gettext extension
1 follower

Prepares PHP's built-in gettext extension using the specified locale (not at all related to Yii's translation system)

Requirements

Yii 1.1 or above

Usage

Extract this package under protected/extensions/

Define the 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', // means 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) ?><br/>


    // php 5.4+ or shorttags allows this shorthand:

        <?=_('All Rights Reserved.')?>

Use a PO editor such as poedit to scan for new messages and create new translations.

Resources

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads