mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-16 22:05:20 +00:00
feat: localize country names in PDFs via symfony/intl (#681)
Ports #639 to 3.x — the original targets the now feature-frozen 2.x line. Address::country_name now resolves the localized country name for the current app locale via Symfony\Component\Intl\Countries, falling back to the stored name on lookup failure. Adds symfony/intl + a unit test. Co-authored-by: Lukas Selch <selchlukas@icloud.com>
This commit is contained in:
committed by
GitHub
parent
acbb1f040c
commit
217deb0bf9
57
tests/Unit/AddressCountryLocalizationTest.php
Normal file
57
tests/Unit/AddressCountryLocalizationTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Address;
|
||||
use App\Models\Country;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
it('returns localized country name for German locale', function () {
|
||||
App::setLocale('de');
|
||||
|
||||
$address = Address::factory()->create([
|
||||
'country_id' => Country::where('code', 'DE')->first()->id,
|
||||
]);
|
||||
|
||||
expect($address->country_name)->toBe('Deutschland');
|
||||
});
|
||||
|
||||
it('returns localized country name for French locale', function () {
|
||||
App::setLocale('fr');
|
||||
|
||||
$address = Address::factory()->create([
|
||||
'country_id' => Country::where('code', 'DE')->first()->id,
|
||||
]);
|
||||
|
||||
expect($address->country_name)->toBe('Allemagne');
|
||||
});
|
||||
|
||||
it('returns null when address has no country', function () {
|
||||
$address = Address::factory()->create([
|
||||
'country_id' => null,
|
||||
]);
|
||||
|
||||
expect($address->country_name)->toBeNull();
|
||||
});
|
||||
|
||||
it('falls back to database name when intl lookup fails', function () {
|
||||
App::setLocale('de');
|
||||
|
||||
// Create a country with a code that won't be found in ICU data
|
||||
$country = new Country;
|
||||
$country->timestamps = false;
|
||||
$country->code = 'XX';
|
||||
$country->name = 'Unknown Land';
|
||||
$country->phonecode = 0;
|
||||
$country->save();
|
||||
|
||||
$address = Address::factory()->create([
|
||||
'country_id' => $country->id,
|
||||
]);
|
||||
|
||||
expect($address->country_name)->toBe('Unknown Land');
|
||||
});
|
||||
Reference in New Issue
Block a user