A Rollup plugin which converts a YAML file to a browser extension's locale (messages.json) files.
# npm
npm install --save-dev rollup-plugin-yaml-locales
# yarn
yarn add --dev rollup-plugin-yaml-locales
rollup.config.js
import i18n from 'rollup-plugin-yaml-locales';
export default {
// ...
plugins: [i18n('src/i18n.yaml')],
};
vite.config.js
import { defineConfig } from 'vite';
import { crx } from '@crxjs/vite-plugin';
import i18n from 'rollup-plugin-yaml-locales';
import manifest from './manifest.json';
export default defineConfig({
plugins: [
crx({ manifest }), // optional
i18n('i18n.yaml'),
],
});
i18n.yaml
extName: Extension Name
extDescription: Extension Description
msg_1:
en: Message text
uk: Текст повідомлення
msg_2:
d: msg_2 description
en: msg_2 message
Type: string
Default: src/i18n.yaml
Type: object
Default: {}
Type: string
Default: en
Type: boolean
Default: true
Messages.json files are created only for supported languages.
Type: string
Default: ' '
The space
parameter of the JSON.stringify
function when generating the messages.json file.
Type: object
Default: {}
See an example below and test for details.
rollup.config.js
import i18n from 'rollup-plugin-yaml-locales';
const beta = process.env.BUILD === 'beta';
export default {
// ...
plugins: [
i18n('src/i18n.yaml', {
suffixes: beta
? {
extName: ' (beta)',
extDesc: {
en: ' (beta version)',
uk: ' (бета версія)',
},
}
: {},
}),
],
};
package.json
{
...
"scripts": {
"dev": "rollup -cw",
"beta": "rollup -c --environment BUILD:beta",
"build": "rollup -c"
}
...
}