agenter-labs/laravel-language 问题修复 & 功能扩展

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

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

agenter-labs/laravel-language

Composer 安装命令:

composer require agenter-labs/laravel-language

包简介

Language switcher package for Laravel

README 文档

README

Downloads StyleCI Quality License

This package allows switching locale easily on Laravel projects. It's so simple to use, once it's installed, your App locale will change only by passing routes into SetLanguage middleware.

Top features:

  • Change automatically app locale depending on user browser configuration
  • Language flags built-in for easy implementation
  • Get language name like 'English' or 'Español' from codes such as 'en' or 'es'
  • Option to choose short (en) or long (en-GB) language code
  • Store locale on users table
  • Restrict users to set languages you don't have translations
  • Helper functions for clean, simple and easy to read API
  • Supports Carbon and Date packages

Getting Started

1. Install

Run the following command:

composer require akaunting/laravel-language

2. Register (for Laravel < 5.5)

Register the service provider in config/app.php

Akaunting\Language\Provider::class,

Add alias if you want to use the facade.

'Language'   => Akaunting\Language\Facade::class,

3. Publish

Publish config, migration and blade files.

php artisan vendor:publish --tag=language

4. Migrate

Add locale column to users table:

php artisan migrate

5. Configure

Default values can be modified also on config/language.php

Keys

  • route: Makes route available
  • carbon: Sets briannesbitt/carbon translator language
  • date: Sets jenssegers/date translator language
  • home: Make home route available
  • auto: Sets language automatically depending on user's browser config
  • prefix: Prefix of routes URI to set locale
  • middleware: default middleware to set locale
  • controller: default controller to handle locale
  • flags: Settings such as width, class etc for flags
  • mode: The language code and name mode
  • allowed: Allowed language codes
  • all: Available language names and codes

Usage

Middleware

All routes in which you want to set language should be under the language middleware to set at each request to App locale.

Route::group(['middleware' => 'language'], function () {

    // Here your routes

});

URL

  • Via URL with return home: /languages/{locale}/home
  • Via URL with return back: /languages/{locale}/back

Tip: /languages prefix can be changed from config/language.php

Methods

language()->allowed()

Returns an array with [$code => $name] for all allowed languages of config. Example usage on blade:

@foreach (language()->allowed() as $code => $name)
    <a href="{{ language()->back($code) }}">{{ $name }}</a>
@endforeach

language()->flags()

Returns an output with flags for all allowed languages of config. Output can be changed from resources/views/vendor/language folder

language()->flag()

Returns the flag of the current locale. Output can be changed from resources/views/vendor/language folder

language()->names($codes = null)

Get an array like [$code => $name] from an array of only $codes.

language()->codes($langs = null)

Get an array like [$name => $code] from an array of only $langs.

language()->back($code)

Returns the URL to set up language and return back: back()

Also if you prefer to use directly route() function you can use it as following code:

{{ route('language::back', ['locale' => $code]) }}

language()->home($code)

Returns the URL to set language and return to home: url('/')

Also if you prefer to use directly route() function you can use it as following code:

{{ route('language::home', ['locale' => $code]) }}

language()->getName($code = 'default')

Returns the language name of $code if specified or the current language set if not.

Tip: Use app()->getLocale() to get the current locale

language()->getCode($name = 'default')

Returns the language code of $name if specified or the current language set if not.

Changelog

Please see Releases for more information what has changed recently.

Contributing

Pull requests are more than welcome. You must follow the PSR coding standards.

Security

If you discover any security related issues, please email security@akaunting.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see LICENSE for more information.

agenter-labs/laravel-language 适用场景与选型建议

agenter-labs/laravel-language 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.85k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「language」 「laravel」 「switcher」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 agenter-labs/laravel-language 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 agenter-labs/laravel-language 我们能提供哪些服务?
定制开发 / 二次开发

基于 agenter-labs/laravel-language 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-01