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
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Symfony\Component\Intl\Countries;
|
||||
|
||||
class Address extends Model
|
||||
{
|
||||
@@ -18,9 +19,18 @@ class Address extends Model
|
||||
|
||||
public function getCountryNameAttribute(): ?string
|
||||
{
|
||||
$name = $this->country ? $this->country->name : null;
|
||||
if (! $this->country) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $name;
|
||||
try {
|
||||
return Countries::getName(
|
||||
$this->country->code,
|
||||
app()->getLocale()
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return $this->country->name;
|
||||
}
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
|
||||
Reference in New Issue
Block a user