Skip to content

Commit

Permalink
Merge branch 'master' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrestoffe committed Dec 8, 2018
2 parents be350e7 + 7215c4f commit b531a52
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .craftplugin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"pluginName":"Locale Redirector","pluginDescription":"Automatically redirect visitors to their preferred language","pluginVersion":"1.1.0","pluginAuthorName":"Pierre Stoffe","pluginVendorName":"pierrestoffe","pluginAuthorUrl":"https://pierrestoffe.be","pluginAuthorGithub":"pierrestoffe","codeComments":"yes","pluginComponents":["services"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"}
{"pluginName":"Locale Redirector","pluginDescription":"Automatically redirect visitors to their preferred language","pluginVersion":"1.1.1","pluginAuthorName":"Pierre Stoffe","pluginVendorName":"pierrestoffe","pluginAuthorUrl":"https://pierrestoffe.be","pluginAuthorGithub":"pierrestoffe","codeComments":"yes","pluginComponents":["services"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

## [1.1.1] - 2018-12-08

### Added
- Added option to overrides URLs per language in the language switcher

## [1.1.0] - 2018-10-19

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pierrestoffe/craft-language-redirector",
"description": "Automatically redirect visitors to their preferred language",
"type": "craft-plugin",
"version": "1.1.0",
"version": "1.1.1",
"keywords": [
"craft",
"cms",
Expand Down
8 changes: 5 additions & 3 deletions src/variables/LanguageSwitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class LanguageSwitcherVariable
/**
* Get the URLs of all languages.
*
* @param array|null $urlOverrides
*
* @return array
*/
public function getUrls(): array
public function getUrls($urlOverrides = null): array
{
$queryParameterName = LanguageRedirector::getInstance()->getSettings()->queryParameterName;
$siteLanguages = LanguageRedirector::getInstance()->getSettings()->languages;
Expand All @@ -40,15 +42,15 @@ public function getUrls(): array

foreach ($siteLanguages as $language => $site) {
$languageService = new LanguageRedirectorService();
$targetUrl = $languageService->getTargetUrl($language);
$targetUrl = $urlOverrides[$language] ?? $languageService->getTargetUrl($language);
$locale = Craft::$app->i18n->getLocaleById($language);

if (null !== $targetUrl) {
$separator = false !== strpos($targetUrl, '?') ? '&' : '?';
$languages[$language]['id'] = $language;
$languages[$language]['name'] = $locale->getDisplayName(Craft::$app->language);
$languages[$language]['nativeName'] = $locale->getDisplayName($language);
$languages[$language]['url'] = $targetUrl.$separator.$queryParameterName.'='.$language;
$languages[$language]['url'] = $targetUrl . $separator . $queryParameterName . '=' . $language;
}
}

Expand Down

0 comments on commit b531a52

Please sign in to comment.