Beispiel #1
0
 /**
  * Sets the configuration and session manager
  */
 public function __construct(ConfigManager $configMan, SessionHandler $sessionHandler, AdapterInterface $adapter)
 {
     // Sets the package configuration and session handler
     $this->configuration = $configMan->get();
     $this->session = $sessionHandler;
     $this->adapter = $adapter;
     // Encoding is set on configuration
     $this->encoding = $this->configuration->getEncoding();
     // Sets defaults for boot
     $locale = $this->session->get($this->configuration->getLocale());
     $this->setLocale($locale);
 }
 /**
  * @expectedException \Xinax\LaravelGettext\Exceptions\UndefinedDomainException
  */
 public function testTranslations()
 {
     /** @var \Xinax\LaravelGettext\Session\SessionHandler|\Mockery\MockInterface $session */
     $session = m::mock('Xinax\\LaravelGettext\\Session\\SessionHandler');
     $session->shouldReceive('get')->andReturn('es_AR');
     $session->shouldReceive('set');
     /** @var \Xinax\LaravelGettext\Adapters\LaravelAdapter|\Mockery\MockInterface $adapter */
     $adapter = m::mock('Xinax\\LaravelGettext\\Adapters\\LaravelAdapter');
     $adapter->shouldReceive('setLocale');
     $adapter->shouldReceive('getApplicationPath')->andReturn(dirname(__FILE__));
     $config = $this->configManager->get();
     // Static traslation files
     $config->setTranslationsPath("translations");
     $gettext = new Gettext($config, $session, $adapter, $this->fileSystem);
     $laravelGettext = new LaravelGettext($gettext);
     $laravelGettext->setLocale("es_AR");
     $this->assertSame("Cadena general con echo de php", _("general string with php echo"));
     $laravelGettext->setDomain("backend");
     $this->assertSame("backend", $laravelGettext->getDomain());
     $this->assertSame("Cadena en el backend con echo de php", _("Backend string with php echo"));
     $laravelGettext->setDomain("frontend");
     $this->assertSame("frontend", $laravelGettext->getDomain());
     $this->assertSame("Cadena de controlador", _("Controller string"));
     $this->assertSame("Cadena de frontend con echo de php", _("Frontend string with php echo"));
     $laravelGettext->setLocale("en_US");
     $this->assertSame("Frontend string with php echo", _("Frontend string with php echo"));
     // Expected exception
     $laravelGettext->setDomain("wrong-domain");
 }
 /**
  * Register the service provider.
  *
  * @return mixed
  */
 public function register()
 {
     $this->app->bind('Adapters/AdapterInterface', 'Adapters/LaravelAdapter');
     // Main class register
     $this->app['laravel-gettext'] = $this->app->share(function ($app) {
         $configuration = Config\ConfigManager::create();
         $fileSystem = new FileSystem($configuration->get(), app_path(), storage_path());
         $gettext = new Gettext($configuration->get(), new Session\SessionHandler($configuration->get()->getSessionIdentifier()), new Adapters\LaravelAdapter(), $fileSystem);
         return new LaravelGettext($gettext);
     });
     // Auto alias
     $this->app->booting(function () {
         $loader = \Illuminate\Foundation\AliasLoader::getInstance();
         $loader->alias('LaravelGettext', 'Xinax\\LaravelGettext\\Facades\\LaravelGettext');
     });
     $this->registerCommands();
 }
 public function setUp()
 {
     parent::setUp();
     // Config
     $testConfig = (include __DIR__ . '/../config/config.php');
     $config = ConfigManager::create($testConfig);
     // Session handler
     $session = m::mock('Xinax\\LaravelGettext\\Session\\SessionHandler');
     $session->shouldReceive('get')->andReturn('en_US');
     $session->shouldReceive('set')->with('en_US');
     // Framework adapter
     $adapter = m::mock('Xinax\\LaravelGettext\\Adapters\\LaravelAdapter');
     $adapter->shouldReceive('setLocale')->with('en_US');
     $adapter->shouldReceive('getApplicationPath')->andReturn(dirname(__FILE__));
     // FileSystem module
     $fileSystem = m::mock('Xinax\\LaravelGettext\\FileSystem');
     $fileSystem->shouldReceive('filesystemStructure')->andReturn(true);
     $fileSystem->shouldReceive('getDomainPath')->andReturn('path');
     $this->gettext = new Gettext($config->get(), $session, $adapter, $fileSystem);
 }
 /**
  * Register the service provider.
  *
  * @return mixed
  */
 public function register()
 {
     $configuration = Config\ConfigManager::create();
     $this->app->bind('Adapters/AdapterInterface', $configuration->get()->getAdapter());
     // Main class register
     $this->app['laravel-gettext'] = $this->app->share(function ($app) use($configuration) {
         $fileSystem = new FileSystem($configuration->get(), app_path(), storage_path());
         if ('symfony' == $configuration->get()->getHandler()) {
             // symfony translator implementation
             $translator = new Translators\Symfony($configuration->get(), new Adapters\LaravelAdapter(), $fileSystem);
         } else {
             // GNU/Gettext php extension
             $translator = new Translators\Gettext($configuration->get(), new Adapters\LaravelAdapter(), $fileSystem);
         }
         return new LaravelGettext($translator);
     });
     include_once __DIR__ . '/Support/helpers.php';
     // Alias
     $this->app->booting(function () {
         $loader = \Illuminate\Foundation\AliasLoader::getInstance();
         $loader->alias('LaravelGettext', 'Xinax\\LaravelGettext\\Facades\\LaravelGettext');
     });
     $this->registerCommands();
 }
Beispiel #6
0
 /**
  * Create a new command instance.
  * @return void
  */
 public function __construct()
 {
     $configManager = new ConfigManager();
     $this->configuration = $configManager->get();
     parent::__construct();
 }
 /**
  * Prepares the package environment for gettext commands
  * 
  * @return void
  */
 protected function prepare()
 {
     $configManager = ConfigManager::create();
     $this->fileSystem = new FileSystem($configManager->get(), app_path(), storage_path());
     $this->configuration = $configManager->get();
 }