cosninix/sin
Composer 安装命令:
composer require cosninix/sin
包简介
Simple internationalization for Laravel
README 文档
README
Sin takes a whole new approach to internationalization (i18n) that is useful for simple projects or when the developer can make fast translations on the fly. The way it works is very simple: Just define a string in a special format containg all the languages, as follows:
"en::What is your name?|nl::Wat je is naam?|de::Wie heisst du?|fr::Comment t'appelles-tu?"
Because Sin uses strings only, it can be used in code, but also in databases, yaml or json files or anywhere where a string is presented to the user.
Sin integrates seemless with Laravel and uses the old and new laravel internationalization styles so it can be seen as an add-on to this mechanism.
Sin is most useful for bi-lingual applications (like dutch/english) where the developer includes immediate translations while coding.
Installation
composer install cosninix/sin
The sin package creates the Sin facade alias, a serviceprovider and a helper function
Basic usage
echo app('Sin')->lang("nl::via de serviceprovider|en::via the serviceprovider");
echo Sin::lang("nl::via de Sin facade deze keer|en::through the Sin facade this time");
// three underscores
echo ___("nl::via de helper function|en::works with the helper function");
and also in blade using the @slang directive
<h1>@slang('nl::blade constructie|en::blade construct')</h1>
If the sin syntax is not found, Sin passes the string as is. The syntax is triggered on all strings beginning wih the XX:: format.
Sin::lang('passed without alterations %f'); --> 'passed without alterations %f'
Sin runs every result (where syntax is triggered!) through sprintf:
Sin::lang("en::We have %d smartphones in stock|nl::nu %d smartphones op voorraad",20);
Of course, Sin is not limited to php code. You can use Sin in yaml or json files as long as you pass it through Sin before presenting it.
list: { options: [ 1, 3 ], text: [ "nl::kies 1|en::choose 1", "nl::Neem er 3|en::Take 3" ] }
For instance this could be done with database values in blade:
<h1>@slang( $stock->article_name )</h1>
Laravel integration
Sin takes the app.locale config as the default language and app.fallback_locale as fallback. If you change the app language using
App::setLocale('nl');
If the current language is not found, the fallback locale is used.
You can prepare for Laravel translations by giving an additional laravel key that can be used with the traditional @lang construct:
Sin::lang('nl::Nederlands|en::English|@@::language_key);
If the language_key exists in the laravel translations, this takes priority, otherwise the Sin translations are used. So you can add traditional translations later on.
cosninix/sin 适用场景与选型建议
cosninix/sin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.75k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「i18n」 「library」 「internationalization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cosninix/sin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cosninix/sin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cosninix/sin 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use i18n translation PHP class for multi-language websites
A custom URL rule class for Yii 2 which allows to create translated URL rules
Easy to use internationalization functions for Laravel
List of all countries with names and ISO 3166-1 codes in all languages and data formats for Laravel
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Inbox pattern process implementation for your Laravel Applications
统计信息
- 总下载量: 2.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-08-10