Skip to content

Commit 3524f7d

Browse files
committed
feat(i18n): adds local support
1 parent c0edfca commit 3524f7d

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

.eslintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
root: true,
33
plugins: ['@dvcol/presets'],
4-
extends: [ 'plugin:@dvcol/presets/vue', 'plugin:@dvcol/presets/base','plugin:@dvcol/presets/jest', 'plugin:@dvcol/presets/vitest'],
4+
extends: ['plugin:@dvcol/presets/base', 'plugin:@dvcol/presets/vue', 'plugin:@dvcol/presets/jest', 'plugin:@dvcol/presets/vitest'],
55
// to apply jest linting even-though we use vitest
66
settings: { jest: { version: 27 } },
77
rules: {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@commitlint/config-conventional": "^17.4.4",
4242
"@dvcol/eslint-plugin-presets": "^1.3.2",
4343
"@dvcol/stylelint-plugin-presets": "^1.1.0",
44-
"@dvcol/web-extension-utils": "^2.2.0",
44+
"@dvcol/web-extension-utils": "^2.3.0",
4545
"@types/chrome": "^0.0.224",
4646
"@types/fs-extra": "^11.0.1",
4747
"@types/jsdom": "^21.1.0",

pnpm-lock.yaml

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/manifest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const manifest: Manifest.WebExtensionManifest = {
1111
name: pkg.title || pkg.name,
1212
version: pkg.version,
1313
description: pkg.description,
14-
// default_locale: 'en', // TODO i18n
14+
default_locale: 'en',
1515
icons: {
1616
16: 'icons/icon-512.png',
1717
48: 'icons/icon-512.png',

scripts/prepare.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { exec } from 'child_process';
22

3+
import { mergeJson } from '@dvcol/web-extension-utils/common';
34
import { watch } from 'chokidar';
45
import fs from 'fs-extra';
56

@@ -28,8 +29,10 @@ const copyViews = async (views = ['options', 'popup']) => views.map(copyIndexHtm
2829
/**
2930
* Copy extension icons to dist folder
3031
*/
31-
const copyIcons = async () =>
32-
isDev ? fs.symlink(resolveParent('icons'), resolveParent('dist/icons'), 'junction') : fs.copySync('icons', 'dist/icons', { overwrite: true });
32+
const copyIcons = async (_isDev: boolean) => {
33+
if (_isDev) return fs.symlink(resolveParent('icons'), resolveParent('dist/icons'), 'junction');
34+
return fs.copySync('icons', 'dist/icons', { overwrite: true });
35+
};
3336

3437
/**
3538
* Copy extension icons to dist folder
@@ -42,7 +45,12 @@ const copyAssets = async () => fs.symlink(resolveParent('src/assets'), resolvePa
4245
const prepare = async (hmr = isDev) => {
4346
writeManifest().catch(e => console.error('Failed to write manifest.json', e));
4447

45-
copyIcons().catch(e => console.error('Failed to copy extension icons', e));
48+
copyIcons(isDev).catch(e => console.error('Failed to copy extension icons', e));
49+
50+
mergeJson({
51+
pattern: 'src/i18n/en/**/*.json',
52+
output: 'dist/_locales/en/messages.json',
53+
}).catch((e: Error) => console.error('Failed to merge jsons', e));
4654

4755
if (hmr) {
4856
console.log('Watching changes ...');
@@ -65,6 +73,13 @@ const prepare = async (hmr = isDev) => {
6573
}
6674
});
6775

76+
watch([resolveParent('src/i18n/en/**/*.json')]).on('change', () => {
77+
mergeJson({
78+
pattern: 'src/i18n/en/**/*.json',
79+
output: 'dist/_locales/en/messages.json',
80+
}).catch((e: Error) => console.error('Failed to merge jsons', e));
81+
});
82+
6883
copyAssets().catch(e => console.error('Failed to write assets', e));
6984
}
7085
};

src/i18n/en/global.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"global__app_name": {
3+
"message": "Side Trakt",
4+
"description": "Extension name."
5+
},
6+
"global__app_title": {
7+
"message": "Side Trakt (companion app for Traskt.tv)",
8+
"description": "Extension title."
9+
},
10+
"global__app_title_popup": {
11+
"message": "Side Trakt Popup",
12+
"description": "Popup page title field."
13+
},
14+
"global__app_title_options": {
15+
"message": "Side Trakt Options",
16+
"description": "Options page title field."
17+
}
18+
}

vite.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,7 @@ export default defineConfig(({ command }) => ({
6161
globals: true,
6262
environment: 'jsdom',
6363
},
64+
optimizeDeps: {
65+
exclude: ['path', 'fast-glob'],
66+
},
6467
}));

0 commit comments

Comments
 (0)