PHP language detection

前端 未结 9 2251
陌清茗
陌清茗 2020-12-14 16:32

I\'m trying to build multilangual site.

I use this piece of code to detect users language. If you havent chosen a language, it will include your language file based

9条回答
  •  旧时难觅i
    2020-12-14 17:23

    I know there already many good solutions, but have found my own way to solve this problem.

     float 1
          'en' => float 0.8
          'uk' => float 0.6
          'ru' => float 0.4
        */
    

    Code will convert HTTP_ACCEPT_LANGUAGE string to array with locales as keys and weight as values, sorted from high value to low. So you can just get one by one with array_shift to get the best match with your site locales.

提交回复
热议问题