Files
vite-plugin-gettext-loader/index.ts
2022-05-02 14:37:54 +02:00

20 lines
579 B
TypeScript

import { gettextToI18next } from 'i18next-conv'
export default function PoLoader() {
return {
name: 'po-loader',
async transform(source: string, id: string) {
const poRegEx = /\.po$/;
console.log(id);
if (poRegEx.test(id)) {
const match = source.match(/Language: (\w+)/)
const lang = match ? match[1] : 'en';
return {
code: `export default ${await gettextToI18next(lang, source)}`
}
}
return {};
}
}
}