public function register()
 {
     // Register filter
     $this->app['lari18n'] = $this->app->share(function ($app) {
         return Lari18n::getInstance();
     });
     $this->app['router']->after(function ($request, $response) {
         if (Lari18n::isActivated()) {
             $this->app['lari18n']->modifyResponse($request, $response);
         }
     });
     parent::register();
 }
Ejemplo n.º 2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $from = $this->argument('from_locale');
     $to = $this->argument('to_locale');
     $Lari18n = Lari18n::getInstance();
     $data = $Lari18n->retrieveI18nData();
     $languages = $data['languages'];
     $languagesPath = $data['paths']['lang'];
     // check
     if (!in_array($from, $languages)) {
         $this->error('There is no locale [' . $from . ']');
     }
     if (in_array($to, $languages)) {
         $this->error('The [' . $to . '] locale already exist');
     }
     // Create the new language directory
     File::copyDirectory($languagesPath . '/' . $from, $languagesPath . '/' . $to);
     $files = File::allFiles($languagesPath . '/' . $to);
     $Lari18n->reinitialiseFiles($files, $to);
     $this->info('The [' . $to . '] translation directory as been created from [' . $from . '] translations files');
 }
Ejemplo n.º 3
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     $this->lari18n = Lari18n::getInstance();
 }
Ejemplo n.º 4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $Lari18n = Lari18n::getInstance();
     // Get language basic data
     $data = $Lari18n->retrieveI18nData();
     $master = Config::get('app.fallback_locale');
     $masterData = $data['languagesData'][$master];
     $masterDataDot = array_dot($masterData);
     $masterLanguagesKeys = array_keys($data['languages'], $master);
     // Remove master language from arrays
     unset($data['languages'][$masterLanguagesKeys[0]]);
     unset($data['languagesData'][$master]);
     // If only one locale
     if (empty($data['languages'])) {
         $this->error('There is only one locale, nothing to update');
     }
     $slaves = $data['languages'];
     $slavesData = $data['languagesData'];
     $updated = array_flip($slaves);
     // Initialise
     foreach ($updated as $key => $value) {
         $updated[$key] = ['add' => 0, 'delete' => 0];
     }
     // Empty line
     $this->info('');
     // Backup
     if (!$this->option('nobackup')) {
         // Create storage directory if it doesn't exist
         if (!File::isDirectory($Lari18n->paths['backup'])) {
             File::makeDirectory($Lari18n->paths['backup'], null, true);
         }
         $filename = $Lari18n->paths['backup'] . date('y-m-d_his') . '_backup';
         // Create Backup directory
         File::makeDirectory($filename);
         // Backup all language files
         File::copyDirectory($Lari18n->paths['lang'], $filename);
         // Log
         $this->info('Backup created in ' . 'app' . str_replace(array(app_path(), '\\'), array('', '/'), $filename));
     }
     // Walk on all master translations
     foreach ($masterDataDot as $key => $value) {
         // Verify for each slave translation
         foreach ($slavesData as $locale => $files) {
             // If translation doesn't exist, create it
             if (array_get($files, $key) === null) {
                 $Lari18n->translate($master, $locale, $key, $Lari18n->todo_translation_key . $value);
                 $updated[$locale]['add']++;
             }
         }
     }
     if (!$this->option('remove')) {
         foreach ($updated as $locale => $numbers) {
             if ($numbers['add'] === 0) {
                 $this->info('No modification for the ' . $locale . ' locale lines');
             } else {
                 $this->info('+' . $numbers['add'] . ' ' . $locale . ' locale lines updated');
             }
         }
         return;
     }
     // On each localisation
     foreach ($slavesData as $key => $slaveData) {
         $slaveDataDot = array_dot($slaveData);
         // Walk on slave translations
         foreach ($slaveDataDot as $keySlave => $valueSlave) {
             // If translation doesn't exist in master, erase it
             if (array_get($masterData, $keySlave) === null) {
                 $Lari18n->remove($key, $keySlave);
                 $updated[$key]['delete']++;
             }
         }
     }
     foreach ($updated as $locale => $numbers) {
         if ($numbers['add'] === 0 && $numbers['delete'] === 0) {
             $this->info('No modification for the ' . $locale . ' locale lines');
         } else {
             $this->info('+' . $numbers['add'] . ' -' . $numbers['delete'] . ' ' . $locale . ' locale lines updated');
         }
     }
 }