mohammad-zarifiyan/laravel-locale-kit
Composer 安装命令:
composer require mohammad-zarifiyan/laravel-locale-kit
包简介
A Laravel package that provides structured locale metadata alongside traditional translation files.
README 文档
README
Laravel Locale Kit provides locale metadata for Laravel applications. It allows you to retrieve locale-specific information such as writing direction, number symbols, punctuation, calendar system, and other locale definitions.
The package also supports custom locale definitions and locale aliases.
Installation
Install the package via Composer:
composer require mohammad-zarifiyan/laravel-locale-kit:^1.0
Publishing Locale Definitions
To publish the predefined locale definition files into your application:
php artisan vendor:publish --provider="MohammadZarifiyan\LaravelLocaleKit\LocaleKitProvider" --tag="locale-kit-locales"
The files will be published to locales directory. You can edit the published files or add your own locale definitions.
Each locale definition file must be named using a locale identifier in the following format:
language_COUNTRY.json
Examples:
en_US.json
en_GB.json
fa_IR.json
fa_AF.json
ar_SA.json
You can edit the published files or add your own locale definition files.
Usage
alias()
Registers an alias for a locale identifier.
use MohammadZarifiyan\LaravelLocaleKit\LocaleKit; LocaleKit::alias('fa', 'fa_IR'); LocaleKit::alias('en', 'en_US'); LocaleKit::alias('ar', 'ar_SA');
In this example, fa, en, and ar become aliases for the locale identifiers fa_IR, en_US, and ar_SA.
After registering an alias, any method that accepts a locale can use either the alias or the full locale identifier.
For example:
use MohammadZarifiyan\LaravelLocaleKit\LocaleKit; LocaleKit::get('direction', 'fa');
is equivalent to:
use MohammadZarifiyan\LaravelLocaleKit\LocaleKit; LocaleKit::get('direction', 'fa_IR');
getIdentifier()
Returns the locale identifier for a locale or alias.
use MohammadZarifiyan\LaravelLocaleKit\LocaleKit; LocaleKit::getIdentifier('fa'); // fa_IR LocaleKit::getIdentifier('en'); // en_US LocaleKit::getIdentifier('fa_AF'); // fa_AF
allLocales()
Returns all locales available in Laravel's lang directory.
use MohammadZarifiyan\LaravelLocaleKit\LocaleKit; $locales = LocaleKit::allLocales();
Example result:
[
'en',
'fa',
'ar',
]
supportedLocales()
Returns all locale definition files available to the package, including custom locale definitions.
use MohammadZarifiyan\LaravelLocaleKit\LocaleKit; $locales = LocaleKit::supportedLocales();
Example result:
[
'en_US',
'en_GB',
'fa_IR',
'ar_SA',
]
get()
Returns a value from a locale definition.
use MohammadZarifiyan\LaravelLocaleKit\LocaleKit; LocaleKit::get('calendar_system', 'en_US');
Result:
'gregorian'
translateNumbers()
Converts numbers to the target locale.
use MohammadZarifiyan\LaravelLocaleKit\LocaleKit; LocaleKit::translateNumbers('۱۲۳۴۵۶ is my number.', 'en_US');
Result:
123456 is my number.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2026-06-25