zymawy/localizer 问题修复 & 功能扩展

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

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

zymawy/localizer

Composer 安装命令:

composer require zymawy/localizer

包简介

Pakcage to change easily default locale in laravel 5.4

README 文档

README

Localizer

StyleCI Version Scrutinizer Downloads License

What is Localizer?

Localizer is a laravel package to change easily locale on laravel projects.

It's so simple to use, once it's installed, your App locale will change only by passing routes into localizer middleare.

Top features:

  • Change automatically app locale depending on user browser configuration
  • Get language like 'Spanish' or 'English' from codes such as 'es' or 'en'.
  • Store on users database table the user locale preference
  • Restrict users to set languages you don't have translations

Getting Started

1. Install it with composer

Running the command below:

composer require aitor24/localizer

2. Register service provider

Register the localizer service provider on config/app.php.

Aitor24\Localizer\LocalizerServiceProvider::class,

Remind to add alias to use Localizer functions comfortably.

'Localizer'   => Aitor24\Localizer\Facades\LocalizerFacade::class,

3. Publish config

It will publish config file.

Running the command below:

php artisan vendor:publish --tag=localizer_config

3.1 Publish languages

Also you can publish your languages to modify or add.

php artisan vendor:publish --tag=localizer_languages

4. Migrate

Publish migrations:

php artisan vendor:publish --tag=localizer_migrations

Running the command below:

php artisan migrate

5. Configure defalt values

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

Keys

  • routes: Makes routes available.
  • carbon: Sets carbon translator language.
  • homeRoute: Make home route available.
  • set_auto_lang: Sets language automatically depending on user's browser config
  • default_lang: Default language if set_auto_lang is false or user is attempting to set an unallowed language
  • prefix: Prefix of routes URI to set locale,
  • allowed_langs: All allowed languages,
  • middleware: default middleware to set locale,

Using Localizer

Middleware

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

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

    // Here your routes

});

Changing languages

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

Tip: /lang prefix will be changed on config

Example languages view

Following there are a little code snippet of a view to select and set languages:

@foreach (Localizer::allowedLanguages() as $code => $value)
    <a href="{{ Localizer::setRouteHome($code) }}">{{ $value }}</a>
@endforeach

API

Localizer::allowedLanguages()

Returns an array with [$code => $language] for all allowed languages of config.

Localizer::addNames($codes)

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

Localizer::addCodes($lang)

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

Localizer::setRoute($code)

Used for modals or dropdowns

Returns the url to set up language and return back.

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

{{ route('localizer::setLocale', ['locale' => $code]) }}

Localizer::setRouteHome($code)

Used for language selection views

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

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

{{ route('localizer::setLocaleHome', ['locale' => $code]) }}

Localizer::getLanguage($code = App::getLocale())

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

Tip: Use App::getLocale() to get the current locale

zymawy/localizer 适用场景与选型建议

zymawy/localizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 zymawy/localizer 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-19