Esempio n. 1
0
    // 	$arr  = array( 'Köpfe', 'Kypper', 'Kopfe' );
    // $coll = collator_create( 'en' );
    // collator_sort_with_sort_keys( $coll, $arr );
    // var_export( $arr );
    // die;
    // $s1 = 'Hello';
    $locale = 'zh';
    $en = collator_create('en');
    $coll = collator_create($locale);
    // $res  = collator_get_sort_key( $coll, $s1);
    // echo urlencode($res);
    App::setLocale($locale);
    $countries = Vinfo\Country::get()->lists('name')->toArray();
    // collator_sort_with_sort_keys ($coll, $countries);
    foreach ($countries as &$country) {
        $country = ['name' => $country, 'pinyin' => Overtrue\Pinyin\Pinyin::trans($country), 'en' => collator_get_sort_key($en, $country), 'coll' => collator_get_sort_key($coll, $country)];
    }
    $countries = new Illuminate\Support\Collection($countries);
    $countries = $countries->sortBy('coll');
    foreach ($countries as $country) {
        echo $country['pinyin'] . '<br>';
    }
    return ' ';
    dd($countries);
});
Route::get('/test/region-names', function () {
    die;
    $translations = RegionTranslation::with('region.country')->get();
    //->where('id', '>', 640)->limit(10)
    foreach ($translations as $translation) {
        $locale = str_replace('-', '_', $translation->locale);
Esempio n. 2
0
 private static function get_tag_name_pinyin($tag)
 {
     $cache_group_id = 'tag-name-pinyin';
     $cache = wp_cache_get($tag['term_id'], $cache_group_id);
     if ($cache) {
         return $cache;
     }
     /** 提取首字母 */
     $first_letter_pattern = '/^[a-z]/i';
     $first_letter = strtolower(mb_substr($tag['name'], 0, 1));
     preg_match($first_letter_pattern, $first_letter, $matches);
     /**
      * 存在字母开头的标签
      */
     if (!empty($matches[0])) {
         wp_cache_set($tag['term_id'], $first_letter, $cache_group_id);
         return $first_letter;
     }
     /**
      * 标签是中文开头
      */
     $utf8_tagname = mb_convert_encoding($tag['name'], 'utf-8', 'ascii,gb2312,gbk,utf-8');
     preg_match("/^[\\x{4e00}-\\x{9fa5}]/u", $utf8_tagname, $matches);
     /**
      * 不是中文,跳到下一个
      */
     if (empty($matches[0])) {
         wp_cache_set($tag['term_id'], false, $cache_group_id);
         return $first_letter;
     }
     if (!class_exists('Overtrue\\Pinyin\\Pinyin')) {
         include __DIR__ . '/inc/Pinyin/Pinyin.php';
     }
     $double_pinyins = ['zh', 'ch', 'sh', 'ou', 'ai', 'ang', 'an'];
     $tag_pinyin = Overtrue\Pinyin\Pinyin::pinyin($tag['name']);
     $tag_two_pinyin = strtolower(substr($tag_pinyin, 0, 2));
     /**
      * 判断巧舌音
      */
     if (in_array($tag_two_pinyin, $double_pinyins)) {
         wp_cache_set($tag['term_id'], $tag_two_pinyin, $cache_group_id);
         return $tag_two_pinyin;
         /**
          * 单音
          */
     } else {
         $tag_one_pinyin = mb_substr($tag_pinyin, 0, 1);
         wp_cache_set($tag['term_id'], $tag_one_pinyin, $cache_group_id);
         return $tag_one_pinyin;
     }
 }