Пример #1
0
 /**
  * Get the best language for multi-language content.
  * @param  Array       $content - multi-language content
  * @param  HttpRequest $request - the HTTP request
  * @param  HttpSession $session - the HTTP session
  * @return the best language for multi-language content
  */
 protected function getBestLanguageForContent($content, $request, $session)
 {
     if (!is_array($content)) {
         return $content;
     }
     $languageDectorPlugin = new LanguageDectorPlugin();
     $currentLanguage = $languageDectorPlugin->getCurrentLanguage($request, $session);
     $defaultLanguage = 'en';
     $firstLanguage = key($content);
     if (array_key_exists($currentLanguage, $content)) {
         return $content[$currentLanguage];
     } else {
         if (array_key_exists($defaultLanguage, $content)) {
             return $content[$defaultLanguage];
         }
     }
     return $content[$firstLanguage];
 }
Пример #2
0
$di->set('security', function () {
    $security = new Security();
    $security->setWorkFactor(12);
    return $security;
}, true);
/**
 * Mail Service.
 */
$di->set('mailSender', function () {
    return new MailSender();
});
/**
 * Localization Service.
 */
$di->set('localization', function () use($di, $config) {
    $languageDectorPlugin = new LanguageDectorPlugin();
    $session = $di->getShared('session');
    $request = $di->getShared('request');
    $language = $languageDectorPlugin->getCurrentLanguage($request, $session);
    $languageDir = APP_PATH . $config->application->languageDir;
    $languageFile = "{$languageDir}/{$language}.php";
    if (file_exists($languageFile)) {
        require $languageFile;
    } else {
        require "{$languageDir}/en.php";
    }
    return new TranslateArray(array("content" => $messages));
});
$di->set('languages', function () {
    return array('en' => 'English', 'zh' => '简体中文');
});