use App\Models\FluidbookTheme;
use App\Models\FluidbookQuote;
+use App\Models\FluidbookTranslate;
use Cubist\Backpack\Console\Commands\CubistCommand;
use Cubist\Backpack\Magic\Fields\Files;
use Cubist\Backpack\Magic\Fields\Color;
//'Backup current database' => 'backup',
//'Import Quotes' => 'importQuotes',
'Migrate magic models' => 'migrate',
- 'Import Themes' => 'importThemes',
+ 'Import Translations' => 'importTranslations',
'Clean caches' => 'cleanCache'
];
$this->executeProcessQuiet('php artisan optimize:clear');
}
- protected function themeCompatTable()
- {
- $theme = new FluidbookTheme();
- $theme->updateWS2Table();
- }
-
- protected function importThemes()
- {
-
- $map = ['theme_id' => 'id',
- 'nom' => 'name',
- 'proprietaire' => 'owner',
- 'date' => 'created_at',];
-
- $ignore = ['extraXSpace', 'extraYSpace'];
-
- FluidbookTheme::$updateWS2ViewOnChange = false;
- foreach (FluidbookTheme::all() as $theme) {
- $theme->delete();
- }
-
- foreach (DB::table($this->_oldDB . '.themes')->get() as $e) {
- $oldRoot = $this->_oldRoot . 'themes/' . $e->theme_id . '/';
- $c = new FluidbookTheme();
- foreach ($map as $old => $new) {
- $v = $e->$old;
- if ($old === 'date') {
- $date = new \DateTime();
- $date->setTimestamp($v);
- $v = $date;
- }
- $c->setAttribute($new, $v);
- }
- $c->save();
-
-
- $s = $this->_unserialize($e->parametres);
-
- foreach ($s->datas as $k => $data) {
- if (in_array($k, $ignore)) {
- continue;
- }
-
- $f = $c->getField($k);
- if (null === $f) {
- continue;
- }
- if ($f instanceof Files) {
- $c->_handleWS2File($f, $data, $oldRoot);
- } else {
- if ($f instanceof Color) {
- $data = FluidbookTheme::_colorToWS3($data);
- }
- $c->setAttribute($k, $data);
- }
- }
- $c->save();
- }
- FluidbookTheme::$updateWS2ViewOnChange = true;
- $this->themeCompatTable();
-
- }
protected function _unserialize($str)
{
}
}
+ protected function importTranslations()
+ {
+ $slug = [];
+ $nsis = [];
+ $contents = [];
+
+ foreach (DB::table($this->_oldDB . '.langues')->get() as $e) {
+ $code = $e->lang_id;
+ if (stristr($code, '-')) {
+ $ex = explode('-', $code);
+ $code = $ex[0] . '_' . mb_strtoupper($ex[1]);
+ }
+ $slug[$code] = '1';
+ $nsis[$code] = $e->nsis;
+ $contents[$code] = ['k' => '-'];
+ $translations = json_decode($e->traductions, true);
+ foreach ($translations as $str => $translation) {
+ $contents[$code]['t_' . base64_encode($str)] = $translation;
+ }
+ touch(FluidbookTranslate::getLanguageFile($code));
+ }
+
+ DB::table('fluidbook_translate')->where('id',1)->update(['slug' => json_encode($slug), 'nsis' => json_encode($nsis), 'content_translatable' => json_encode($contents)]);
+ }
+
}
public function setFields()
{
- $this->addField(['name' => 'nsis', 'type' => NSISLocale::class, 'label' => __('Langue de l\'installeur'), 'translatable' => true]);
+ $this->addField(['name' => 'nsis', 'type' => NSISLocale::class, 'label' => __('Langue de l\'installeur'), 'translatable' => true, 'default' => 'English']);
parent::setFields();
}
{
return array_merge(parent::getExtensions(), ['js']);
}
+
+ protected function _getLanguageFile($locale)
+ {
+ return self::getLanguageFile($locale);
+ }
+
+ public static function getLanguageFile($locale){
+ return resource_path('lang/fluidbook.' . $locale . '.json');
+ }
}