Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 100 lines (47 sloc) 2.441 kb
5a12a29 @acerix init
authored
1 Yii extension: php-gettext initializer
2 ======================================
3
4 Prepares php gettext extension
5
6
7 http://php.net/gettext
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
8
5a12a29 @acerix init
authored
9 http://www.gnu.org/software/gettext/
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
10
5a12a29 @acerix init
authored
11 http://github.com/acerix/yii-gettext
12
13
14 INSTALLATION
15 ------------
16
cdebb05 @acerix simplify readme
authored
17 *. Clone this package into protected/extensions/
5a12a29 @acerix init
authored
18
cdebb05 @acerix simplify readme
authored
19 $ git clone git://github.com/acerix/yii-gettext.git protected/extensions/gettext
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
20
cdebb05 @acerix simplify readme
authored
21
22 *. Define component and preload in protected/config/main.php:
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
23
5a12a29 @acerix init
authored
24 ...
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
25
5a12a29 @acerix init
authored
26 'preload'=>array('gettext','log'),
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
27
5a12a29 @acerix init
authored
28 ...
29
30 'components'=>array(
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
31
5a12a29 @acerix init
authored
32 'gettext'=>array(
33 'class' => 'ext.gettext.components.GetText',
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
34
ecf61d9 @acerix clarify example
authored
35 // specify language_locale, could be based on domain name, URI, cookie, etc
36 'language' => 'fr_ca', // means french_canada
5a12a29 @acerix init
authored
37 ),
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
38
5a12a29 @acerix init
authored
39 ...
40
41
cdebb05 @acerix simplify readme
authored
42
5a12a29 @acerix init
authored
43 USAGE
44 -----
45
46 *. Use gettext functions such as _($message) whenever displaying or defining a message.
47
48 Examples:
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
49
5a12a29 @acerix init
authored
50 <?php echo _('All Rights Reserved.') ?>
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
51
52 <?php echo CHtml::submitButton(_('Login')); ?>
53
5a12a29 @acerix init
authored
54 <?php printf(_('Copyright &copy; %d %s.'), date('Y'), Yii::app()->name) ?><br/>
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
55
56
5a12a29 @acerix init
authored
57 // php 5.4+ or shorttags allows this shorthand:
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
58
5a12a29 @acerix init
authored
59 <?=_('All Rights Reserved.')?>
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
60
61
5a12a29 @acerix init
authored
62 NOTE: Messages in source files should only use ASCII characters (no accents, etc) and are typically written in English.
63
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
64
65 Read about gettext and how to write messages that are easy to translate:
66
5a12a29 @acerix init
authored
67 http://www.gnu.org/software/gettext/manual/gettext.html
68
69
70 Read more about php's gettext functions:
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
71
5a12a29 @acerix init
authored
72 http://php.net/gettext
73
74
75 *. Scan your .php files for _() messages, and add them to a translation files
76
77 This can be done automatically using poedit ( http://www.poedit.net/ ) or other gettext tools
78
79 Using poedit:
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
80
5a12a29 @acerix init
authored
81 Add a 'new translation project', then add the directory: protected/extensions/gettext/locale/
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
82
8727e2d @acerix removed symbolic links, just store translations where gettext looks (poe...
authored
83 The example translation (fr_CA...yii.po) should now be listed in the catalog, double-click it
5a12a29 @acerix init
authored
84
85 Use 'Catalog > Update Sources' to scan for new messages
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
86
8727e2d @acerix removed symbolic links, just store translations where gettext looks (poe...
authored
87 Use 'Save As' to create a copy of the template for each desired translation (each needs the same directory structure as the example)
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
88
8727e2d @acerix removed symbolic links, just store translations where gettext looks (poe...
authored
89 poedit automatically generates the .mo files in the same folder when saving
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
90
5a12a29 @acerix init
authored
91 NOTE: Translations should be saved as UTF-8
92
93
94 *. Restart webserver to apply new translations
95
96 NOTE: Gettext's cache cannot be disabled or cleared, so translations are only updated when the webserver (or php-fpm) is restarted
595a3d5 @acerix fixed login button example to what it would actually be in yii
authored
97
98 A workaround is to change the gettext domain whenever a .mo file is updated ( doing so is not supported by this extension )
99
Something went wrong with that request. Please try again.