承接 marvinrabe/laravel-intl 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

marvinrabe/laravel-intl

Composer 安装命令:

composer require marvinrabe/laravel-intl

包简介

Easy to use internationalization functions for Laravel

README 文档

README

Easy to use internationalization functions for Laravel and Lumen based on various libraries for easy retrieval of localized values and formatting of numeric values into their localized patterns.

This is a fork of Propaganistas/Laravel-Intl. I will continue to maintain this package because I use it extensively in my own projects.

Feel free to provide pull requests. I will include them as fast as possible!

💥 Upgrade from Propaganistas/Laravel-Intl

Probably you see this message all the time when installing Composer dependencies:

Package propaganistas/laravel-intl is abandoned, you should avoid using it. No replacement was suggested.

Don't worry! This is the replacement you seek.

In composer.json change requirement from propaganistas/laravel-intl to:

"marvinrabe/laravel-intl": "^1.0",

I changed the namespace of this package (because I am selfish 🤪). In your project search for Propaganistas and replace it with MarvinRabe.

Thanks for migrating to this package!

Overview

Installation

Run the following command to install the latest version of the package

composer require marvinrabe/laravel-intl

Laravel

If you don't use auto-discovery, open up your app config and add the Service Provider to the $providers array:

'providers' => [
   ...
   MarvinRabe\LaravelIntl\IntlServiceProvider::class,
],

Lumen

In bootstrap/app.php, register the Service Provider

$app->register(MarvinRabe\LaravelIntl\IntlServiceProvider::class);

Usage

Note: always use the helper functions or Facades, or make use of dependency injection.

Country

Output localized country names.

use MarvinRabe\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', ...]

Currency

Output localized currency names and format currency amounts into their localized pattern.

use MarvinRabe\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 MarvinRabe\LaravelIntl\Facades\Currency;

// Application locale: nl
Currency::parse('€ 1.234,50'); // 1234.5
// Application locale: nl
currency()->parse('€ 1.234,50'); // 1234.5

Date

Just use Illuminate\Support\Facades\Date.

Additional methods are also available to output localized common date formats. E.g. toShortDateString():

  • Locale "en": 1/31/2018
  • Locale "nl": 31-01-2018
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();

Language

Output localized language names.

use MarvinRabe\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', ...]

Number

Output localized numeric values into their localized pattern.

use MarvinRabe\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 MarvinRabe\LaravelIntl\Facades\Number;

// Application locale: fr
Number::parse('1 000'); // 1000
number()->parse('1,5'); // 1.5

Changing locales

Ever feel the need to use a locale other than the current application locale? You can temporarily use another locale by using the usingLocale() method.

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 setLocale() on the helper function or Facade. Usually you'd set this in the boot() method of a ServiceProvider.

marvinrabe/laravel-intl 适用场景与选型建议

marvinrabe/laravel-intl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.15k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2020 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「i18n」 「intl」 「l10n」 「laravel」 「internationalization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 marvinrabe/laravel-intl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 marvinrabe/laravel-intl 我们能提供哪些服务?
定制开发 / 二次开发

基于 marvinrabe/laravel-intl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 19.15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-04