Skip to content

Commit fb4ca71

Browse files
committed
Add language path type
1 parent 92ba1e1 commit fb4ca71

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Model/Config/PathType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ enum PathType: string
1313
private const PHRASES = [
1414
self::StoreCode->value => 'Store Code',
1515
self::CountryCode->value => 'Country Code',
16+
self::LanguageCode->value => 'Language Code',
1617
self::LocaleUnderscore->value => 'Locale Code (_)',
1718
self::LocaleHyphen->value => 'Locale Code (-)',
1819
self::Custom->value => 'Custom',
1920
];
2021

2122
case StoreCode = 'store_code';
2223
case CountryCode = 'country_code';
24+
case LanguageCode = 'language_code';
2325
case LocaleUnderscore = 'locale_underscore';
2426
case LocaleHyphen = 'locale_hyphen';
2527
case Custom = 'custom';

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ bin/magento setup:upgrade
4343

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

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

5152
## Settings

Service/PathResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use function explode;
1515
use function implode;
16+
use function strtok;
1617
use function strtolower;
1718

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

0 commit comments

Comments
 (0)