Skip to content

Commit 28e4c3f

Browse files
authored
Merge pull request #1 from LibreSign/fix/use-package-default-locale
Fix/use package default locale
2 parents fa7af8a + 047abcc commit 28e4c3f

File tree

6 files changed

+15
-23
lines changed

6 files changed

+15
-23
lines changed

.github/workflows/phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Setup PHP
1717
uses: shivammathur/setup-php@v2
1818
with:
19-
php-version: '8.0'
19+
php-version: '8.2'
2020
coverage: none
2121

2222
- name: Install composer dependencies

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ubuntu-latest, windows-latest]
16-
php: [8.0]
16+
php: [8.2, 8.3]
1717
stability: [prefer-lowest, prefer-stable]
1818

1919
name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"phpstan/extension-installer": "^1.1",
2020
"phpstan/phpstan-deprecation-rules": "^1.0",
2121
"phpstan/phpstan-phpunit": "^1.0",
22-
"tightenco/jigsaw": "^1.4"
22+
"tightenco/jigsaw": "^1.7"
2323
},
2424
"autoload": {
2525
"files": [

src/helpers.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
/**
1111
* @param mixed $page
12-
* @param string $text
1312
* @param ?string $current_locale
1413
* @return string The translated text if found, else returns the same given $text
1514
*/
@@ -29,8 +28,6 @@ function current_path_locale($page): string
2928
{
3029
$path = trim($page->getPath(), '/');
3130

32-
$default_locale = $page->defaultLocale ?? packageDefaultLocale();
33-
3431
/**
3532
* - [a-z]{2,3} language code
3633
* - [A-Z]{2} region code
@@ -41,12 +38,12 @@ function current_path_locale($page): string
4138

4239
preg_match($locale_regex, $path, $matches);
4340

44-
return $matches['locale'] ?? $default_locale;
41+
return $matches['locale'] ?? packageDefaultLocale();
4542
}
4643

4744
/**
4845
* @param mixed $page
49-
* @param ?string $target_locale set to the default locale if null
46+
* @param ?string $target_locale set to the default locale if null
5047
* @return string Places $target_locale code in the current path
5148
*/
5249
function translate_path($page, ?string $target_locale = null): string
@@ -56,19 +53,19 @@ function translate_path($page, ?string $target_locale = null): string
5653
$current_locale = current_path_locale($page);
5754

5855
$partial_path = match (true) {
59-
$current_locale === $page->defaultLocale => $page->getPath(),
56+
$current_locale === packageDefaultLocale($page) => $page->getPath(),
6057
default => substr($page->getPath(), strlen($current_locale) + 1),
6158
};
6259

6360
return match (true) {
64-
$target_locale === $page->defaultLocale => "{$partial_path}",
61+
$target_locale === packageDefaultLocale($page) => "{$partial_path}",
6562
default => "/{$target_locale}{$partial_path}",
6663
};
6764
}
6865

6966
/**
7067
* @param mixed $page
71-
* @param ?string $target_locale set to the default locale if null
68+
* @param ?string $target_locale set to the default locale if null
7269
* @return string Places $target_locale code in the current url
7370
*/
7471
function translate_url($page, ?string $target_locale = null): string
@@ -78,8 +75,8 @@ function translate_url($page, ?string $target_locale = null): string
7875

7976
/**
8077
* @param mixed $page
81-
* @param string $partial_path A path without the language prefix
82-
* @param ?string $target_locale uses the default locale if null
78+
* @param string $partial_path A path without the language prefix
79+
* @param ?string $target_locale uses the default locale if null
8380
* @return string A path on the target locale
8481
*/
8582
function locale_path($page, string $partial_path, ?string $target_locale = null): string
@@ -89,15 +86,15 @@ function locale_path($page, string $partial_path, ?string $target_locale = null)
8986
$partial_path = '/'.trim($partial_path, '/');
9087

9188
return match (true) {
92-
$target_locale === $page->defaultLocale => $partial_path,
89+
$target_locale === packageDefaultLocale($page) => $partial_path,
9390
default => "/{$target_locale}{$partial_path}"
9491
};
9592
}
9693

9794
/**
9895
* @param mixed $page
99-
* @param string $partial_path A path without the language prefix
100-
* @param ?string $target_locale uses the default locale if null
96+
* @param string $partial_path A path without the language prefix
97+
* @param ?string $target_locale uses the default locale if null
10198
* @return string A URL on the target locale
10299
*/
103100
function locale_url($page, string $partial_path, ?string $target_locale = null): string

tests/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tests;
44

55
use PHPUnit\Framework\TestCase as BaseTestCase;
6+
use TightenCo\Jigsaw\Container;
67

78
// use TightenCo\Jigsaw\File\ConfigFile;
89

@@ -14,8 +15,7 @@ protected function setUp(): void
1415
{
1516
parent::setUp();
1617

17-
require __DIR__.'/../vendor/tightenco/jigsaw/jigsaw-core.php';
18-
$this->app = $container;
18+
$this->app = new Container;
1919

2020
// $this->app->bind('config', function ($c) use ($cachePath) {
2121
// $config = (new ConfigFile($c['cwd'] . '/config.php', $c['cwd'] . '/helpers.php'))->config;

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)