0.3.26 • Published 1 year ago

vite-plugin-i18n-validator v0.3.26

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

vite-plugin-i18n-validator

A Vite plugin validates Json files with internationalization support in worker thread.

  • Compare with the base language file to verify the presence of key and value.
  • Optional: Use textlint to proofread values.

Motivation

  • We want to reduce obstacles caused by forgotten key settings by supporting multiple languages.
  • We want to reduce obstacles such as shaky notation.
  • I want to use correct grammar to provide easier-to-understand text to users.

Install

npm i -D vite-plugin-i18n-validator

Options

  • You can set an object or an array.
ParameterTypeDescription
enabledBuildbooleanEnable checks at build time. (default: false)
baseLocaleFilePathstringSet the path of the file to be compared.
includestring | RegExp | Array<string | RegExp>Set the target path.
excludestring | RegExp | Array<string | RegExp>Set the paths you want to exclude.
ignoreKeysRegExp | ArraySet key not to validate.
prohibitedKeysstring[]Set prohibited keys.
prohibitedValuesstring[]Set prohibited values.
textlinttrue | {CreateLinterOptions,LoadTextlintrcOptions}https://github.com/textlint/textlint

Usage

vite.config.ts

import { defineConfig } from "vite";
import i18nValidator from "vite-plugin-i18n-validator";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    i18nValidator([
      {
        enabledBuild: true,
        include: ["src/locales/*.json"],
        baseLocaleFilePath: path.resolve(__dirname, "src/locales/ja.json"),
        prohibitedValues: ["public"],
        textlint: true,
      },
      {
        include: ["src/locales2/*.json"],
        baseLocaleFilePath: path.resolve(__dirname, "src/locales/ja.json"),
        ignoreKeys: /(foo\.todo2)+/i,
      },
    ]),
  ],
});
  • Compare files in baseLocaleFilePath when files set to include are saved.
npm run dev
  • Compare all files set in include with those in baseLocaleFilePath.
npm run build
  • When a file is updated or built, the following messages are output.
2:05:34 [vite] src/locales/ja.json:5:14: Found TODO: 'todo:hoge"'
2:05:34 [vite] src/locales/ja.json:7:15: Found TODO: 'todo:hoge"'
2:05:49 [vite] src/locales/en.json: Not found: 'foo.zoo'
2:05:49 [vite] src/locales/en.json: Not found: 'foo.todo'
2:05:49 [vite] src/locales/en.json: Not found: 'foo.todo2'
2:05:49 [vite] src/locales/en.json: Not found: 'foo.todo3'
  • If proofreading is required, install the textlint library.

Principles of conduct

Please see the principles of conduct when building a site.

License

This library is licensed under the MIT license.

0.3.26

1 year ago

0.3.25

1 year ago

0.3.24

1 year ago

0.3.23

1 year ago

0.3.22

1 year ago

0.3.21

1 year ago

0.3.20

1 year ago

0.3.17

1 year ago

0.3.19

1 year ago

0.3.18

1 year ago

0.3.16

1 year ago

0.3.15

1 year ago

0.3.14

1 year ago

0.3.13

1 year ago

0.3.12

1 year ago

0.3.9

1 year ago

0.3.6

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.10

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.1.0

1 year ago