Skip to content

Commit a309af0

Browse files
committed
fix: usage of defaultLocale property
Need to use the function packageDefaultLocale to prevent problems when defaultLocale is not defined Signed-off-by: Vitor Mattos <[email protected]>
1 parent f988a16 commit a309af0

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/helpers.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ function current_path_locale($page): string
2929
{
3030
$path = trim($page->getPath(), '/');
3131

32-
$default_locale = $page->defaultLocale ?? packageDefaultLocale();
33-
3432
/**
3533
* - [a-z]{2,3} language code
3634
* - [A-Z]{2} region code
@@ -41,7 +39,7 @@ function current_path_locale($page): string
4139

4240
preg_match($locale_regex, $path, $matches);
4341

44-
return $matches['locale'] ?? $default_locale;
42+
return $matches['locale'] ?? packageDefaultLocale();
4543
}
4644

4745
/**
@@ -56,12 +54,12 @@ function translate_path($page, ?string $target_locale = null): string
5654
$current_locale = current_path_locale($page);
5755

5856
$partial_path = match (true) {
59-
$current_locale === $page->defaultLocale => $page->getPath(),
57+
$current_locale === packageDefaultLocale($page) => $page->getPath(),
6058
default => substr($page->getPath(), strlen($current_locale) + 1),
6159
};
6260

6361
return match (true) {
64-
$target_locale === $page->defaultLocale => "{$partial_path}",
62+
$target_locale === packageDefaultLocale($page) => "{$partial_path}",
6563
default => "/{$target_locale}{$partial_path}",
6664
};
6765
}
@@ -89,7 +87,7 @@ function locale_path($page, string $partial_path, ?string $target_locale = null)
8987
$partial_path = '/'.trim($partial_path, '/');
9088

9189
return match (true) {
92-
$target_locale === $page->defaultLocale => $partial_path,
90+
$target_locale === packageDefaultLocale($page) => $partial_path,
9391
default => "/{$target_locale}{$partial_path}"
9492
};
9593
}

tests/_Mocks/PageMock.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ class PageMock
1212

1313
public array $localization = [];
1414

15-
public function __construct()
16-
{
17-
$this->defaultLocale = packageDefaultLocale();
18-
}
19-
2015
public function setPath(string $path): static
2116
{
2217
$this->path = '/'.trim($path, '/');

0 commit comments

Comments
 (0)