tips:browserlanguagedetection
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tips:browserlanguagedetection [2013-09-25 17:40] – [A Improved Using of the top Tip] littlebat | tips:browserlanguagedetection [2018-04-24 01:41] (current) – Dr-Yukon | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Browser Language Detection ====== | ====== Browser Language Detection ====== | ||
+ | |||
+ | :!: OBSOLETE | ||
+ | |||
To have the Wiki language being select based on available languages set on user's browser, perform these actions: | To have the Wiki language being select based on available languages set on user's browser, perform these actions: | ||
Line 10: | Line 13: | ||
with | with | ||
<code php> | <code php> | ||
- | // $conf[' | + | $conf[' |
$conf[' | $conf[' | ||
$conf[' | $conf[' | ||
Line 60: | Line 63: | ||
</ | </ | ||
---- | ---- | ||
- | Edit **inc/ | + | Edit **inc/ |
<code php> | <code php> | ||
require_once(" | require_once(" | ||
Line 74: | Line 77: | ||
</ | </ | ||
---- | ---- | ||
- | Edit **doku.php**, and replace | + | Edit **conf/ |
<code php> | <code php> | ||
- | require_once(" | + | // $conf[' |
- | require_once(" | + | |
</ | </ | ||
- | with | ||
- | <code php> | ||
- | require_once(" | ||
- | // DWD Modify -> Add: Set Language from Browser Language Settings. | ||
- | $conf[' | ||
- | // DWD Modify End. | ||
- | require_once(" | ||
- | </ | ||
- | ---- | ||
- | Edit **media.php**, | ||
- | <code php> | ||
- | require_once(" | ||
- | require_once(" | ||
- | </ | ||
- | with | ||
- | <code php> | ||
- | require_once(" | ||
- | // DWD Modify -> Add: Set Language from Browser Language Settings. | ||
- | $conf[' | ||
- | // DWD Modify End. | ||
- | require_once(" | ||
- | </ | ||
- | |||
- | |||
- | |||
+ | ==== Discussion ==== | ||
- | ===== Discussion ===== | ||
I prefer this new function rather than the old one because it is more precise in parsing the browser acceptable languages and because it either returns a language found by match or the default language. Although it seems the former code was also fixed to return the same results. It also doesn' | I prefer this new function rather than the old one because it is more precise in parsing the browser acceptable languages and because it either returns a language found by match or the default language. Although it seems the former code was also fixed to return the same results. It also doesn' | ||
Line 335: | Line 312: | ||
===== A Improved Using of the top Tip ===== | ===== A Improved Using of the top Tip ===== | ||
- | I use Release 2013-05-10a " | + | I use Release 2013-05-10a " |
* Can't be used in current DokuWiki; | * Can't be used in current DokuWiki; | ||
* Can't match language code correctly sometime, e.g., browser accepted languages " | * Can't match language code correctly sometime, e.g., browser accepted languages " | ||
Line 436: | Line 413: | ||
-- posted 2013-09-25 [[http:// | -- posted 2013-09-25 [[http:// | ||
+ | |||
+ | ==== Discussion ==== | ||
+ | Please post your comment about "A Improved Using of the top Tip" below. | ||
+ | |||
+ | I think there are two goals with the above - one appears to be allow for translation and the other is simply to provide a per-user localised interface for the users of dokuwiki. | ||
+ | |||
+ | I want the latter function and I achieved it by using the detect_browser_language() function above. I placed it in inc/ | ||
+ | I then hacked init_lang (in init.php). I haven' | ||
+ | |||
+ | |||
+ | < | ||
+ | function init_lang($langCode) { | ||
+ | //prepare language array | ||
+ | global $lang, $config_cascade; | ||
+ | $lang = array(); | ||
+ | $langCode = detect_browser_language(); | ||
+ | |||
+ | //load the language files | ||
+ | require(DOKU_INC.' | ||
+ | foreach ($config_cascade[' | ||
+ | if (@file_exists($config_file . ' | ||
+ | include($config_file . ' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if ($langCode && $langCode != ' | ||
+ | if (file_exists(DOKU_INC." | ||
+ | require(DOKU_INC." | ||
+ | } | ||
+ | foreach ($config_cascade[' | ||
+ | if (@file_exists($config_file . " | ||
+ | include($config_file . " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ |
tips/browserlanguagedetection.1380123658.txt.gz · Last modified: 2013-09-25 17:40 by littlebat