mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
44 lines
1.1 KiB
PHP
Executable File
44 lines
1.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Services\Helpers;
|
|
|
|
use Locale;
|
|
use Symfony\Component\Intl\Currencies;
|
|
use Symfony\Component\Intl\Locales;
|
|
|
|
class LocaleHelper
|
|
{
|
|
/**
|
|
* This is only used to populate settings to the database, after
|
|
* that it should be retrieved from the settings table.
|
|
*/
|
|
public static function getAppLocaleSettings(): array
|
|
{
|
|
return [
|
|
'locale' => config('app.locale', 'en'),
|
|
'currency' => CurrencyHelper::getCurrencyFromLocale(
|
|
config('app.currency_locale', 'en_US')
|
|
)['iso'] ?? 'USD',
|
|
];
|
|
}
|
|
|
|
public static function getAllLocalesAsOptions(): array
|
|
{
|
|
return collect(Locales::getNames())
|
|
->mapWithKeys(fn ($name, $locale) => [
|
|
$locale => $locale.' ('.Locale::getDisplayLanguage($locale).')',
|
|
])
|
|
->toArray();
|
|
}
|
|
|
|
public static function getAllCurrencyLocalesAsOptions(): array
|
|
{
|
|
return collect(Currencies::getNames())
|
|
->mapWithKeys(fn ($name, $iso) => [
|
|
$iso => $iso.' ('.$name.')',
|
|
])
|
|
->sort()
|
|
->toArray();
|
|
}
|
|
}
|