定制 arosemena/localechooser 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

arosemena/localechooser

最新稳定版本:1.0.1

Composer 安装命令:

composer require arosemena/localechooser

包简介

Locale chooser based on common browser headers

README 文档

README

This is a simple class to detect the locale that the user preffers.

Installation

The easiest way to install this is through composer, inside your composer.json require block add

"arosemena/localechooser": "1.0.1"

and then do composer update, otherwise you could grab the class itself and autoload it with the method of your choosing.

Usage

You will need an instance of the LocaleChooser class, the constructor takes 3 parameters, first an array of the available language, ['en', 'es', 'fr'] for example, the second parameter is a string of the default language in case nothing can be matched, the third parameter is the name of the cookie that contains the language that overrides all the normal priority.

    $chooser = new Arosemena\LanguageChooser\LanguageChooser(['en', 'es'], 'en', 'language');

After the class has been instanciated do $chooser->obtain() to get the appropiate locale.

Examples

    $chooser = new Arosemena\LanguageChooser\LanguageChooser(['en', 'es', 'fr'], 'es', 'language');
    // if the browser says that the user prefers french (fr)
    $chooser->obtain(); // returns 'fr'
    // if the browser says that the user prefers german (de)
    $chooser->obtain(); // returns 'es' because it is the default language and german isn't supported
    // if the browser says that the user prefers spanish (es) and sends a cookie named language with the value 'fr'
    $chooser->obtain(); // returns 'fr' because the cookie overrides the browser preferred language

How does it work?

The class will read the $_SERVER['HTTP_ACCEPT_LANGUAGE'] variable which is a header sent by most modern browsers and it will be parsed and evaluated against the available languages to determine the most appropiate one.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固