From: Vincent Vanwaelscappel Date: Wed, 9 Dec 2020 12:11:14 +0000 (+0100) Subject: wip #3753 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=9833ca5f7ecedeecdd5f8c9062a3f2690386156e;p=cubist_cms-back.git wip #3753 @0.5 --- diff --git a/src/app/Magic/Controllers/CubistMagicController.php b/src/app/Magic/Controllers/CubistMagicController.php index 6684bf3..9b8b988 100644 --- a/src/app/Magic/Controllers/CubistMagicController.php +++ b/src/app/Magic/Controllers/CubistMagicController.php @@ -78,7 +78,7 @@ class CubistMagicController extends CubistCrudController $this->crud->setRoute(backpack_url($this->_routeURL)); - $this->crud->setEntityNameStrings($this->_singular, $this->_plural); + $this->crud->setEntityNameStrings(__($this->_singular), __($this->_plural)); /* diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index d616a7b..ce564a2 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -372,15 +372,29 @@ class CubistMagicAbstractModel extends Model implements HasMedia protected function _replaceInCode($stub, $dest) { + $singular = $this->getOption('singular', $this->getOption('name')); + $plural = $this->getOption('plural', ''); + + $totranslate = [$singular, $plural]; + $translate = '/*' . "\n"; + foreach ($totranslate as $str) { + if (!$str) { + continue; + } + $translate .= "\t__('" . addcslashes($str, "'") . "')\n"; + } + $translate .= "\t*/"; + $vars = ['CONTROLLERCLASS' => $this->getControllerClass(), 'ROUTEURL' => $this->getOption('route', $this->getOption('name')), - 'SINGULAR' => $this->getOption('singular', $this->getOption('name')), - 'PLURAL' => $this->getOption('plural', ''), + 'SINGULAR' => $singular, + 'PLURAL' => $plural, 'MODELNAMESPACE' => get_class($this), 'EXTENDS' => '\\' . $this->_getBaseController(), 'BULK' => $this->getOption('bulk', true) ? 'true' : 'false', 'ONEINSTANCE' => $this->getOption('oneinstance', false) ? 'true' : 'false', - 'USE' => $this->_getUse()]; + 'USE' => $this->_getUse(), + 'TRANSLATE' => $translate]; $res = file_get_contents($stub); foreach ($vars as $name => $value) { diff --git a/src/resources/cubistmagic/Controller.stub b/src/resources/cubistmagic/Controller.stub index c28bb3b..45f57a7 100644 --- a/src/resources/cubistmagic/Controller.stub +++ b/src/resources/cubistmagic/Controller.stub @@ -6,6 +6,8 @@ class _CONTROLLERCLASS_ extends _EXTENDS_ { _USE_ + _TRANSLATE_ + protected $_modelNamespace = '_MODELNAMESPACE_'; protected $_routeURL = '_ROUTEURL_'; protected $_singular = '_SINGULAR_';