getLocale() public method

public getLocale ( )
Ejemplo n.º 1
0
 protected function startup()
 {
     parent::startup();
     // Login check
     if ($this->getName() != 'Admin:Sign') {
         $role = $this->user->getRoles();
         $roleCheck = $this->database->table("users_roles")->get($role[0]);
         if ($roleCheck->admin_access == 0) {
             $this->flashMessage($this->translator->translate('messages.sign.invalidLogin'), "error");
             $this->redirect(':Admin:Sign:in');
         }
         if ($this->user->isLoggedIn()) {
         } else {
             if ($this->user->logoutReason === Nette\Security\IUserStorage::INACTIVITY) {
                 $this->flashMessage($this->translator->translate('messages.sign.youWereLoggedIn'), "note");
             }
             $this->redirect('Sign:in', array('backlink' => $this->storeRequest()));
         }
     }
     if ($this->user->isLoggedIn()) {
         $this->template->isLoggedIn = TRUE;
         $this->template->member = $this->database->table("users")->get($this->user->getId());
     }
     // Set values from db
     $this->template->settings = $this->database->table("settings")->fetchPairs("setkey", "setvalue");
     $this->template->appDir = APP_DIR;
     $this->template->signed = TRUE;
     $this->template->langSelected = $this->translator->getLocale();
     // Set language from cookie
     if ($this->context->httpRequest->getCookie('language_admin') == '') {
         $this->translator->setLocale($this->translator->getDefaultLocale());
     } else {
         $this->translator->setLocale($this->context->httpRequest->getCookie('language_admin'));
     }
 }
Ejemplo n.º 2
0
 /**
  * @return NULL|string
  */
 public function getLocale()
 {
     if ($this->locale === NULL) {
         $this->locale = $this->translator->getLocale();
     }
     if (!in_array($this->locale, $this->translator->getAvailableLocales())) {
         $this->locale = $this->translator->getLocale();
     }
     return $this->locale;
 }
Ejemplo n.º 3
0
 public function sortCollectionByLocales(Nextras\Orm\Mapper\Dbal\DbalCollection $collection, string $column) : Nextras\Orm\Mapper\Dbal\DbalCollection
 {
     $builder = $collection->getQueryBuilder();
     foreach ([$this->translator->getLocale(), $this->translator->getDefaultLocale()] as $locale) {
         $separator = strpos($locale, '_');
         $subLocales = $separator === FALSE ? [$locale] : [$locale, substr($locale, 0, $separator)];
         foreach ($subLocales as $subLocale) {
             $builder->addOrderBy(implode('=', [$column, '%s']) . ' DESC', $subLocale);
         }
     }
     return $collection;
 }
 /**
  * @param Application $sender
  * @param Request $request
  */
 public function onRequest(Application $sender, Request $request)
 {
     $params = $request->getParameters();
     if ($request->getMethod() === Request::FORWARD && empty($params['locale'])) {
         return;
     }
     $this->request = $request;
     if (!$this->translator) {
         return;
     }
     $this->translator->setLocale(NULL);
     $this->translator->getLocale();
     // invoke resolver
 }
Ejemplo n.º 5
0
 public function onRequest(Application $app, Request $request)
 {
     if (!$this->translator) {
         return;
     }
     $snapshot = array('request' => $request, 'locale' => $this->translator->getLocale(), 'resolvers' => array());
     foreach ($this->localeResolvers as $name => $resolver) {
         $snapshot['resolvers'][$name] = $resolver->resolve($this->translator);
     }
     $this->onRequestLocaleSnapshot[] = $snapshot;
 }
Ejemplo n.º 6
0
 public function startup()
 {
     parent::startup();
     $this->actualLanguage = Language::findOneBy(array('locale' => $this->translator->getLocale(), 'public' => true)) ?: Language::findOneBy(array('locale' => $this->translator->getDefaultLocale()));
     $this->translatorSession->setLocale($this->actualLanguage->getLocale());
 }
