Guest User

Untitled

a guest
Mar 13th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. App::import('Core', 'L10n');
  4.  
  5. class LocaleRoute extends CakeRoute {
  6.  
  7.     public function parse($url) {
  8.         $params = parent::parse($url);
  9.  
  10.         $l10n = new L10n();
  11.  
  12.         $defaultLang = $l10n->default;
  13.         $defaultLoc = $l10n->map($defaultLang);
  14.  
  15.         $language = $defaultLang;
  16.  
  17.         if (isset($params['locale'])) {
  18.             $locale = $params['locale'];
  19.  
  20.             if(in_array($locale, Configure::read('SupportedLocales'))) {
  21.                 $language = ($l10n->map($locale)) ? $l10n->map($locale) : $defaultLang;
  22.             } else {
  23.                // $params['locale'] = $defaultLoc;
  24.             }
  25.         } else {
  26.            // $params['locale'] = $defaultLoc;
  27.         }
  28.  
  29.         Configure::write('Config.language', $language);
  30.         setlocale(LC_ALL, $language .'UTF8', $language .'UTF-8', $language, $defaultLang . '.UTF8', $defaultLang . '.UTF-8', $defaultLang, 'en_US');
  31.  
  32.         return $params;
  33.     }
  34. }
  35.  
  36. ?>
Add Comment
Please, Sign In to add comment