Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
Package: PEAR::Translation2
2
http://pear.php.net/Translation2
3
--------------------------------
4
 
5
PEAR::Translation2 offers a gettext driver along with the db-based ones.
6
 
7
Gettext is designed to offer the best performance when
8
used on its own, without wrappers like this one.
9
 
10
This driver resorts to the .mo parser provided by the
11
PEAR::File_Gettext class to offer the getPage() functionality.
12
This can be useful to get all the strings from a domain
13
and to pass them to a template engine, for instance.
14
 
15
Obviously, it may lead to worse gettext performance.
16
If you want to use gettext at the max speed, don't use this class ;),
17
or at least turn 'prefetch' off AND don't use the getPage() method.
18
Anyway, I haven't done any benchmark, so I can't say how worse it is.
19
The speed difference may be negligible, I really don't know.
20
 
21
End of the necessary preface :)
22
 
23
 
24
=============================
25
Usage example
26
=============================
27
<?php
28
 
29
$params = array(
30
    'prefetch' => false
31
);
32
$gettext_options = array(
33
    'langs_avail_file' => '/path/to/langs.ini',
34
    'domains_path_file' => '/path/to/domains.ini',
35
    'default_domain' => 'messages'
36
);
37
 
38
$tr =& Translation2::factory('gettext', $gettext_options, $params);
39
$tr->setLang('en');
40
 
41
echo $tr->get('mystring');
42
 
43
$tr->setPage('otherDomain');
44
echo $tr->get('aStringFromOtherDomain');
45
 
46
print_r($tr->getPage('thirdDomain'));
47
 
48
?>
49
 
50
 
51
=============================
52
langs.ini file format example
53
=============================
54
; lang code can be in "lang_DIALECT" or in "lang" format
55
 
56
[en_US]
57
name = English
58
encoding = iso-8859-1
59
 
60
[en_GB]
61
name = English
62
encoding = iso-8859-1
63
 
64
[de_DE]
65
name = Deutsch
66
encoding = iso-8859-1
67
 
68
[de_AT]
69
name = Deutsch
70
encoding = iso-8859-1
71
 
72
[it]
73
name = italiano
74
encoding = iso-8859-1
75
 
76
 
77
===============================
78
domains.ini file format example
79
===============================
80
; path the "locale" dir of each domain
81
messages = /usr/data/locale
82
errors = /usr/data/locale
83
myApp =  /usr/data/locale
84
myOtherApp = /usr/newData/locale
85