2018-12-18 21:45:49 +01:00
|
|
|
import path from 'path'
|
|
|
|
import fs from 'fs'
|
2019-01-20 00:06:25 +01:00
|
|
|
import { promisify } from 'util'
|
2020-12-19 05:02:36 +01:00
|
|
|
import { LOCALE } from '../src/routes/_static/intl'
|
2018-12-18 21:45:49 +01:00
|
|
|
|
2019-01-20 00:06:25 +01:00
|
|
|
const readFile = promisify(fs.readFile)
|
2020-06-29 08:12:14 +02:00
|
|
|
const writeFile = promisify(fs.writeFile)
|
2018-12-18 21:45:49 +01:00
|
|
|
|
2020-12-19 05:02:36 +01:00
|
|
|
// Try 'en-US' first, then 'en' if that doesn't exist
|
|
|
|
const PREFERRED_LOCALES = [LOCALE, LOCALE.split('-')[0]]
|
|
|
|
|
|
|
|
// emojibase seems like the most "neutral" shortcodes, but cldr is available in every language
|
|
|
|
const PREFERRED_SHORTCODES = ['emojibase', 'cldr']
|
|
|
|
|
|
|
|
async function getEmojiI18nFile (locale, shortcode) {
|
|
|
|
const filename = path.resolve(__dirname,
|
|
|
|
'../node_modules/emoji-picker-element-data',
|
|
|
|
locale,
|
|
|
|
shortcode,
|
|
|
|
'data.json')
|
|
|
|
try {
|
|
|
|
return JSON.parse(await readFile(filename, 'utf8'))
|
|
|
|
} catch (err) { /* ignore */ }
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getFirstExistingEmojiI18nFile () {
|
|
|
|
for (const locale of PREFERRED_LOCALES) {
|
|
|
|
for (const shortcode of PREFERRED_SHORTCODES) {
|
|
|
|
const json = await getEmojiI18nFile(locale, shortcode)
|
|
|
|
if (json) {
|
|
|
|
return json
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-18 21:45:49 +01:00
|
|
|
async function main () {
|
2020-12-19 05:02:36 +01:00
|
|
|
const json = await getFirstExistingEmojiI18nFile()
|
|
|
|
|
|
|
|
if (!json) {
|
|
|
|
throw new Error(`Couldn't find i18n data for locale ${LOCALE}. Is it supported in emoji-picker-element-data?`)
|
|
|
|
}
|
|
|
|
|
2020-06-29 08:12:14 +02:00
|
|
|
await writeFile(
|
2020-12-19 05:02:36 +01:00
|
|
|
path.resolve(__dirname, `../static/emoji-${LOCALE}.json`),
|
2020-06-29 08:12:14 +02:00
|
|
|
JSON.stringify(json),
|
|
|
|
'utf8'
|
|
|
|
)
|
2018-12-18 21:45:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main().catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|