Published
Edited
Nov 16, 2021
Insert cell
Insert cell
md`
[guillaumepotier/gettext.js](https://github.com/guillaumepotier/gettext.js/)
`
Insert cell
_('unlike')
Insert cell
_('a year ago')
Insert cell
{
let i = 0
return i18n.strfmt(
_('You are now using %s. Plurk will stop supporting IE on July 1, 2021.')
.replace(/%s/g, () => '%' + ++i), 'EVIL IE')
}
Insert cell
Insert cell
_ = (s, ...$) => i18n.gettext(s, ...$)
Insert cell
_n = (s, p, n, ...$) => i18n.ngettext(s, p, n, ...$)
Insert cell
_p = (c, s, ...$) => i18n.pgettext(c, s, ...$)
Insert cell
Insert cell
catelog_zh_tw = fetch('https://s.plurk.com/2283ef125526b25e935a.js')
.then(r => r.text())
.then(s => json5.parse(s.match(/Translations.getTranslation\(\).load\((.+}})\)}}/)[1]))
Insert cell
i18n = {
const { locale, messages: _msg } = catelog_zh_tw
const messages = Object.fromEntries(
Object.entries(_msg).map(([k, v]) => {
if (Array.isArray(v) && v.length == 1) return [k, v[0]]
return [k, v]
}))
const i18n = new I18n({
locale,
messages,
})
return i18n
}
Insert cell
I18n = (await import('gettext.js/dist/gettext.esm')).default
Insert cell
json5 = require('json5')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more