From ddd38e6c45cb9d5ef609fc114c37109fecdcf1f6 Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Tue, 16 May 2017 10:49:04 +0200 Subject: [PATCH 1/6] Added support for sites with a single locale --- elementtypes/TranslateElementType.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/elementtypes/TranslateElementType.php b/elementtypes/TranslateElementType.php index 5f14845..7ecc248 100644 --- a/elementtypes/TranslateElementType.php +++ b/elementtypes/TranslateElementType.php @@ -241,6 +241,12 @@ public function getSources($context = null) */ public function getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context, $includeContainer, $showCheckboxes) { + // If the site only has 1 locale enabled, set the translated locale to the primary (and only) locale + if(empty($criteria['locale'])) { + $localization = new LocalizationService(); + $criteria['locale'] = $localization->getPrimarySiteLocale(); + } + $variables = array( 'viewMode' => $viewState['mode'], 'context' => $context, From 134e9c7b36385d94e798c12d862706f75a3d2bec Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Tue, 16 May 2017 10:54:47 +0200 Subject: [PATCH 2/6] Use craft()->i18n to get the primary locale --- elementtypes/TranslateElementType.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/elementtypes/TranslateElementType.php b/elementtypes/TranslateElementType.php index 7ecc248..f3c0ab0 100644 --- a/elementtypes/TranslateElementType.php +++ b/elementtypes/TranslateElementType.php @@ -243,8 +243,7 @@ public function getIndexHtml($criteria, $disabledElementIds, $viewState, $source { // If the site only has 1 locale enabled, set the translated locale to the primary (and only) locale if(empty($criteria['locale'])) { - $localization = new LocalizationService(); - $criteria['locale'] = $localization->getPrimarySiteLocale(); + $criteria['locale'] = craft()->i18n->getPrimarySiteLocale() } $variables = array( From 0abbcf51e8160accc6ab3faeaca7815c9caa6de1 Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Tue, 16 May 2017 10:56:27 +0200 Subject: [PATCH 3/6] Typo --- elementtypes/TranslateElementType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elementtypes/TranslateElementType.php b/elementtypes/TranslateElementType.php index f3c0ab0..7455e60 100644 --- a/elementtypes/TranslateElementType.php +++ b/elementtypes/TranslateElementType.php @@ -243,7 +243,7 @@ public function getIndexHtml($criteria, $disabledElementIds, $viewState, $source { // If the site only has 1 locale enabled, set the translated locale to the primary (and only) locale if(empty($criteria['locale'])) { - $criteria['locale'] = craft()->i18n->getPrimarySiteLocale() + $criteria['locale'] = craft()->i18n->getPrimarySiteLocale(); } $variables = array( From e697125721f25deed1f64d723c47c4ae1b6e2ca4 Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Tue, 16 May 2017 11:01:33 +0200 Subject: [PATCH 4/6] Version bump to 0.4.3 and changelog update --- README.md | 3 +++ TranslatePlugin.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 276868f..4679906 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ phpunit --bootstrap craft/app/tests/bootstrap.php --configuration craft/plugins/ Changelog ================= +###0.4.3### +- Fixed a bug where translations wouldn't be shown on sites with only 1 locale defined + ###0.4.2### - Add node_modules to excluded vendor folders (thanks to @tcsehv) diff --git a/TranslatePlugin.php b/TranslatePlugin.php index 0100a24..7cf2341 100644 --- a/TranslatePlugin.php +++ b/TranslatePlugin.php @@ -30,7 +30,7 @@ public function getName() */ public function getVersion() { - return '0.4.2'; + return '0.4.3'; } /** From 38acd814155ce8c221278ffaa50d790643cbaed3 Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Tue, 16 May 2017 11:11:58 +0200 Subject: [PATCH 5/6] PSR-2 code styling --- elementtypes/TranslateElementType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elementtypes/TranslateElementType.php b/elementtypes/TranslateElementType.php index 7455e60..4c468c8 100644 --- a/elementtypes/TranslateElementType.php +++ b/elementtypes/TranslateElementType.php @@ -242,7 +242,7 @@ public function getSources($context = null) public function getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context, $includeContainer, $showCheckboxes) { // If the site only has 1 locale enabled, set the translated locale to the primary (and only) locale - if(empty($criteria['locale'])) { + if (empty($criteria['locale'])) { $criteria['locale'] = craft()->i18n->getPrimarySiteLocale(); } From c89b8f61583311bbc56576691e494691584a554e Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Tue, 16 May 2017 11:14:21 +0200 Subject: [PATCH 6/6] Added credits to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4679906..fb6627f 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ phpunit --bootstrap craft/app/tests/bootstrap.php --configuration craft/plugins/ Changelog ================= ###0.4.3### -- Fixed a bug where translations wouldn't be shown on sites with only 1 locale defined +- Fixed a bug where translations wouldn't be shown on sites with only 1 locale defined (thanks to @janhenckens) ###0.4.2### - Add node_modules to excluded vendor folders (thanks to @tcsehv)