Package Data | |
---|---|
Maintainer Username: | raoyc |
Maintainer Contact: | raoyc2009@gmail.com (raoyc) |
Package Create Date: | 2016-07-13 |
Package Last Update: | 2023-04-27 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-09-01 15:04:45 |
Package Statistics | |
---|---|
Total Downloads: | 5,151 |
Monthly Downloads: | 248 |
Daily Downloads: | 0 |
Total Stars: | 4 |
Total Watchers: | 2 |
Total Forks: | 1 |
Total Open Issues: | 0 |
Browser Preferred Language Detector, detect by browser Accept-Language
request header.
Get Composer, then run in terminal:
cd /path/to/your-project
composer require "douyasi/locator:~1.0"
Route::get('test', function () {
$detector = app('Douyasi\Locator\PreferredLanguageDetector');
return $detector->detect(['zh-CN', 'en']);
//return $detector->get();
//return $detector->get_languages(['zh-CN,zh', 'en', 'zh-TW'], ['0.8', '0.6', '0.4']);
});
You can use
$detector->detect(['zh-CN', 'en'])
to replaceRequest::getPreferredLanguage(['zh-CN', 'en'])
in Laravel.
$langs = ['zh-CN', 'en']; //available languages (i18n array) in your web project
$detector->detect($langs); //return 'zh-CN' or 'en', according to your browser language preference.
$detector->get();
You can get some data (json format) like blow:
[
{
"priority": 80,
"tags": "zh-CN,zh",
"locales": [
{
"language": "zh",
"region": "CN",
"script": "",
"variant1": "",
"variant2": "",
"variant3": "",
"private1": "",
"private2": "",
"private3": ""
},
{
"language": "zh",
"script": "",
"region": "",
"variant1": "",
"variant2": "",
"variant3": "",
"private1": "",
"private2": "",
"private3": ""
}
]
},
{
"priority": 60,
"tags": "en",
"locales": [
{
"language": "en",
"script": "",
"region": "",
"variant1": "",
"variant2": "",
"variant3": "",
"private1": "",
"private2": "",
"private3": ""
}
]
},
]
http://douyasi.com
Copyright (c) 2016 douyasi org by ycrao