https://github.com/quilljou/chrome-intl-code-gen
Type safe version of chrome extension i18n
https://github.com/quilljou/chrome-intl-code-gen
Last synced: 8 months ago
JSON representation
Type safe version of chrome extension i18n
- Host: GitHub
- URL: https://github.com/quilljou/chrome-intl-code-gen
- Owner: Quilljou
- Created: 2020-03-18T10:31:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-02T10:16:58.000Z (over 5 years ago)
- Last Synced: 2024-12-31T03:22:38.319Z (9 months ago)
- Language: TypeScript
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Chrome intl Code Gen
[](https://www.npmjs.com/package/chrome-intl-code-gen)
[](https://github.com/Quilljou/chrome-intl-code-gen)It provide a webpack plugin for watching chrome extesion's `_locales` directory, if locale file changed, A typescript file which contains a type-safe version of `chrome.i18n.getMessage` will be generated at the output path. the file contents includes a default export and multiple exports like this. Also you can customize your own generated content with the `template` option.
```ts
/* eslint-disable */
// This file is generated by chrome-i18n-code-gen, do not edit itexport type ChromeI18nKeys = "extName" | "extDescription"
export default function i18n(key: ChromeI18nKeys): string {
return chrome.i18n.getMessage(key)
}
/**
* extension name
*/
export function extName(): string {
return chrome.i18n.getMessage('extName')
}
/**
* extension description
*/
export function extDescription(): string {
return chrome.i18n.getMessage('extDescription')
}
```## Usage
```ts
const ChromeIntlCodeGenPlguin = require('chrome-intl-code-gen').default;[
new ChromeIntlCodeGenPlguin({
input: "public/_locales",
output: "src/shared/locale.ts"
})
]
```Options
```ts
interface Options {
/**
* path of `_locales` directory
*/
input: string;
/**
* output typescript file path
*/
output: string;
/**
* base language, defaults to en
*/
base?: string;
/**
* optional custom template function to generate your own output file
* interface Message { [keyName: string]: { "message": string; "description": string; } }
*/
template?: ((data: Message) => string);
}
```