Skip to content
This repository was archived by the owner on Aug 7, 2022. It is now read-only.

Commit 38a873e

Browse files
authored
Merge pull request #6 from luisprmat/main
Update to Laravel 9
2 parents 1281569 + 86324d8 commit 38a873e

File tree

7 files changed

+58
-38
lines changed

7 files changed

+58
-38
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
}
1212
],
1313
"require": {
14-
"laravel-lang/lang": "^10.1"
14+
"laravel-lang/lang": "^10.4",
15+
"laravel-lang/attributes": "^1.0"
1516
},
1617
"require-dev": {
1718
"orchestra/testbench": "^6.20"

src/Console/InstallCommand.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ public function handle()
3737
return;
3838
}
3939

40-
(new Filesystem)->ensureDirectoryExists(resource_path("lang/{$locale}"));
40+
(new Filesystem)->ensureDirectoryExists(lang_path("{$locale}"));
4141

42-
copy(base_path("vendor/laravel-lang/lang/locales/{$locale}/auth.php"), resource_path("lang/{$locale}/auth.php"));
43-
copy(base_path("vendor/laravel-lang/lang/locales/{$locale}/pagination.php"), resource_path("lang/{$locale}/pagination.php"));
44-
copy(base_path("vendor/laravel-lang/lang/locales/{$locale}/passwords.php"), resource_path("lang/{$locale}/passwords.php"));
42+
copy(base_path("vendor/laravel-lang/lang/locales/{$locale}/auth.php"), lang_path("{$locale}/auth.php"));
43+
copy(base_path("vendor/laravel-lang/lang/locales/{$locale}/pagination.php"), lang_path("{$locale}/pagination.php"));
44+
copy(base_path("vendor/laravel-lang/lang/locales/{$locale}/passwords.php"), lang_path("{$locale}/passwords.php"));
4545

4646
if ($this->option('inline')) {
47-
copy(base_path("vendor/laravel-lang/lang/locales/{$locale}/validation-inline.php"), resource_path("lang/{$locale}/validation.php"));
47+
copy(base_path("vendor/laravel-lang/lang/locales/{$locale}/validation-inline.php"), lang_path("{$locale}/validation.php"));
4848
} else {
49-
copy(base_path("vendor/laravel-lang/lang/locales/{$locale}/validation.php"), resource_path("lang/{$locale}/validation.php"));
49+
copy(base_path("vendor/laravel-lang/lang/locales/{$locale}/validation.php"), lang_path("{$locale}/validation.php"));
5050
$this->mergeAttributes($locale);
5151
}
5252

@@ -115,7 +115,7 @@ private function loadJsonFile($locale, $packages = [])
115115

116116
$modifiedJson = json_encode($modify, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
117117

118-
File::put(resource_path("lang/{$locale}.json"), $modifiedJson);
118+
File::put(lang_path("{$locale}.json"), $modifiedJson);
119119
}
120120

