jsor/string-formatter
最新稳定版本:v2.0.0
Composer 安装命令:
composer require jsor/string-formatter
包简介
Localized formatting of personal names, addresses and telephone numbers.
关键字:
README 文档
README
Localized formatting of personal names, addresses and telephone numbers.
Note: At the moment, only a NameFormatter is available. Address and telephone formatters will follow.
Installation
Install the latest version with Composer.
composer require jsor/string-formatter
Check the Packagist page for all available versions.
NameFormatter
The NameFormatter formats the appropriate representation of a person’s name for a locale by the given name parts.
use Jsor\NameFormatter; $nameParts = [ 'given_name' => 'John', 'family_name' => 'Doe', 'salutation' => 2 // name_mr ]; $enUsFormatter = new NameFormatter('en_US'); echo $enUsFormatter->format($nameParts)."\n"; $deDeFormatter = new NameFormatter('de_DE'); echo $deDeFormatter->format($nameParts)."\n"; $zhCnFormatter = new NameFormatter('zh_CN'); echo $zhCnFormatter->format($nameParts)."\n";
The above example will output:
Mr. John Doe
Herr John Doe
Doe John 先生
A custom pattern can be passed as the second argument to the constructor.
use Jsor\NameFormatter; $formatter = new NameFormatter('en_US', '%d%t%g%t%m%t%f'); echo $formatter->format([ 'given_name' => 'John', 'family_name' => 'Doe', 'salutation' => 'Mr.', ]);
The above example will output:
Mr. John Doe
Pattern
The pattern argument can contain any combination of characters and field descriptors.
The following field descriptor are supported.
%fFamily names.%FFamily names in uppercase.%gFirst given name.%GFirst given initial.%lFirst given name with latin letters. In some cultures, eg on Taiwan it is customary to also have a first name written with Latin letters, although the rest of the name is written in another script.%oOther shorter name, eg. "Bill".%mAdditional given names.%MInitials for additional given names.%pProfession.%dSalutation, supporting the FDCC-sets conventions, with1forname_gen,2forname_mr,3forname_mrs,4forname_miss,5forname_ms.%sFull Salutation, such as "Doctor".%SAbbreviated salutation, such as "Mr." or "Dr."%tIf the preceding field descriptor resulted in an empty string, then the empty string, else a space.
Values
The array argument passed to format() can define a value for each field
descriptor. The keys can be either the descriptor character or a named key.
The following keys are supported.
family_name,family_namesorf(for%f)family_name_in_uppercase,family_names_in_uppercaseorF(for%F)given_name,given_namesorg(for%g)given_initial,given_initialsorG(for%G)given_name_with_latin_letters,given_names_with_latin_lettersorl(for%l)other_shorter_name,other_shorter_namesoro(for%o)additional_given_name,additional_given_namesorm(for%m)initials_for_additional_given_name,initials_for_additional_given_namesorM(for%M)profession,professionsorp(for%p)salutation,salutationsord(for%d)full_salutation,full_salutationsors(for%s)abbreviated_salutation,abbreviated_salutationsorS(for%S)
License
Copyright (c) 2015-2022 Jan Sorgalla. Released under the MIT license.
统计信息
- 总下载量: 17.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-09