From debf3ca6aed73602116e3dc858eef4c954dfc83d Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Sun, 2 Sep 2018 16:27:28 +0200 Subject: [PATCH 1/8] Translation helper controler --- dev/RepoController.php | 2 +- dev/TranslationController.php | 65 +++++++++++++++++++++++++++++++++++ dev/luyadev | 1 + 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 dev/TranslationController.php diff --git a/dev/RepoController.php b/dev/RepoController.php index 7d77ce18f..5ab38957e 100644 --- a/dev/RepoController.php +++ b/dev/RepoController.php @@ -15,7 +15,7 @@ /** * Dev Env cloning and updating. * - * Provdes functions to clone and update the repos. + * Provides functions to clone and update the repos. * * Usage * diff --git a/dev/TranslationController.php b/dev/TranslationController.php new file mode 100644 index 000000000..a02f10a1d --- /dev/null +++ b/dev/TranslationController.php @@ -0,0 +1,65 @@ + + * @since 1.0.6 + */ +class TranslationController extends BaseDevCommand +{ + public $dry = false; + + public function options($actionId) + { + return array_merge(['dry'], parent::options($actionId)); + } + + public function actionAdd($repo, $filename, $language = "*") + { + $repoPath = "repos/$repo"; + $messageFiles = glob("$repoPath/src/*/messages/$language/$filename.php"); + + $this->outputInfo('Following files will be affected:'); + $this->output(implode("\n", $messageFiles) . "\n"); + + $key = $this->prompt('Insert translation key:'); + $text = $this->prompt('Insert translation text:'); + + foreach ($messageFiles as $messageFile) { + $content = file_get_contents($messageFile); + $newContent = preg_replace("/(\];)/", "\t'$key' => '$text',\n$1", $content); + + if (!$this->dry) { + file_put_contents($messageFile, $newContent); + } + else { + $this->outputInfo($messageFile); + } + } + + if (!$this->dry) { + if (exec("[ -d $repoPath/.git ] && command -v git")) { + $diffCommand = "git --git-dir=$repoPath/.git --work-tree=$repoPath diff -- " . str_replace($repoPath . '/', '', implode(" ", $messageFiles)); + exec($diffCommand,$diff); + $this->output(implode("\n", $diff)); + } + + $this->outputSuccess("Translations added. Review the changes before you commit them!"); + } + } +} \ No newline at end of file diff --git a/dev/luyadev b/dev/luyadev index 5d46d2dae..768fca092 100755 --- a/dev/luyadev +++ b/dev/luyadev @@ -27,6 +27,7 @@ $boot->setConfigArray([ 'defaultRoute' => 'repo', 'controllerMap' => [ 'repo' => 'luya\dev\RepoController', + 'translation' => 'luya\dev\TranslationController', ], ]); $boot->applicationConsole(); \ No newline at end of file From dd0711c3d398582b8c0d9520906647f1d8f13d17 Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Sun, 2 Sep 2018 16:46:08 +0200 Subject: [PATCH 2/8] PHPdoc --- dev/TranslationController.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dev/TranslationController.php b/dev/TranslationController.php index a02f10a1d..a2fc6dc64 100644 --- a/dev/TranslationController.php +++ b/dev/TranslationController.php @@ -5,9 +5,9 @@ use luya\helpers\StringHelper; /** - * Dev tool for translators. + * Dev tool for translators. This is only a helper tool for developer to edit the many translation files in different repositories. * - * Provides functions to add new transaltions. + * Provides functions to add new translations. * * Usage * @@ -22,6 +22,9 @@ */ class TranslationController extends BaseDevCommand { + /** + * @var bool Outputs the operations but will not execute anything. + */ public $dry = false; public function options($actionId) @@ -29,10 +32,17 @@ public function options($actionId) return array_merge(['dry'], parent::options($actionId)); } + /** + * Add a new translation to a repository by filename (for admin and frondend). + * + * @param string $repo Name of the repo directory (e.g. luya-module-cms) + * @param string $filename Name of the php file without suffix (e.g. cmsadmin) + * @param string $language (Optional) Add the translation only to one language. Use shortcode e.g. en, de, ... + */ public function actionAdd($repo, $filename, $language = "*") { $repoPath = "repos/$repo"; - $messageFiles = glob("$repoPath/src/*/messages/$language/$filename.php"); + $messageFiles = glob("$repoPath/src/**/messages/$language/$filename.php") ?: glob("$repoPath/src/messages/$language/$filename.php"); $this->outputInfo('Following files will be affected:'); $this->output(implode("\n", $messageFiles) . "\n"); From 67b3f8deb10189e92a539f73c94370a054a13479 Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Wed, 14 Nov 2018 20:21:20 +0100 Subject: [PATCH 3/8] Correct parameter order for help --- dev/RepoController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/RepoController.php b/dev/RepoController.php index 5ab38957e..87ed73119 100644 --- a/dev/RepoController.php +++ b/dev/RepoController.php @@ -27,7 +27,7 @@ * Or clone a custom repo into the repos folder: * * ```sh - * ./venodr/bin/luyadev repo/clone luya-module-news luyadev + * ./venodr/bin/luyadev repo/clone luyadev luya-module-news * ``` * * In order to remove an existing repo from update list @@ -168,8 +168,8 @@ public function actionUpdate() /** * Clone a repo into the repos folder. * - * @param string $repo * @param string $vendor + * @param string $repo */ public function actionClone($vendor = null, $repo = null) { From 15bca4e67395022c1f170e3d65fbe8d31aae3468 Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Mon, 19 Nov 2018 08:55:37 +0100 Subject: [PATCH 4/8] Bugfix with language switcher #1876 --- core/web/UrlManager.php | 2 +- dev/RepoController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/web/UrlManager.php b/core/web/UrlManager.php index 57cc3413d..d62cae042 100644 --- a/core/web/UrlManager.php +++ b/core/web/UrlManager.php @@ -367,7 +367,7 @@ private function urlReplaceModule($url, $navItemId, Composition $composition) } // if current controller context has an other module as the requested url, its an outgoing link to another module which should not be modificated. - if ($moduleName !== Yii::$app->controller->module->id) { + if ($moduleName !== $item->moduleName && $moduleName !== Yii::$app->controller->module->id) { return $url; } diff --git a/dev/RepoController.php b/dev/RepoController.php index 87ed73119..4e123db25 100644 --- a/dev/RepoController.php +++ b/dev/RepoController.php @@ -27,7 +27,7 @@ * Or clone a custom repo into the repos folder: * * ```sh - * ./venodr/bin/luyadev repo/clone luyadev luya-module-news + * ./venodr/bin/luyadev repo/clone luyadev/luya-module-news * ``` * * In order to remove an existing repo from update list From 273a03b1197e98eb7baed0ecdf354140905aaa26 Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Mon, 19 Nov 2018 20:18:00 +0100 Subject: [PATCH 5/8] Unit test fix --- tests/data/classes/UnitMenu.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/data/classes/UnitMenu.php b/tests/data/classes/UnitMenu.php index d22628d07..12d5ecd5e 100644 --- a/tests/data/classes/UnitMenu.php +++ b/tests/data/classes/UnitMenu.php @@ -63,6 +63,8 @@ class Item public $link = 'this-is-a-cms-link'; + public $moduleName = null; + public $isHome = false; } @@ -72,6 +74,8 @@ class ItemHome public $link = 'this-is-a-cms-link'; + public $moduleName = null; + public $isHome = true; } From ec1cf2e59c5ba5fe5a928fce46e2e890eb1ffb11 Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Tue, 20 Nov 2018 08:13:24 +0100 Subject: [PATCH 6/8] Refactoring urlReplaceModule --- core/web/UrlManager.php | 12 ++++++++---- tests/data/classes/UnitMenu.php | 4 ---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/web/UrlManager.php b/core/web/UrlManager.php index d62cae042..b3bc64dc0 100644 --- a/core/web/UrlManager.php +++ b/core/web/UrlManager.php @@ -358,16 +358,20 @@ private function urlReplaceModule($url, $navItemId, Composition $composition) throw new BadRequestHttpException("Unable to find nav_item_id '$navItemId' to generate the module link for url '$url'."); } + $isOutgoingModulePage = $item->type == 2 && $moduleName !== $item->moduleName; + // 1. if the current page is a module and the requested url is not the same module, its an outgoing link to // another module which should not be modificated. // 2. If the current page (nav) context is the homepage, we have to keep the original link as it wont work because the homepage // does not have a route prefix. - if (($item->type == 2 && $moduleName !== $item->moduleName) || $item->isHome) { + if ($isOutgoingModulePage || $item->isHome) { return $url; } - - // if current controller context has an other module as the requested url, its an outgoing link to another module which should not be modificated. - if ($moduleName !== $item->moduleName && $moduleName !== Yii::$app->controller->module->id) { + + // 1. if the current page is a module and the requested url is not the same module, its an outgoing link to + // another module and ... + // 2. if current controller context has an other module as the requested url, its an outgoing link to another module which should not be modificated. + if ($isOutgoingModulePage && $moduleName !== Yii::$app->controller->module->id) { return $url; } diff --git a/tests/data/classes/UnitMenu.php b/tests/data/classes/UnitMenu.php index 12d5ecd5e..d22628d07 100644 --- a/tests/data/classes/UnitMenu.php +++ b/tests/data/classes/UnitMenu.php @@ -63,8 +63,6 @@ class Item public $link = 'this-is-a-cms-link'; - public $moduleName = null; - public $isHome = false; } @@ -74,8 +72,6 @@ class ItemHome public $link = 'this-is-a-cms-link'; - public $moduleName = null; - public $isHome = true; } From 49d847c3cafee5fce688c2752feb80a31cd05bd9 Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Fri, 23 Nov 2018 20:20:20 +0100 Subject: [PATCH 7/8] Changelog --- core/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 721fe4b57..05e57b5e5 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. This project make usage of the [Yii Versioning Strategy](https://github.com/yiisoft/yii2/blob/master/docs/internals/versions.md). In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md). +## 1.0.15 (in progress) + +### Fixed + ++ [#1876](https://github.com/luyadev/luya/issues/1876) Fixed the url generation without module context when using language switcher. + ## 1.0.14 (17. November 2018) + [#1872](https://github.com/luyadev/luya/issues/1872) Added new schemas for Json-Ld. Fixed Event Json-Ld, and TypeHinting. From b7f9bd7517d17924c513b570871f97d8cd520c15 Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Fri, 23 Nov 2018 20:33:57 +0100 Subject: [PATCH 8/8] Typo --- core/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 05e57b5e5..e50a3460d 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -24,7 +24,7 @@ All notable changes to this project will be documented in this file. This projec ## 1.0.12 (8. October 2018) -+ [#1856](https://github.com/luyadev/luya/issues/1856) If application console method is runing, the cli determination should be forced. ++ [#1856](https://github.com/luyadev/luya/issues/1856) If application console method is running, the cli determination should be forced. + [#1853](https://github.com/luyadev/luya/issues/1853) Add option to lazy load mocked arguments. + [#1852](https://github.com/luyadev/luya/pull/1852) Updated Svg widget to enable usage of symbols (svg sprite) via svg > use implementation + [#1851](https://github.com/luyadev/luya/issues/1851) Add string helper method highlightWord() to highlight a given word withing a string.