-
-
Notifications
You must be signed in to change notification settings - Fork 234
check overrides for parent locale when compiling language files #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
LukeTowers
merged 9 commits into
develop
from
fix-client-localization-strings-compilation
Sep 28, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
713a5e0
- get fallback locale from app's config
mjauvin 79a13be
revert using app.fallback_locale
mjauvin f247e39
remove empty lines
mjauvin dd943d2
Update modules/system/console/WinterUtil.php
LukeTowers 75f10d3
Update modules/system/console/WinterUtil.php
LukeTowers a3fa392
include all override levels when merging overrides
mjauvin 3f4e346
remove empty line
mjauvin 0b675e8
Added WinterUtilTest for compile lang testing
jaxwilko 638f74f
Tidied up test and improved comments
jaxwilko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| <?php | ||
|
|
||
| class WinterUtilTest extends TestCase | ||
| { | ||
| public function testCompileLang() | ||
| { | ||
| $defaultClient = base_path('/modules/system/lang/en/client.php'); | ||
|
|
||
| // mv file so we can inject a test | ||
| rename($defaultClient, $defaultClient . '.backup'); | ||
|
|
||
| file_put_contents($defaultClient, '<?php return [\'winter\' => \'is coming\'];'); | ||
|
|
||
| // execute compile | ||
| $this->artisan('winter:util compile lang')->execute(); | ||
|
|
||
| // validate default lang handling | ||
| $lang = file_get_contents(base_path('modules/system/assets/js/lang/lang.en.js')); | ||
| $this->assertStringContainsString('winter', $lang); | ||
| $this->assertStringContainsString('is coming', $lang); | ||
|
|
||
| // simulate override | ||
| $created = []; | ||
|
|
||
| foreach (['lang/en/system', 'lang/en-gb/system'] as $slug) { | ||
| $path = rtrim(base_path(), '/'); | ||
| foreach (explode('/', $slug) as $dir) { | ||
| $path = $path . '/' . $dir; | ||
| if (!is_dir($path)) { | ||
| mkdir($path, 0755); | ||
| $created[] = $path; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $langClient = base_path('lang/en/system/client.php'); | ||
| // handle existing file | ||
| if (file_exists($langClient)) { | ||
| rename($langClient, $langClient . '.backup'); | ||
| } | ||
|
|
||
| file_put_contents($langClient, '<?php return [\'winter\' => \'is epic\'];'); | ||
|
|
||
| $langCountryClient = base_path('lang/en-gb/system/client.php'); | ||
| // handle existing file | ||
| if (file_exists($langCountryClient)) { | ||
| rename($langCountryClient, $langCountryClient . '.backup'); | ||
| } | ||
|
|
||
| file_put_contents($langCountryClient, '<?php return [\'whats_epic\' => \'winter\'];'); | ||
|
|
||
| // execute compile | ||
| $this->artisan('winter:util compile lang')->execute(); | ||
|
|
||
| // validate override handling | ||
| $lang = file_get_contents(base_path('modules/system/assets/js/lang/lang.en.js')); | ||
| $this->assertStringContainsString('winter', $lang); | ||
| $this->assertStringContainsString('is epic', $lang); | ||
|
|
||
| // check that lang subset has included parent overrides | ||
| $lang = file_get_contents(base_path('modules/system/assets/js/lang/lang.en-gb.js')); | ||
| $this->assertStringContainsString('winter', $lang); | ||
| $this->assertStringContainsString('is epic', $lang); | ||
| $this->assertStringContainsString('whats_epic', $lang); | ||
| $this->assertStringContainsString('winter', $lang); | ||
|
|
||
| // restore | ||
| unlink($defaultClient); | ||
| rename($defaultClient . '.backup', $defaultClient); | ||
|
|
||
| foreach ([$langClient, $langCountryClient] as $client) { | ||
| unlink($client); | ||
| if (file_exists($client . '.backup')) { | ||
| rename($client . '.backup', $client); | ||
| } | ||
| } | ||
|
|
||
| foreach (array_reverse($created) as $dir) { | ||
| rmdir($dir); | ||
| } | ||
|
|
||
| // regenerate original compiled lang | ||
| $this->artisan('winter:util compile lang')->execute(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.