Skip to content

Commit

Permalink
Renamed helpers "route" -> "url"
Browse files Browse the repository at this point in the history
  • Loading branch information
medilies committed Jul 3, 2022
1 parent 8c7be77 commit 7e27ad0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ $page->url('/fr/contact'); // example.com/e-commerce-project/fr/contact
$page->url('es/about'); // example.com/e-commerce-project/es/about
```

### translated_route
### translated_url

When you have a page that is available in many languages. `translated_route` helps you get the equivalent translated route `href`.
When you have a page that is available in many languages. `translated_url` helps you get the equivalent translated route `href`.

```php
$page->translated_route($translation_lang)
$page->translated_url($translation_lang)
```

input/output examples:
Expand All @@ -271,17 +271,17 @@ Usage example:
```php
<nav>
@foreach(['en', 'es', 'fr'] as $translation_lang)
<a href="{{ $page->translated_route($translation_lang) }}"> {{ $translation_lang }} </a>
<a href="{{ $page->translated_url($translation_lang) }}"> {{ $translation_lang }} </a>
@endforeach
</nav>
```

### lang_route
### lang_url

To avoid hard coding the `current_lang` into `URLs`, input only what comes after the lang part of the path into this helper and it will handle the rest for you.
To avoid hard coding the `current_lang` into `URLs`, input only the partial path that comes after the lang part into this helper and it will handle the rest for you.

```php
$href = lang_route($url)
$href = lang_url($url)
```

| $url | current_lang | href |
Expand Down
12 changes: 6 additions & 6 deletions src/LoadLocalization.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function handle(Jigsaw $jigsaw)

$this->registerCurrentPathLangHelper($jigsaw);
$this->registerTranslationRetrieverHelper($jigsaw);
$this->registerTranslatedRouteHelper($jigsaw);
$this->registerLangRouteHelper($jigsaw);
$this->registerTranslatedUrlHelper($jigsaw);
$this->registerLangUrlHelper($jigsaw);
$this->registerUrlHelper($jigsaw);
}

Expand Down Expand Up @@ -76,10 +76,10 @@ function ($page): string {
);
}

private function registerTranslatedRouteHelper(Jigsaw $jigsaw)
private function registerTranslatedUrlHelper(Jigsaw $jigsaw)
{
$jigsaw->setConfig(
'translated_route',
'translated_url',
/**
* ! This helper relies on the language prefix folder structure
*/
Expand Down Expand Up @@ -110,10 +110,10 @@ function ($page, string $trans_lang, string|null $current_lang = null): string {
);
}

private function registerLangRouteHelper(Jigsaw $jigsaw)
private function registerLangUrlHelper(Jigsaw $jigsaw)
{
$jigsaw->setConfig(
'lang_route',
'lang_url',
/**
* ! This helper relies on the language prefix folder structure
*/
Expand Down

0 comments on commit 7e27ad0

Please sign in to comment.