1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<?php
class SysLang extends BaseSimpleModel { protected $table = "sys_lang"; protected $primaryKey = "langid";
public static function negotiate($accepts = [], $default = "en") { $accepts = count($accepts) > 0 ? $accepts : ['ko', 'id', 'km', 'zh-hk', 'zh-tw', 'zh', 'en'];
$accept_factory = new Aura\Accept\AcceptFactory($_SERVER); $accept = $accept_factory->newInstance(); if ($accept->negotiateLanguage($accepts)) { $langcode = $accept->negotiateLanguage($accepts)->getValue();
switch (strtolower($langcode)) { case 'ko': case 'id': case 'km': return 'idn'; case 'zh-tw': case 'zh-hk': return 'tc'; case 'zh': return 'sc'; case 'en': default: return $default; } } return $default;
} }
|