{"action":"created","issue":{"url":"https://api.github.com/repos/Juris-M/citeproc-js/issues/4","repository_url":"https://api.github.com/repos/Juris-M/citeproc-js","labels_url":"https://api.github.com/repos/Juris-M/citeproc-js/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/Juris-M/citeproc-js/issues/4/comments","events_url":"https://api.github.com/repos/Juris-M/citeproc-js/issues/4/events","html_url":"https://github.com/Juris-M/citeproc-js/issues/4","id":151784170,"number":4,"title":"Locale seems to always default to `en-US`, even when supplied with a \"locale getter\" function","user":{"login":"dsifford","id":5240018,"avatar_url":"https://avatars.githubusercontent.com/u/5240018?v=3","gravatar_id":"","url":"https://api.github.com/users/dsifford","html_url":"https://github.com/dsifford","followers_url":"https://api.github.com/users/dsifford/followers","following_url":"https://api.github.com/users/dsifford/following{/other_user}","gists_url":"https://api.github.com/users/dsifford/gists{/gist_id}","starred_url":"https://api.github.com/users/dsifford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsifford/subscriptions","organizations_url":"https://api.github.com/users/dsifford/orgs","repos_url":"https://api.github.com/users/dsifford/repos","events_url":"https://api.github.com/users/dsifford/events{/privacy}","received_events_url":"https://api.github.com/users/dsifford/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":34,"created_at":"2016-04-29T02:56:22Z","updated_at":"2016-04-30T19:49:10Z","closed_at":null,"body":"Hi there. \r\n\r\nI can't seem to get any other locale other than en-US. To my knowledge, I'm supplying the CSL.engine with the correct functions to retrieve the locale, but it just isn't happening. \r\n\r\nHere is the relevant code from my repo: \r\n\r\n```ts\r\n\r\ndeclare var CSL;\r\n\r\nexport class CSLPreprocessor {\r\n\r\n    public citeprocSys: Citeproc.SystemObj;\r\n    public citations: { [id: string]: CSL.Data };\r\n\r\n    /**\r\n     * Constructor for the CSLPreprossor class.\r\n     * @param  {string}  locale  The current user's locale string.\r\n     * @param  {{[id: string]:CSL.Data}}  citations  An object of CSL.Data.\r\n     *   Note, the object key MUST match the `id` param within the object.\r\n     * @param  {string}   style  The user's selected style string.\r\n     * @param  {Function} callback  Callback function\r\n     * @return {void}\r\n     */\r\n    constructor(locale: string, citations: { [id: string]: CSL.Data }, style: string, callback: Function) {\r\n\r\n        this.citations = citations;\r\n\r\n        let p1 = new Promise((resolve, reject) => {\r\n            this.getLocale(locale, (data: string) => {\r\n                resolve({\r\n                    retrieveLocale: (lang) => data,\r\n                    retrieveItem: (id: string | number) => this.citations[id],\r\n                });\r\n            });\r\n        });\r\n\r\n        p1.then((data: Citeproc.SystemObj) => {\r\n            this.citeprocSys = data;\r\n            this.getProcessor(style, data, callback);\r\n        });\r\n        \r\n    }\r\n\r\n    /**\r\n     * Retrieves the locale rules for CSL using HTTP and passes it to a callback function.\r\n     * @param {string}   locale   The user's locale.\r\n     * @param {Function} callback Callback function.\r\n     */\r\n    getLocale(locale: string, callback: Function): void {\r\n        let req = new XMLHttpRequest();\r\n\r\n        let cslLocale = this.locales[locale];\r\n        if (typeof cslLocale === 'boolean') {\r\n            locale = 'en-US';\r\n        }\r\n        else {\r\n            locale = cslLocale;\r\n        }\r\n\r\n        req.onreadystatechange = () => {\r\n            if (req.readyState === 4) {\r\n                callback(req.responseText);\r\n            }\r\n        };\r\n\r\n        req.open(\"GET\", `https://raw.githubusercontent.com/citation-style-language/locales/8c976408d3cb287d0cecb29f97752ec3a28db9e5/locales-${locale}.xml`);\r\n        req.send(null);\r\n    }\r\n\r\n    /**\r\n     * Retrieves the CSL style rules for the selected style using HTTP. When the\r\n     *   style instructions are received, a CSL.Engine is created and passed to\r\n     *   the callback function.\r\n     * @param  {string}   styleID  The style ID for the style of interest (no .csl extension)\r\n     * @param  {Function} callback Callback function.\r\n     */\r\n    getProcessor(styleID: string, data: Citeproc.SystemObj, callback: Function): void {\r\n        let req = new XMLHttpRequest();\r\n        req.open('GET', `https://raw.githubusercontent.com/citation-style-language/styles/master/${styleID}.csl`);\r\n\r\n        req.onreadystatechange = () => {\r\n            if (req.readyState === 4) {\r\n                let citeproc = new CSL.Engine(data, req.responseText);\r\n                callback(citeproc);\r\n            }\r\n        }\r\n\r\n        req.send(null);\r\n    }\r\n\r\n    /**\r\n     * Receives the response object from `getProcessor`, makes the bibliography,\r\n     *   removes outer HTML, pushes it to an array, and returns the array.\r\n     * @param  {Object}   citeproc The citeproc engine.\r\n     * @return {string[]}          Array of citations to be served.\r\n     */\r\n    prepare(citeproc): string[] {\r\n        citeproc.updateItems(Object.keys(this.citations));\r\n        let bib = citeproc.makeBibliography();\r\n\r\n        let data = [];\r\n        bib[1].forEach(ref => {\r\n            data.push(this.trimHTML(ref));\r\n        });\r\n        return data;\r\n    }\r\n\r\n    /**\r\n     * Removes outer HTML formatting served from citeproc, sparing inner `<i>` tags.\r\n     * @param  {string} ref The reference payload from citeproc.\r\n     * @return {string}     A formatted reference string without outer HTML.\r\n     */\r\n    trimHTML(ref: string): string {\r\n        return ref\r\n            .replace(/<(?!(i|\\/i|a|\\/a)).+?>/g, '')\r\n            .trim()\r\n            .replace(/^\\d+\\.\\s?/, '');\r\n    }\r\n\r\n    /**\r\n     * This object converts the locale names in wordpress (keys) to the locales\r\n     *   in CSL (values). If CSL doesn't have a locale for a given WordPress locale,\r\n     *   then false is used (which will default to en-US).\r\n     */\r\n    private locales: {[wp: string]:string|boolean} = {\r\n        'af': 'af-ZA',\r\n        'ak': false,\r\n        'am': false,\r\n        'ar': 'ar',\r\n        'arq': 'ar',\r\n        'art_xemoji': 'ar',\r\n        'ary': 'ar',\r\n        'as': 'en-US',\r\n        'az_TR': 'tr-TR',\r\n        'az': 'tr-TR',\r\n        'azb': 'en-US',\r\n        'ba': false,\r\n        'bal': false,\r\n        'bcc': false,\r\n        'bel': false,\r\n        'bg_BG': 'bg-BG',\r\n        'bn_BD': 'en-US',\r\n        'bo': false,\r\n        'bre': false,\r\n        'bs_BA': false,\r\n        'ca': 'ca-AD',\r\n        'ceb': false,\r\n        'ckb': false,\r\n        'co': false,\r\n        'cs_CZ': 'cs-CZ',\r\n        'cy': 'cy-GB',\r\n        'da_DK': 'da-DK',\r\n        'de_CH': 'de-CH',\r\n        'de_DE': 'de-DE',\r\n        'dv': false,\r\n        'dzo': false,\r\n        'el': 'el-GR',\r\n        'en_AU': 'en-US',\r\n        'en_CA': 'en-US',\r\n        'en_GB': 'en-GB',\r\n        'en_NZ': 'en-US',\r\n        'en_US': 'en-US',\r\n        'en_ZA': 'en-US',\r\n        'eo': false,\r\n        'es_AR': 'es-ES',\r\n        'es_CL': 'es-CL',\r\n        'es_CO': 'es-CL',\r\n        'es_ES': 'es-ES',\r\n        'es_GT': 'es-ES',\r\n        'es_MX': 'es-MX',\r\n        'es_PE': 'es-CL',\r\n        'es_PR': 'es-CL',\r\n        'es_VE': 'es-CL',\r\n        'et': 'et-ET',\r\n        'eu': 'eu',\r\n        'fa_AF': 'fa-IR',\r\n        'fa_IR': 'fa-IR',\r\n        'fi': 'fi-FI',\r\n        'fo': false,\r\n        'fr_BE': 'fr-FR',\r\n        'fr_CA': 'fr-CA',\r\n        'fr_FR': 'fr-FR',\r\n        'frp': false,\r\n        'fuc': false,\r\n        'fur': false,\r\n        'fy': false,\r\n        'ga': false,\r\n        'gd': false,\r\n        'gl_ES': false,\r\n        'gn': false,\r\n        'gsw': 'de-CH',\r\n        'gu': false,\r\n        'haw_US': 'en-US',\r\n        'haz': false,\r\n        'he_IL': 'he-IL',\r\n        'hi_IN': false,\r\n        'hr': 'hr-HR',\r\n        'hu_HU': 'hu-HU',\r\n        'hy': false,\r\n        'id_ID': 'id-ID',\r\n        'ido': false,\r\n        'is_IS': 'is-IS',\r\n        'it_IT': 'it-IT',\r\n        'ja': 'ja-JP',\r\n        'jv_ID': false,\r\n        'ka_GE': false,\r\n        'kab': false,\r\n        'kal': false,\r\n        'kin': false,\r\n        'kk': false,\r\n        'km': 'km-KH',\r\n        'kn': false,\r\n        'ko_KR': 'ko-KR',\r\n        'ky_KY': false,\r\n        'lb_LU': 'lt-LT',\r\n        'li': false,\r\n        'lin': false,\r\n        'lo': false,\r\n        'lt_LT': 'lt-LT',\r\n        'lv': 'lv-LV',\r\n        'me_ME': false,\r\n        'mg_MG': false,\r\n        'mk_MK': false,\r\n        'ml_IN': false,\r\n        'mn': 'mn-MN',\r\n        'mr': false,\r\n        'mri': false,\r\n        'ms_MY': false,\r\n        'my_MM': false,\r\n        'nb_NO': 'nb-NO',\r\n        'ne_NP': false,\r\n        'nl_BE': 'nl-NL',\r\n        'nl_NL': 'nl-NL',\r\n        'nn_NO': 'nn-NO',\r\n        'oci': false,\r\n        'ory': false,\r\n        'os': false,\r\n        'pa_IN': false,\r\n        'pl_PL': 'pl-PL',\r\n        'ps': false,\r\n        'pt_BR': 'pt-PR',\r\n        'pt_PT': 'pt-PT',\r\n        'rhg': false,\r\n        'ro_RO': 'ro-RO',\r\n        'roh': false,\r\n        'ru_RU': 'ru-RU',\r\n        'rue': false,\r\n        'rup_MK': false,\r\n        'sa_IN': false,\r\n        'sah': false,\r\n        'si_LK': false,\r\n        'sk_SK': 'sk-SK',\r\n        'sl_SI': 'sl-SI',\r\n        'snd': false,\r\n        'so_SO': false,\r\n        'sq': false,\r\n        'sr_RS': 'sr-RS',\r\n        'srd': false,\r\n        'su_ID': false,\r\n        'sv_SE': 'sv-SE',\r\n        'sw': false,\r\n        'szl': false,\r\n        'ta_IN': false,\r\n        'ta_LK': false,\r\n        'tah': false,\r\n        'te': false,\r\n        'tg': false,\r\n        'th': 'th-TH',\r\n        'tir': false,\r\n        'tl': false,\r\n        'tr_TR': 'tr-TR',\r\n        'tt_RU': false,\r\n        'tuk': false,\r\n        'twd': false,\r\n        'tzm': false,\r\n        'ug_CN': false,\r\n        'uk': 'uk-UA',\r\n        'ur': false,\r\n        'uz_UZ': false,\r\n        'vi': 'vi-VN',\r\n        'wa': false,\r\n        'xmf': false,\r\n        'yor': false,\r\n        'zh_CN': 'zh-CN',\r\n        'zh_HK': 'zh-CN',\r\n        'zh_TW': 'zh-TW',\r\n    }\r\n\r\n\r\n}\r\n```\r\n\r\nAny tips would be much appreciated. Thank you in advance!"},"comment":{"url":"https://api.github.com/repos/Juris-M/citeproc-js/issues/comments/215989958","html_url":"https://github.com/Juris-M/citeproc-js/issues/4#issuecomment-215989958","issue_url":"https://api.github.com/repos/Juris-M/citeproc-js/issues/4","id":215989958,"user":{"login":"fbennett","id":75338,"avatar_url":"https://avatars.githubusercontent.com/u/75338?v=3","gravatar_id":"","url":"https://api.github.com/users/fbennett","html_url":"https://github.com/fbennett","followers_url":"https://api.github.com/users/fbennett/followers","following_url":"https://api.github.com/users/fbennett/following{/other_user}","gists_url":"https://api.github.com/users/fbennett/gists{/gist_id}","starred_url":"https://api.github.com/users/fbennett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbennett/subscriptions","organizations_url":"https://api.github.com/users/fbennett/orgs","repos_url":"https://api.github.com/users/fbennett/repos","events_url":"https://api.github.com/users/fbennett/events{/privacy}","received_events_url":"https://api.github.com/users/fbennett/received_events","type":"User","site_admin":false},"created_at":"2016-04-30T19:49:10Z","updated_at":"2016-04-30T19:49:10Z","body":"Re inline citations, the manual is in the process of moving home. I'll have it back online soon; but I have an idea for a dynamic demo page that will be better than a windy explanation. I'll build that in the next day or two and send you a link.\r\n"}}