@streamr/po-loader
Version:
A small webpack-loader for po files
18 lines (12 loc) • 477 B
JavaScript
const { getOptions } = require('loader-utils')
const { gettextToI18next: po2json } = require('i18next-conv')
function loader(source) {
const options = getOptions(this)
if (this.cacheable) {
this.cacheable()
}
const callback = this.async()
const language = (source.match(/Language:\s*(\w+)/) || [null, 'en'])[1]
po2json(language, source, options).then((data) => callback(null, `module.exports = ${data};`))
}
module.exports = loader