Example #1
1
 /**
  * Creates new instance.
  *
  * @param  \Illuminate\Foundation\Application                          $app
  * @param  \Arcanedev\Localization\Contracts\RouteTranslatorInterface  $routeTranslator
  * @param  \Arcanedev\Localization\Contracts\LocalesManagerInterface   $localesManager
  */
 public function __construct(Application $app, RouteTranslatorInterface $routeTranslator, LocalesManagerInterface $localesManager)
 {
     $this->app = $app;
     $this->routeTranslator = $routeTranslator;
     $this->localesManager = $localesManager;
     $this->localesManager->setDefaultLocale($this->app->getLocale());
 }
Example #2
1
 /**
  * Determine the locale for the current module.
  *
  * @return string
  */
 public function determine()
 {
     $default = $this->app->getLocale();
     if ($this->currentSection() === 'auth') {
         return $this->isValidBackLocale($this->app->request->segment(1)) ? $this->app->request->segment(1) : $default;
     }
     if ($this->currentSection() === 'back') {
         // User might not be set yet if called in a service provider so a fallback is provided
         if ($this->app->auth->user() !== null) {
             return $this->app->auth->user()->locale;
         }
         return $default;
     }
     return $this->isValidLocale($this->app->request->segment(1)) ? $this->app->request->segment(1) : $default;
 }
Example #3
0
 /**
  * Initialize the base controller sharing important data to all views
  *
  * @return void
  */
 public function initBaseController()
 {
     $lang = $this->app->getLocale();
     $now = $this->carbon->now();
     $this->view->share('lang', $lang);
     $this->view->share('now', $now);
 }
Example #4
0
 /**
  * Collects the data for the site view model
  *
  * @return array
  */
 protected function collectVisitData()
 {
     $request = $this->request;
     $user = $request->user();
     $userId = $user ? $user->getKey() : null;
     return ['user_id' => $userId, 'http_referer' => $request->server('HTTP_REFERER'), 'url' => $request->fullUrl(), 'request_method' => $request->method(), 'request_path' => $request->getPathInfo(), 'http_user_agent' => $request->server('HTTP_USER_AGENT'), 'http_accept_language' => $request->server('HTTP_ACCEPT_LANGUAGE'), 'locale' => $this->app->getLocale(), 'request_time' => $request->server('REQUEST_TIME')];
 }
 /**
  * Set the default locale.
  *
  * @param  string  $defaultLocale
  *
  * @return self
  */
 public function setDefaultLocale($defaultLocale = null)
 {
     if (is_null($defaultLocale)) {
         $defaultLocale = $this->app->getLocale();
     }
     $this->isDefaultLocaleSupported($defaultLocale);
     $this->defaultLocale = $defaultLocale;
     // TODO: Refresh locales & supportedLocales collection [Locale entity => default property]
     return $this;
 }
 /**
  * Prep the PHPTAL object
  *
  * @param
  *            $app
  */
 public function __construct($app)
 {
     $this->app = $app;
     $this->config = $app['config'];
     $this->phptal = new \PHPTAL();
     // Override the defaults with information from config file
     $preFilters = $this->config->get('phptal.preFilters', []);
     $postFilters = $this->config->get('phptal.postFilters', []);
     $encoding = $this->config->get('phptal.translationEncoding', 'UTF-8');
     $outputMode = $this->config->get('phptal.outputMode', \PHPTAL::HTML5);
     $phpCodeDestination = $this->config->get('phptal.phpCodeDestination', $app['path.storage'] . '/framework/views');
     $forceReparse = $this->config->get('phptal.forceParse', true);
     $templateRepositories = $this->config->get('phptal.templateRepositories', $app['path.base'] . '/resources/views' . (TEMPLATE_ID ? '/' . TEMPLATE_ID : ''));
     $translationClass = $this->config->get('phptal.translationClass');
     $translationDomain = $this->config->get('phptal.translationDomain', 'messages');
     $translationLanguage = [$this->app->getLocale()];
     // Setting up translation settings
     $this->translationSettings['encoding'] = $encoding;
     if (!empty($translationClass)) {
         $this->setTranslator($translationLanguage, $translationDomain, $translationClass);
     }
     // Setting up all the filters
     if (!empty($preFilters)) {
         foreach ($preFilters as $filter) {
             $this->phptal->addPreFilter($filter);
         }
     }
     if (!empty($postFilters)) {
         $filterChain = new PHPTALFilterChain();
         foreach ($postFilters as $filter) {
             $filterChain->add($filter);
         }
         $this->phptal->setPostFilter($filterChain);
     }
     $this->phptal->setForceReparse($forceReparse);
     $this->phptal->setOutputMode($outputMode);
     $this->phptal->setTemplateRepository($templateRepositories);
     $this->phptal->setPhpCodeDestination($phpCodeDestination);
 }
Example #7
0
 /**
  * Get the current application locale.
  *
  * @return string 
  * @static 
  */
 public static function getLocale()
 {
     return \Illuminate\Foundation\Application::getLocale();
 }
Example #8
0
 /**
  * Get current locale
  *
  * @return string
  */
 public function getCurrentLocale()
 {
     return $this->app->getLocale();
 }
 function __construct(Application $app, Store $session)
 {
     $this->locale = $app->getLocale();
     $this->session = $session;
 }
Example #10
0
 /**
  * Sets the time locale
  *
  * @param string $locale
  * @return void
  */
 public function setTimeLocale($locale = null)
 {
     $locale = $locale ?: $this->session->get('_locale', $this->app->getLocale());
     setlocale(LC_TIME, $this->config->get('translatable.full_locales.' . $locale, null));
     Carbon::setLocale($locale);
 }
Example #11
0
 /**
  * @param Application $app
  * @return mixed
  */
 protected function systemInfo(Application $app)
 {
     return ['locale' => $app->getLocale(), 'systemLocales' => $this->system_locales()->toArray(), 'locales' => $this->system_locales()->filter(function ($item) {
         return $item->activated == true;
     })->toArray(), 'systemModules' => $this->system_modules()->toArray()];
 }