diff --git a/Model/Config/PathType.php b/Model/Config/PathType.php index e157816..006a36e 100644 --- a/Model/Config/PathType.php +++ b/Model/Config/PathType.php @@ -13,6 +13,7 @@ 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', @@ -20,6 +21,7 @@ enum PathType: string case StoreCode = 'store_code'; case CountryCode = 'country_code'; + case LanguageCode = 'language_code'; case LocaleUnderscore = 'locale_underscore'; case LocaleHyphen = 'locale_hyphen'; case Custom = 'custom'; diff --git a/README.md b/README.md index 01e6cd3..b85d67b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Service/PathResolver.php b/Service/PathResolver.php index b0543ec..baae860 100644 --- a/Service/PathResolver.php +++ b/Service/PathResolver.php @@ -13,6 +13,7 @@ use function explode; use function implode; +use function strtok; use function strtolower; class PathResolver @@ -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(),