cosninix/sin 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

cosninix/sin

最新稳定版本:v2.0.04

Composer 安装命令:

composer require cosninix/sin

包简介

Simple internationalization for Laravel

README 文档

README

GitHub Release GitHub Release Total Downloads License Actions Status

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.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-10