Skip to content

Commit 7814b9e

Browse files
committed
CSL locale support
Via the 'locale' query parameter Closes FiligranHQ#4
1 parent fc7425b commit 7814b9e

File tree

3 files changed

+76
-46
lines changed

3 files changed

+76
-46
lines changed

model/API.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class Zotero_API {
7575
'style' => "chicago-note-bibliography",
7676
'css' => "inline",
7777
'linkwrap' => 0,
78+
'locale' => "en-US",
7879

7980
// search
8081
'fq' => '',

model/Cite.inc.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,12 @@ private static function getCacheKey($mode, $item, array $queryParams) {
387387

388388
// Any query parameters that have an effect on the output
389389
// need to be added here
390-
$allowedParams = array(
390+
$allowedParams = [
391391
'style',
392+
'locale',
392393
'css',
393394
'linkwrap'
394-
);
395+
];
395396
$cachedParams = Z_Array::filterKeys($queryParams, $allowedParams);
396397

397398
return $mode . "_" . $lk . "_"
@@ -407,6 +408,7 @@ private static function getBibCacheKey(array $items, array $queryParams) {
407408
// need to be added here
408409
$allowedParams = array(
409410
'style',
411+
'locale',
410412
'css',
411413
'linkwrap'
412414
);
@@ -449,6 +451,13 @@ private static function buildURLPath(array $queryParams, $mode) {
449451
if ($mode == 'citation') {
450452
$url .= "&citations=1&bibliography=0";
451453
}
454+
if ($queryParams['locale'] != "en-US"
455+
&& preg_match('/^[a-z]{2}(-[A-Z]{2})?/', $queryParams['locale'], $matches)) {
456+
if (strlen($matches[0]) == 2) {
457+
$matches[0] = $matches . '-' . strtoupper($matches[0]);
458+
}
459+
$url .= "&locale=" . $matches[0];
460+
}
452461
return $url;
453462
}
454463

0 commit comments

Comments
 (0)