Ejemplo n.º 7
0
 protected function startup()
 {
     parent::startup();
     if (session_status() == PHP_SESSION_NONE) {
         session_start();
     }
     $this->template->page = $this->database->table("pages")->get($this->getParameter("page_id"));
     $this->template->settings = $this->database->table("settings")->fetchPairs("setkey", "setvalue");
     /* Maintenance mode */
     if ($this->template->settings["maintenance_enabled"]) {
         if (empty($this->template->settings["maintenance_message"])) {
             include_once '.maintenance.php';
         } else {
             echo $this->template->settings["maintenance_message"];
         }
         exit;
     }
     /* IP mode */
     $ip = explode(";", $this->template->settings["site_ip_whitelist"]);
     if (strlen($this->template->settings["site_ip_whitelist"]) < 4 || in_array($_SERVER['REMOTE_ADDR'], $ip)) {
     } else {
         if (empty($this->template->settings["maintenance_message"])) {
             include_once '.maintenance.php';
         } else {
             echo $this->template->settings["maintenance_message"];
         }
         exit;
     }
     /* Secret password mode */
     $secret = $_COOKIE["secretx"];
     if ($this->template->settings['site_cookie_whitelist'] != '') {
         if ($this->template->settings["site_cookie_whitelist"] != $secret) {
             if ($_GET["secretx"] == $this->template->settings["site_cookie_whitelist"]) {
                 setcookie("secretx", $this->template->settings["site_cookie_whitelist"], time() + 3600000);
             } else {
                 if (empty($this->template->settings["maintenance_message"])) {
                     include_once '.maintenance.php';
                 } else {
                     echo $this->template->settings["maintenance_message"];
                 }
                 exit;
             }
         } else {
             $message = "5";
         }
     }
     // Arguments for language switch box
     $parametres = $this->getParameters(TRUE);
     unset($parametres["locale"]);
     $this->template->args = $parametres;
     $this->template->langSelected = $this->translator->getLocale();
     $this->template->langDefault = $this->translator->getDefaultLocale();
     if ($this->translator->getLocale() != $this->translator->getDefaultLocale()) {
         $this->template->langSuffix = '_' . $this->translator->getLocale();
     }
     try {
         if ($this->user->isLoggedIn()) {
             $this->template->isLoggedIn = TRUE;
             $this->template->member = $this->database->table("users")->get($this->user->getId());
         } else {
             $this->template->isLoggedIn = FALSE;
         }
     } catch (\Exception $e) {
         $this->template->isLoggedIn = FALSE;
     }
     $this->template->appDir = APP_DIR;
     $this->template->languageSelected = $this->translator->getLocale();
     if ($this->template->settings['store:enabled']) {
         $cart = new Model\Store\Cart($this->database, $this->user->getId(), $this->template->isLoggedIn);
         $cart->cleanCarts();
         $this->template->cartObject = $cart;
         $this->template->cartId = $cart->getCartId();
         $this->template->cartItems = $cart->getCartItems();
         $this->template->cartItemsArr = $cart->getItems();
         $this->template->cartTotal = $cart->getCartTotal($this->template->settings);
         $this->template->cartInfo = $cart->getCart();
         if ($cart->getItems()) {
             $this->template->cart = $cart->getItems()->order("id");
         }
         $bonus = new Model\Store\Bonus($this->database);
         $bonus->setUser($this->user->getId());
         $bonus->setCartTotal($this->template->cartTotal);
         $amountBonus = $bonus->getAmount($cart->getCartTotal($this->template->settings));
         $this->template->amountBonus = abs($amountBonus);
         if ($amountBonus <= 0) {
             $this->template->bonusEnabled = true;
         } else {
             $this->template->bonusEnabled = false;
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * @return string
  */
 public function getLocale() : string
 {
     $locale = $this->translator->getLocale();
     return $locale ?: $this->translator->getDefaultLocale();
 }