在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Propaganistas/Laravel-Intl开源软件地址(OpenSource Url):https://github.com/Propaganistas/Laravel-Intl开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Laravel IntlEasy to use internationalization functions for Laravel 5 and Lumen based on various libraries for easy retrieval of localized values and formatting of numeric values into their localized patterns. OverviewInstallationRun the following command to install the latest version of the package composer require propaganistas/laravel-intl LaravelIf you don't use auto-discovery, open up your app config and add the Service Provider to the 'providers' => [
...
Propaganistas\LaravelIntl\IntlServiceProvider::class,
], LumenIn $app->register(Propaganistas\LaravelIntl\IntlServiceProvider::class); Usage
CountryOutput localized country names. use Propaganistas\LaravelIntl\Facades\Country;
// Application locale: nl
Country::name('US'); // Verenigde Staten
Country::all(); // ['US' => 'Verenigde Staten', 'BE' => 'België', ...] // Application locale: en
country('US'); // United States
country()->all(); // ['US' => 'United States', 'BE' => 'Belgium', ...] CurrencyOutput localized currency names and format currency amounts into their localized pattern. use Propaganistas\LaravelIntl\Facades\Currency;
// Application locale: nl
Currency::name('USD'); // Amerikaanse dollar
Currency::symbol('USD'); // $
Currency::format(1000, 'USD'); // $ 1.000,00
Currency::formatAccounting(-1234, 'USD'); // (US$ 1.234,00)
Currency::all(); // ['USD' => 'Amerikaanse dollar', 'EUR' => 'Euro', ...] // Application locale: en
currency('USD'); // US Dollar
currency()->symbol('USD'); // $
currency(1000, 'USD'); // $1,000.00
currency()->all(); // ['USD' => 'US Dollar', 'EUR' => 'Euro', ...] Parse localized values into native PHP numbers. use Propaganistas\LaravelIntl\Facades\Currency;
// Application locale: nl
Currency::parse('€ 1.234,50'); // 1234.5 // Application locale: nl
currency()->parse('€ 1.234,50'); // 1234.5 DateJust use Additional methods are also available to output localized common date formats. E.g.
use Illuminate\Support\Facades\Date;
$date = Date::now(); // or carbon()->now()
$date->toShortDateString();
$date->toMediumDateString();
$date->toLongDateString();
$date->toFullDateString();
$date->toShortTimeString();
$date->toMediumTimeString();
$date->toLongTimeString();
$date->toFullTimeString();
$date->toShortDatetimeString();
$date->toMediumDatetimeString();
$date->toLongDatetimeString();
$date->toFullDatetimeString(); LanguageOutput localized language names. use Propaganistas\LaravelIntl\Facades\Language;
// Application locale: nl
Language::name('en'); // Engels
Language::all(); // ['en' => 'Engels', 'nl' => 'Nederlands', ...] // Application locale: en
language('en'); // English
language()->all(); // ['en' => 'English', 'nl' => 'Dutch', ...] NumberOutput localized numeric values into their localized pattern. use Propaganistas\LaravelIntl\Facades\Number;
// Application locale: en
Number::format(1000); // '1,000'
Number::percent('0.75'); // '75%' // Application locale: fr
number(1000); // '1 000'
number()->percent('0.75'); // '75 %' Parse localized values into native PHP numbers. use Propaganistas\LaravelIntl\Facades\Number;
// Application locale: fr
Number::parse('1 000'); // 1000
number()->parse('1,5'); // 1.5 Changing localesEver feel the need to use a locale other than the current application locale? You can temporarily use another locale by using the country()->name('US'); // United States
country()->usingLocale('nl', function($country) {
return $country->name('US');
}); // Verenigde Staten
country()->name('US'); // United States Alternatively, you can force each component individually to the preferred locale for the remainder of the application by calling the |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论