Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add @LOCALE@ macro for translation #166

Merged
merged 5 commits into from
Oct 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) {
}
break;
default:
$page = $this->_apply_macro($page);
$page = $this->_apply_macro($page, $parent_id);
resolve_pageid(getNS($parent_id), $page, $exists); // resolve shortcuts and clean ID
if (auth_quickaclcheck($page) >= AUTH_READ)
$pages[] = $page;
Expand Down Expand Up @@ -793,11 +793,44 @@ function _get_included_pages_from_meta_instructions($instructions) {
}
return $pages;
}


/**
* Get wiki language from "HTTP_ACCEPT_LANGUAGE"
* We allow the pattern e.g. "ja,en-US;q=0.7,en;q=0.3"
*/
function _get_language_of_wiki($id, $parent_id) {
global $conf;
$result = $conf['lang'];
if(strpos($id, '@BROWSER_LANG@') !== false){
$brlangp = "/([a-zA-Z]{1,8}(-[a-zA-Z]{1,8})*|\*)(;q=(0(.[0-9]{0,3})?|1(.0{0,3})?))?/";
if(preg_match_all(
$brlangp, $_SERVER["HTTP_ACCEPT_LANGUAGE"],
$matches, PREG_SET_ORDER
)){
$langs = array();
foreach($matches as $match){
$langname = $match[1] == '*' ? $conf['lang'] : $match[1];
$qvalue = $match[4] == '' ? 1.0 : $match[4];
$langs[$langname] = $qvalue;
}
arsort($langs);
foreach($langs as $lang => $langq){
$testpage = $this->_apply_macro(str_replace('@BROWSER_LANG@', $lang, $id), $parent_id);
resolve_pageid(getNS($parent_id), $testpage, $exists);
if($exists){
$result = $lang;
break;
}
}
}
}
return cleanID($result);
}

/**
* Makes user or date dependent includes possible
*/
function _apply_macro($id) {
function _apply_macro($id, $parent_id) {
global $INFO;
global $auth;

Expand Down Expand Up @@ -847,6 +880,7 @@ function _apply_macro($id) {
'@USER@' => cleanID($user),
'@NAME@' => cleanID($INFO['userinfo']['name']),
'@GROUP@' => cleanID($group),
'@BROWSER_LANG@' => $this->_get_language_of_wiki($id, $parent_id),
'@YEAR@' => date('Y',$time_stamp),
'@MONTH@' => date('m',$time_stamp),
'@WEEK@' => date('W',$time_stamp),
Expand Down