forked from zotero/zoterobib
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zbib will now normalize browser-reported languages and attempt to find a matching a supported locale. This fixes an issue where citeproc-rs would use a fallback locale if lang didn't match exactly (e.g. Chrome reports "pl" but locale name is "pl-PL"). Also Zbib will now attempt to match all browser-reported languages in order of preference (previously if first lang didn't match locale, fallback would be used).
- Loading branch information
Showing
4 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as fs from 'fs/promises'; | ||
import { dirname, resolve } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const collectLocale = async (pathToLocales, outputPath) => { | ||
const files = await fs.readdir(pathToLocales); | ||
const localeXmls = files.filter(fname => fname.startsWith('locales') && fname.endsWith('.xml')); | ||
const locales = localeXmls.map(xml => xml.slice(8, -4)).map(locale => { | ||
const localeSplit = locale.split('-'); | ||
return localeSplit.length > 1 ? | ||
`${localeSplit[0].toLowerCase()}-${localeSplit[1].toUpperCase()}` : | ||
localeSplit[0].toLowerCase(); | ||
}); | ||
|
||
await fs.mkdir(resolve(dirname(outputPath)), { recursive: true }); | ||
await fs.writeFile(outputPath, JSON.stringify(locales)); | ||
}; | ||
|
||
if (process.argv[1] === fileURLToPath(import.meta.url)) { | ||
const pathToLocales = `${dirname(fileURLToPath(import.meta.url))}/../third-party/locales`; | ||
const outputPath = `${dirname(fileURLToPath(import.meta.url))}/../data/supported-locales.json`; | ||
collectLocale(pathToLocales, outputPath); | ||
} | ||
|
||
export default collectLocale; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters