Compare commits

...

5 Commits

Author SHA1 Message Date
GitHub Actions c30adb409c chore(release): @wxt-dev/i18n v0.2.2
vhs / vhs (push) Cancelled after 0s
2024-10-23 13:44:57 +00:00
Bread Grocery ab83031462 feat: Add support for configuring the locales directory (#1109) 2024-10-23 08:39:30 -05:00
imnaK cd7285c3ef docs: fix wrong anchor to "Environment Variables" (#1107) 2024-10-22 22:58:22 -05:00
Aaron bdb775c88d Update changelog 2024-10-22 09:58:51 -05:00
Aaron d20793d5e6 docs: Use full URLs in README so they work on the docs site 2024-10-22 09:50:57 -05:00
8 changed files with 61 additions and 14 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ Here's a brief summary of each of these files and directories:
- `hooks/`: Auto-imported by default, contains hooks for React and Solid
- `public/`: Contains any files you want to copy into the output folder as-is, without being processed by WXT
- `utils/`: Auto-imported by default, contains generic utilities used throughout your project
- `.env`: Contains [Environment Variables](/guide/essentials/config/runtime#environment-variables)
- `.env`: Contains [Environment Variables](/guide/essentials/config/environment-variables)
- `.env.publish`: Contains Environment Variables for [publishing](/guide/essentials/publishing)
- `app.config.ts`: Contains [Runtime Config](/guide/essentials/config/runtime)
- `package.json`: The standard file used by your package manager
+1 -1
View File
@@ -41,4 +41,4 @@ export default defineConfig({
});
```
Options have JSDocs available in your editor, or you can read them in the source code: [`AutoIconsOptions`](./src/index.ts).
Options have JSDocs available in your editor, or you can read them in the source code: [`AutoIconsOptions`](https://github.com/wxt-dev/wxt/blob/main/packages/auto-icons/src/index.ts).
+12
View File
@@ -1,5 +1,17 @@
# Changelog
## v0.2.2
[compare changes](https://github.com/wxt-dev/wxt/compare/i18n-v0.2.1...i18n-v0.2.2)
### 🚀 Enhancements
- Add support for configuring the `locales` directory ([#1109](https://github.com/wxt-dev/wxt/pull/1109))
### ❤️ Contributors
- Bread Grocery <breadgrocery@gmail.com>
## v0.2.1
[compare changes](https://github.com/wxt-dev/wxt/compare/i18n-v0.2.0...i18n-v0.2.1)
+15
View File
@@ -98,6 +98,21 @@ And you're done! Using WXT, you get type-safety out of the box.
i18n.t('helloWorld'); // "Hello world!";
```
## Configuration
The module can be configured via the `i18n` config:
```ts
export default defineConfig({
modules: ['@wxt-dev/i18n'],
i18n: {
// ...
},
});
```
Options have JSDocs available in your editor, or you can read them in the source code: [`I18nOptions`](https://github.com/wxt-dev/wxt/blob/main/packages/i18n/src/module.ts).
## Messages File Format
> [!DANGER]
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@wxt-dev/i18n",
"description": "Type-safe wrapper around browser.i18n.getMessage with additional features",
"version": "0.2.1",
"version": "0.2.2",
"type": "module",
"repository": {
"type": "git",
+27 -7
View File
@@ -23,11 +23,11 @@ import { watch } from 'chokidar';
import { GeneratedPublicFile, WxtDirFileEntry } from 'wxt';
import { writeFile } from 'node:fs/promises';
export default defineWxtModule({
export default defineWxtModule<I18nOptions>({
name: '@wxt-dev/i18n',
configKey: 'i18n',
imports: [{ from: '#i18n', name: 'i18n' }],
setup(wxt) {
setup(wxt, options) {
if (wxt.config.manifest.default_locale == null) {
wxt.logger.warn(
`\`[i18n]\` manifest.default_locale not set, \`@wxt-dev/i18n\` disabled.`,
@@ -38,9 +38,12 @@ export default defineWxtModule({
'`[i18n]` Default locale: ' + wxt.config.manifest.default_locale,
);
const { localesDir = resolve(wxt.config.srcDir, 'locales') } =
options ?? {};
const getLocalizationFiles = async () => {
const files = await glob('locales/*', {
cwd: wxt.config.srcDir,
const files = await glob('*.{json,json5,yml,yaml,toml}', {
cwd: localesDir,
absolute: true,
});
return files.map((file) => ({
@@ -71,7 +74,7 @@ export default defineWxtModule({
)!;
if (defaultLocaleFile == null) {
throw Error(
`\`[i18n]\` Required localization file does not exist: \`<srcDir>/locales/${wxt.config.manifest.default_locale}.{json|json5|yml|yaml|toml}\``,
`\`[i18n]\` Required localization file does not exist: \`<localesDir>/${wxt.config.manifest.default_locale}.{json|json5|yml|yaml|toml}\``,
);
}
@@ -154,9 +157,26 @@ export { type GeneratedI18nStructure }
if (wxt.config.command === 'serve') {
wxt.hooks.hookOnce('build:done', () => {
const watcher = watch(resolve(wxt.config.srcDir, 'locales'));
const watcher = watch(localesDir);
watcher.on('change', updateLocalizations);
});
}
},
});
/**
* Options for the i18n module
*/
export interface I18nOptions {
/**
* Directory containing files that define the translations.
* @default "${config.srcDir}/locales"
*/
localesDir?: string;
}
declare module 'wxt' {
export interface InlineConfig {
i18n?: I18nOptions;
}
}
+1 -1
View File
@@ -44,4 +44,4 @@ export default defineConfig({
});
```
Options have JSDocs available in your editor, or you can read them in the source code: [`UnoCSSOptions`](./src/index.ts).
Options have JSDocs available in your editor, or you can read them in the source code: [`UnoCSSOptions`](https://github.com/wxt-dev/wxt/blob/main/packages/auto-icons/src/index.ts).
+3 -3
View File
@@ -14,8 +14,8 @@
### ❤️ Contributors
- Craig Slusher <cslush@gmail.com>
- Aaron <aaronklinker1@gmail.com>
- Aaron ([@aklinker1](http://github.com/aklinker1))
- Craig Slusher ([@sleekslush](http://github.com/sleekslush))
## v0.19.12
@@ -2578,4 +2578,4 @@ Initial release of WXT. Full support for production builds and initial toolkit f
### 🤖 CI
- Create validation workflow ([#12](https://github.com/wxt-dev/wxt/pull/12))
- Create release workflow ([#13](https://github.com/wxt-dev/wxt/pull/13))
- Create release workflow ([#13](https://github.com/wxt-dev/wxt/pull/13))