Skip to content

Commit

Permalink
Add language path type
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Mar 18, 2024
1 parent 92ba1e1 commit fb4ca71
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Model/Config/PathType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ enum PathType: string
private const PHRASES = [
self::StoreCode->value => 'Store Code',
self::CountryCode->value => 'Country Code',
self::LanguageCode->value => 'Language Code',
self::LocaleUnderscore->value => 'Locale Code (_)',
self::LocaleHyphen->value => 'Locale Code (-)',
self::Custom->value => 'Custom',
];

case StoreCode = 'store_code';
case CountryCode = 'country_code';
case LanguageCode = 'language_code';
case LocaleUnderscore = 'locale_underscore';
case LocaleHyphen = 'locale_hyphen';
case Custom = 'custom';
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ bin/magento setup:upgrade

The module allows to replace the store code in url with the following options:

- Country Code, e.g: fr
- Locale Code (separated with a hyphen), e.g: fr-fr
- Locale Code (separated with an underscore), e.g: fr_fr
- Country Code, e.g: be
- Language Code, e.g: fr
- Locale Code (separated with a hyphen), e.g: fr-be
- Locale Code (separated with an underscore), e.g: fr_be
- Custom (you can setup the path of your choice), e.g: emea

## Settings
Expand Down
2 changes: 2 additions & 0 deletions Service/PathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use function explode;
use function implode;
use function strtok;
use function strtolower;

class PathResolver
Expand All @@ -24,6 +25,7 @@ public function resolve(ScopeInterface|StoreInterface $scope): string
return strtolower(match ($this->config->getStorePathType()) {
PathType::StoreCode => $scope->getCode(),
PathType::CountryCode => $this->config->getCountry($scope),
PathType::LanguageCode => strtok($this->config->getLocale($scope), '_'),
PathType::LocaleUnderscore => $this->config->getLocale($scope),
PathType::LocaleHyphen => implode('-', explode('_', $this->config->getLocale($scope))),
PathType::Custom => $this->config->getCustomPathMapper()[(int)$scope->getId()] ?? $scope->getCode(),
Expand Down

0 comments on commit fb4ca71

Please sign in to comment.