senseexception / intl-bundle
针对 Symfony 的改进和简单 Intl 实现
1.1.0
2023-10-23 22:09 UTC
Requires
- php: ^8.1
- ext-intl: *
- senseexception/intl-format: ^2.3
- senseexception/intl-sort: ^2.0
- symfony/config: ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/http-foundation: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
- symfony/twig-bundle: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- doctrine/coding-standard: ^12.0
- infection/infection: ^0.27
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpunit/phpunit: ^9.6
- psalm/plugin-phpunit: ^0.18.4
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^5.15
README
针对 Symfony 的改进和简单 Intl 实现。
安装
您可以使用 Composer 安装它。
composer require senseexception/intl-bundle
如果使用 symfony/flex 的 composer 安装尚未注册该捆绑包,您需要手动将其注册到 bundles.php 中
return [ // ... Budgegeria\Bundle\IntlBundle\BudgegeriaIntlBundle::class => ['all' => true], // ... ];
配置
默认情况下,如果所需区域设置为 en_US 并且货币为 USD,则不需要添加配置。对于任何其他区域或货币,您可以在项目中添加以下配置并配置所需区域和货币值
budgegeria_intl: locale: 'de_DE' currency: 'EUR'
使用方法
格式化器
格式化器可以以两种不同的方式使用:通过过滤器和函数
过滤器
国际化文本格式化
{{ "This is the %ordinal time that the number %integer appears"|intl_format(4, 6000) }}
{# This is the 4th time that the number 6.000 appears #}
函数
国际化文本格式化
{{ intl_format("This is the %ordinal time that the number %integer appears", 4, 6000) }}
{# This is the 4th time that the number 6.000 appears #}
配置区域的货币符号
{{ currency_symbol() }}
{# € #}
排序器
配置排序器的示例
budgegeria_intl: locale: 'de_DE' currency: 'EUR' sorter: sorter_wo_locale: order_by_desc: ~ my_sorter: order_by_desc: ~ locale: 'de_DE'
my_sorter 和 sorter_wo_locale 是可自由选择的键,将用于创建新的服务 ID budgegeria_intl_bundle.sorter.my_sorter 和 budgegeria_intl_bundle.sorter.sorter_wo_locale,这些 ID 可以用作依赖项。
class Foo { /** * Injecting services "budgegeria_intl_bundle.sorter.my_sorter" or * "budgegeria_intl_bundle.sorter.sorter_wo_locale" */ public function __construct(private Budgegeria\IntlSort\Sorter\Sorter $sorter) { } public function bar(): void { $sortedArray = $this->sorter->sort(['a', 'y', 'ä']); } }
如果在 budgegeria_intl_bundle.sorter.sorter_wo_locale 中省略了区域,它将使用捆绑配置中设置的默认区域。
budgegeria_intl: locale: 'de_DE'
可用的配置
可用的配置是 Budgegeria\IntlSort\Sorter\Sorter 类的方法名称,以下划线值表示。
- enable_french_collation
- disable_french_collation
- lower_case_first
- upper_case_first
- remove_case_first
- enable_normalization_mode
- disable_normalization_mode
- enable_numeric_collation
- disable_numeric_collation
- enable_case_level
- disable_case_level
- non_ignorable_alternate_handling
- shifted_alternate_handling
- primary_strength
- secondary_strength
- tertiary_strength
- quaternary_strength
- identical_strength
- keep_keys
- omit_keys
- order_by_asc
- order_by_desc
- order_by_keys
- order_by_values
- null_first
- null_last
- remove_null_position
您可能正在使用 Intl-Sort 的较旧版本,其中尚未存在这些方法。有关方法的更多信息,请参阅 排序器文档。