Skip to content

Commit

Permalink
Fix #4: Add support for generation of locale based URLs (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
rustamwin committed Oct 23, 2021
1 parent f221fd4 commit a345631
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -155,6 +155,27 @@ function getUrl(UrlGeneratorInterface $urlGenerator, $parameters = [])
}
```

### Creating locale URLs

Locale based URLs can be configured the following:

```php

$urlGenerator->setLocales(['en' => 'en-US', 'ru' => 'ru-RU', 'uz' => 'uz-UZ']);
$urlGenerator->setLocaleParameterName('_locale');
```

Then that is how locale URL could be obtained for it:

```php
use Yiisoft\Router\UrlGeneratorInterface;

function getLocaleUrl(UrlGeneratorInterface $urlGenerator, string $locale)
{
return $urlGenerator->generate('test', ['_locale' => $locale]);
}
```

## Obtain current route and URI

Current route (matched last) and URI could be obtained the following:
Expand Down
6 changes: 6 additions & 0 deletions src/UrlGeneratorInterface.php
Expand Up @@ -39,4 +39,10 @@ public function generateAbsolute(string $name, array $parameters = [], string $s
public function getUriPrefix(): string;

public function setUriPrefix(string $name): void;

public function getLocales(): array;

public function setLocales(array $locales): void;

public function setLocaleParameterName(string $localeParameterName): void;
}

0 comments on commit a345631

Please sign in to comment.