Skip to content

A Rollup plugin which converts a YAML file to a browser extension's locale files.

License

Notifications You must be signed in to change notification settings

ukhan/rollup-plugin-yaml-locales

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YAML to Locales plugin for Rollup

A Rollup plugin which converts a YAML file to a browser extension's locale (messages.json) files.

Installation

# npm
npm install --save-dev rollup-plugin-yaml-locales

# yarn
yarn add --dev rollup-plugin-yaml-locales

Usage

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

Configuration

yamlFile

Type: string
Default: src/i18n.yaml

options

Type: object
Default: {}

options.defaultLocale

Type: string
Default: en

options.onlySupportedLocales

Type: boolean
Default: true

Messages.json files are created only for supported languages.

options.space

Type: string
Default: ' '

The space parameter of the JSON.stringify function when generating the messages.json file.

options.suffixes

Type: object
Default: {}

See an example below and test for details.

Advanced usage

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"
  }
  ...
}

About

A Rollup plugin which converts a YAML file to a browser extension's locale files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published