121121
/**
@@ -158,7 +158,7 @@ protected function discoveredPackages(): array
158158

159159
private function mergeAttributes($locale)
160160
{
161-
$attributesSource = base_path("vendor/laravel-lang/lang/locales/{$locale}/validation-attributes.php");
161+
$attributesSource = base_path("vendor/laravel-lang/attributes/locales/{$locale}/validation.php");
162162
if (!File::exists($attributesSource)) return;
163163

164164
$attributes = File::get($attributesSource);
@@ -173,7 +173,8 @@ private function mergeAttributes($locale)
173173
PHP;
174174
$attributes = Str::replace($endOfLine, "];", $attributes);
175175
$split = explode($separator, $attributes);
176-
$this->replaceInFile("];", $split[1], resource_path("lang/{$locale}/validation.php"));
176+
177+
$this->replaceInFile("];", $split[1], lang_path("{$locale}/validation.php"));
177178
}
178179

179180
/**

tests/Feature/CopyPhpFilesTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function tearDown(): void
2222
{
2323
parent::tearDown();
2424
File::deleteDirectory(config_path());
25-
File::deleteDirectory(resource_path());
25+
File::deleteDirectory(base_path('lang'));
2626
File::delete(base_path('composer.json'));
2727
}
2828

@@ -31,7 +31,7 @@ function merge_attributes_in_validation()
3131
{
3232
$this->artisan('lang:add');
3333

34-
$this->assertTrue(File::exists(resource_path('lang/es/validation.php')));
34+
$this->assertTrue(File::exists(lang_path('es/validation.php')));
3535

3636
$expected = <<<PHP
3737
<?php
@@ -51,10 +51,11 @@ function merge_attributes_in_validation()
5151
],
5252
];
5353
54+
5455
PHP;
5556
$this->assertEquals(
5657
$expected,
57-
File::get(resource_path('lang/es/validation.php'))
58+
File::get(lang_path('es/validation.php'))
5859
);
5960
}
6061

@@ -63,7 +64,7 @@ function merge_attributes_in_validation_other_language()
6364
{
6465
$this->artisan('lang:add xx_GB');
6566

66-
$this->assertTrue(File::exists(resource_path('lang/xx_GB/validation.php')));
67+
$this->assertTrue(File::exists(lang_path('xx_GB/validation.php')));
6768

6869
$expected = <<<PHP
6970
<?php
@@ -86,7 +87,7 @@ function merge_attributes_in_validation_other_language()
8687
PHP;
8788
$this->assertEquals(
8889
$expected,
89-
File::get(resource_path('lang/xx_GB/validation.php'))
90+
File::get(lang_path('xx_GB/validation.php'))
9091
);
9192
}
9293
}

tests/Feature/DiscoverPackagesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected function tearDown(): void
2020
{
2121
parent::tearDown();
2222
File::deleteDirectory(config_path());
23-
File::deleteDirectory(resource_path());
23+
File::deleteDirectory(base_path('lang'));
2424
File::delete(base_path('composer.json'));
2525
}
2626

tests/Feature/InstallLanguageTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,30 @@ protected function tearDown(): void
2222
{
2323
parent::tearDown();
2424
File::deleteDirectory(config_path());
25-
File::deleteDirectory(resource_path());
25+
File::deleteDirectory(base_path('lang'));
2626
File::delete(base_path('composer.json'));
2727
}
2828

2929
/** @test */
3030
function it_installs_supported_language()
3131
{
32-
$this->assertFalse(File::exists(resource_path('lang/xx_GB')));
33-
$this->assertFalse(File::exists(resource_path('lang/xx_GB/auth.php')));
34-
$this->assertFalse(File::exists(resource_path('lang/xx_GB/passwords.php')));
35-
$this->assertFalse(File::exists(resource_path('lang/xx_GB/pagination.php')));
36-
$this->assertFalse(File::exists(resource_path('lang/xx_GB/validation.php')));
37-
$this->assertFalse(File::exists(resource_path('lang/xx_GB.json')));
32+
$this->assertFalse(File::exists(lang_path('xx_GB')));
33+
$this->assertFalse(File::exists(lang_path('xx_GB/auth.php')));
34+
$this->assertFalse(File::exists(lang_path('xx_GB/passwords.php')));
35+
$this->assertFalse(File::exists(lang_path('xx_GB/pagination.php')));
36+
$this->assertFalse(File::exists(lang_path('xx_GB/validation.php')));
37+
$this->assertFalse(File::exists(lang_path('xx_GB.json')));
3838

3939
$this->artisan('lang:add xx_GB')
4040
->expectsOutput("Language [xx_GB] installed successfully as default.")
4141
->doesntExpectOutput("Language [es] installed successfully as default.");
4242

43-
$this->assertTrue(File::exists(resource_path('lang/xx_GB')));
44-
$this->assertTrue(File::exists(resource_path('lang/xx_GB/auth.php')));
45-
$this->assertTrue(File::exists(resource_path('lang/xx_GB/passwords.php')));
46-
$this->assertTrue(File::exists(resource_path('lang/xx_GB/pagination.php')));
47-
$this->assertTrue(File::exists(resource_path('lang/xx_GB/validation.php')));
48-
$this->assertTrue(File::exists(resource_path('lang/xx_GB.json')));
43+
$this->assertTrue(File::exists(lang_path('xx_GB')));
44+
$this->assertTrue(File::exists(lang_path('xx_GB/auth.php')));
45+
$this->assertTrue(File::exists(lang_path('xx_GB/passwords.php')));
46+
$this->assertTrue(File::exists(lang_path('xx_GB/pagination.php')));
47+
$this->assertTrue(File::exists(lang_path('xx_GB/validation.php')));
48+
$this->assertTrue(File::exists(lang_path('xx_GB.json')));
4949
}
5050

