1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
<?php
/**
* Lithium: the most rad php framework
*
* @copyright Copyright 2010, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
/**
* This bootstrap file contains class configuration for all aspects of globalizing your application,
* including localization of text, validation rules, setting timezones and character inflections,
* and identifying a user's locale.
*/
use lithium\core\Libraries;
use lithium\core\Environment;
use lithium\g11n\Locale;
use lithium\g11n\Catalog;
use lithium\g11n\Message;
use lithium\util\Inflector;
use lithium\util\Validator;
use lithium\net\http\Media;
use lithium\action\Dispatcher as ActionDispatcher;
use lithium\console\Dispatcher as ConsoleDispatcher;
/**
* Sets the default timezone used by all date/time functions.
*/
date_default_timezone_set('UTC');
/**
* Adds globalization specific settings to the environment.
*
* The settings for the current locale, time zone and currency are kept as environment
* settings. This allows for _centrally_ switching, _transparently_ setting and retrieving
* globalization related settings.
*
* The environment settings are:
*
* - `'locale'` The effective locale.
* - `'locales'` Application locales available mapped to names. The available locales are used
* to negotiate he effective locale, the names can be used i.e. when displaying
* a menu for choosing the locale to users.
*/
$locale = 'en';
$locales = array('en' => 'English');
Environment::set('production', compact('locale', 'locales'));
Environment::set('development', compact('locale', 'locales'));
Environment::set('test', array('locale' => 'en', 'locales' => array('en' => 'English')));
/**
* Globalization (g11n) catalog configuration. The catalog allows for obtaining and
* writing globalized data. Each configuration can be adjusted through the following settings:
*
* - `'adapter'` _string_: The name of a supported adapter. The builtin adapters are `Memory` (a
* simple adapter good for runtime data and testing), `Php`, `Gettext`, `Cldr` (for
* interfacing with Unicode's common locale data repository) and `Code` (used mainly for
* extracting message templates from source code).
*
* - `'path'` All adapters with the exception of the `Memory` adapter require a directory
* which holds the data.
*
* - `'scope'` If you plan on using scoping i.e. for accessing plugin data separately you
* need to specify a scope for each configuration, except for those using the `Memory`,
* `Php` or `Gettext` adapter which handle this internally.
*/
Catalog::config(array(
'runtime' => array(
'adapter' => 'Memory'
),
// 'app' => array(
// 'adapter' => 'Gettext',
// 'path' => Libraries::get(true, 'resources') . '/g11n'
// ),
'lithium' => array(
'adapter' => 'Php',
'path' => LITHIUM_LIBRARY_PATH . '/lithium/g11n/resources/php'
)
) + Catalog::config());
/**
* Integration with `Inflector`.
*/
// Inflector::rules('transliteration', Catalog::read(true, 'inflection.transliteration', 'en'));
/**
* Inflector configuration examples. If your application has custom singular or plural rules, or
* extra non-ASCII characters to transliterate, you can configure that by uncommenting the lines
* below.
*/
// Inflector::rules('singular', array('rules' => array('/rata/' => '\1ratus')));
// Inflector::rules('singular', array('irregular' => array('foo' => 'bar')));
//
// Inflector::rules('plural', array('rules' => array('/rata/' => '\1ratum')));
// Inflector::rules('plural', array('irregular' => array('bar' => 'foo')));
//
// Inflector::rules('transliteration', array('/É|Ê/' => 'E'));
//
// Inflector::rules('uninflected', 'bord');
// Inflector::rules('uninflected', array('bord', 'baird'));
/**
* Integration with `View`. Embeds message translation aliases into the `View`
* class (or other content handler, if specified) when content is rendered. This
* enables translation functions, i.e. `<?=$t("Translated content"); ?>`.
*/
Media::applyFilter('_handle', function($self, $params, $chain) {
$params['handler'] += array('outputFilters' => array());
$params['handler']['outputFilters'] += Message::aliases();
return $chain->next($self, $params, $chain);
});
/**
* Integration with `Validator`. You can load locale dependent rules into the `Validator`
* by specifying them manually or retrieving them with the `Catalog` class.
*/
foreach (array('phone', 'postalCode', 'ssn') as $name) {
Validator::add($name, Catalog::read(true, "validation.{$name}", 'en_US'));
}
/**
* Intercepts dispatching processes in order to set the effective locale by using
* the locale of the request or if that is not available retrieving a locale preferred
* by the client.
*/
ActionDispatcher::applyFilter('_callable', function($self, $params, $chain) {
$request = $params['request'];
$controller = $chain->next($self, $params, $chain);
if (!$request->locale) {
$request->params['locale'] = Locale::preferred($request);
}
Environment::set(Environment::get(), array('locale' => $request->locale));
return $controller;
});
ConsoleDispatcher::applyFilter('_callable', function($self, $params, $chain) {
$request = $params['request'];
$command = $chain->next($self, $params, $chain);
if (!$request->locale) {
$request->params['locale'] = Locale::preferred($request);
}
Environment::set(Environment::get(), array('locale' => $request->locale));
return $command;
});
?>
|