From 2389d66da849798f8d4ec5f10e3b07c11da49185 Mon Sep 17 00:00:00 2001 From: Michael Francis Date: Sat, 28 May 2011 13:28:16 -0400 Subject: Initial Commit --- config/bootstrap/g11n.php | 149 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 config/bootstrap/g11n.php (limited to 'config/bootstrap/g11n.php') diff --git a/config/bootstrap/g11n.php b/config/bootstrap/g11n.php new file mode 100644 index 0000000..e96241f --- /dev/null +++ b/config/bootstrap/g11n.php @@ -0,0 +1,149 @@ + '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. ``. + */ +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; +}); + +?> \ No newline at end of file -- cgit v1.2.3