5151
/** @test */
@@ -56,12 +56,12 @@ function it_installs_supported_language_with_validation_inline()
5656

5757
$this->assertStringContainsString(
5858
'El campo debe ser verdadero o falso.',
59-
File::get(resource_path('lang/es/validation.php'))
59+
File::get(lang_path('es/validation.php'))
6060
);
6161

6262
$this->assertStringNotContainsString(
6363
'El campo :attribute debe tener un valor verdadero o falso.',
64-
File::get(resource_path('lang/es/validation.php'))
64+
File::get(lang_path('es/validation.php'))
6565
);
6666
}
6767

@@ -75,11 +75,11 @@ function it_installs_spanish_language_by_default()
7575
/** @test */
7676
function it_doesnt_install_language_if_not_supported()
7777
{
78-
$this->assertFalse(File::exists(resource_path('lang/no_valid')));
78+
$this->assertFalse(File::exists(lang_path('no_valid')));
7979
$this->artisan('lang:add no-valid')
8080
->expectsOutput("Language [no-valid] is not supported!");
8181

82-
$this->assertFalse(File::exists(resource_path('lang/no_valid')));
82+
$this->assertFalse(File::exists(lang_path('no_valid')));
8383

8484
$this->artisan('lang:add es')
8585
->doesntExpectOutput("Language [es] is not supported!");
@@ -125,7 +125,7 @@ function it_installs_json_locale_only_with_base_translations()
125125
JSON;
126126
$this->assertEquals(
127127
$expected,
128-
File::get(resource_path('lang/es.json'))
128+
File::get(lang_path('es.json'))
129129
);
130130

131131
$this->artisan('lang:add xx_GB');
@@ -139,7 +139,7 @@ function it_installs_json_locale_only_with_base_translations()
139139
JSON;
140140
$this->assertEquals(
141141
$expected,
142-
File::get(resource_path('lang/xx_GB.json'))
142+
File::get(lang_path('xx_GB.json'))
143143
);
144144
}
145145

@@ -164,7 +164,7 @@ function it_installs_json_with_base_plus_discovered_packages_one()
164164
JSON;
165165
$this->assertEquals(
166166
$expected,
167-
File::get(resource_path('lang/es.json'))
167+
File::get(lang_path('es.json'))
168168
);
169169

170170
}
@@ -190,7 +190,7 @@ function it_installs_json_with_base_plus_discovered_packages_other()
190190
JSON;
191191
$this->assertEquals(
192192
$expected,
193-
File::get(resource_path('lang/es.json'))
193+
File::get(lang_path('es.json'))
194194
);
195195

196196
}
@@ -218,7 +218,7 @@ function it_installs_json_with_base_plus_discovered_packages_mixed()
218218
JSON;
219219
$this->assertEquals(
220220
$expected,
221-
File::get(resource_path('lang/es.json'))
221+
File::get(lang_path('es.json'))
222222
);
223223

224224
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
return [
4+
'attributes' => [
5+
'address' => 'dirección',
6+
'hour' => 'hora',
7+
],
8+
];
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'attributes' => [
5+
'address' => 'address',
6+
'hour' => 'hour',
7+
],
8+
];

0 commit comments

Comments
 (0)