Skip to content

Commit a66dabb

Browse files
author
Guillaume Chau
committed
feat(ui): plugin locales
1 parent 9a852d6 commit a66dabb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+451
-83
lines changed

docs/plugin-dev-ui.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This guide will walk you through the development of cli-ui specific features for
1010
- [Shared data](#shared-data)
1111
- [Plugin actions](#plugin-actions)
1212
- [Inter-process communication (IPC)](#inter-process-communication-ipc)
13+
- [Localization](#localization)
1314
- [Hooks](#hooks)
1415
- [Public static files](#public-static-files)
1516

@@ -350,11 +351,19 @@ ClientAddonApi.component('vue-webpack-dashboard', WebpackDashboard)
350351
ClientAddonApi.addRoutes('vue-webpack', [
351352
{ path: '', name: 'test-webpack-route', component: TestView }
352353
])
354+
355+
// You can translate your plugin components
356+
// Load the locale files (uses vue-i18n)
357+
const locales = require.context('./locales', true, /[a-z0-9]+\.json$/i)
358+
locales.keys().forEach(key => {
359+
const locale = key.match(/([a-z0-9]+)\./i)[1]
360+
ClientAddonApi.addLocalization(locale, locales(key))
361+
})
353362
```
354363

355364
The cli-ui registers `Vue` and `ClientAddonApi` as global variables in the `window` scope.
356365

357-
In your components, you can use all the components and the CSS classes of [@vue/ui](https://github.com/vuejs/ui) and [@vue/cli-ui](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-ui/src/components) in order to keep the look and feel consistent.
366+
In your components, you can use all the components and the CSS classes of [@vue/ui](https://github.com/vuejs/ui) and [@vue/cli-ui](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-ui/src/components) in order to keep the look and feel consistent. You can also translate the strings with [vue-i18n](https://github.com/kazupon/vue-i18n) which is included.
358367
#### Register the client addon
359368

360369
Back to the `ui.js` file, use the `api.addClientAddon` method with a require query to the built folder:
@@ -632,6 +641,43 @@ api.ipcSend({
632641
})
633642
```
634643

644+
### Localization
645+
646+
You can put locale files compatible with [vue-i18n](https://github.com/kazupon/vue-i18n) in a `locales` folder at the root of your plugin. They will be automatically loaded into the client when the project is opened. You can then use `$t` to translate strings in your components and other vue-i18n helpers. Also, the strings used in the UI API (like `describeTask`) will go through vue-i18n as well to you can localize them.
647+
648+
Example `locales` folder:
649+
650+
```
651+
vue-cli-plugin/locales/en.json
652+
vue-cli-plugin/locales/fr.json
653+
```
654+
655+
Example usage in API:
656+
657+
```js
658+
api.describeConfig({
659+
// vue-i18n path
660+
description: 'my-plugin.config.foo'
661+
})
662+
```
663+
664+
Example usage in components:
665+
666+
```html
667+
<VueButton>{{ $t('my-plugin.actions.bar') }}</VueButton>
668+
```
669+
670+
You can also load the locale files in a client addon if you prefer, using the `ClientAddonApi`:
671+
672+
```js
673+
// Load the locale files (uses vue-i18n)
674+
const locales = require.context('./locales', true, /[a-z0-9]+\.json$/i)
675+
locales.keys().forEach(key => {
676+
const locale = key.match(/([a-z0-9]+)\./i)[1]
677+
ClientAddonApi.addLocalization(locale, locales(key))
678+
})
679+
```
680+
635681
### Hooks
636682

637683
Hooks allows to react to certain cli-ui events.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"eslint": {
3+
"config": {
4+
"eslint": {
5+
"description": "Error checking & Code quality",
6+
"groups": {
7+
"strongly-recommended": "Strongly recommended",
8+
"recommended": "Recommended"
9+
}
10+
}
11+
}
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"eslint": {
3+
"config": {
4+
"eslint": {
5+
"description": "Vérification des erreurs & Qualité du code",
6+
"groups": {
7+
"strongly-recommended": "Fortement recommandé",
8+
"recommended": "Recommandé"
9+
}
10+
}
11+
}
12+
}
13+
}

packages/@vue/cli-plugin-eslint/ui.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = api => {
55
api.describeConfig({
66
id: 'eslintrc',
77
name: 'ESLint configuration',
8-
description: 'Error checking & Code quality',
8+
description: 'eslint.config.eslint.description',
99
link: 'https://eslint.org',
1010
icon: '.eslintrc.json',
1111
files: {
@@ -19,7 +19,7 @@ module.exports = api => {
1919
name: 'vue/attribute-hyphenation',
2020
type: 'list',
2121
message: 'Attribute hyphenation',
22-
group: 'Strongly recommended',
22+
group: 'eslint.config.eslint.groups.strongly-recommended',
2323
description: 'Enforce attribute naming style in template (`my-prop` or `myProp`)',
2424
link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/attribute-hyphenation.md',
2525
default: JSON.stringify('off'),
@@ -43,7 +43,7 @@ module.exports = api => {
4343
name: 'vue/html-end-tags',
4444
type: 'confirm',
4545
message: 'Template end tags style',
46-
group: 'Strongly recommended',
46+
group: 'eslint.config.eslint.groups.strongly-recommended',
4747
description: 'End tag on Void elements, end tags and self-closing opening tags',
4848
link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-end-tags.md',
4949
default: false,
@@ -55,7 +55,7 @@ module.exports = api => {
5555
name: 'vue/html-indent',
5656
type: 'list',
5757
message: 'Template indentation',
58-
group: 'Strongly recommended',
58+
group: 'eslint.config.eslint.groups.strongly-recommended',
5959
description: 'Enforce indentation in template',
6060
link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-indent.md',
6161
default: JSON.stringify('off'),
@@ -87,7 +87,7 @@ module.exports = api => {
8787
name: 'vue/html-self-closing',
8888
type: 'confirm',
8989
message: 'Template tag self-closing style',
90-
group: 'Strongly recommended',
90+
group: 'eslint.config.eslint.groups.strongly-recommended',
9191
description: 'Self-close any component or non-Void element tags',
9292
link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-self-closing.md',
9393
default: false,
@@ -99,7 +99,7 @@ module.exports = api => {
9999
name: 'vue/require-default-prop',
100100
type: 'confirm',
101101
message: 'Require default in required props',
102-
group: 'Strongly recommended',
102+
group: 'eslint.config.eslint.groups.strongly-recommended',
103103
description: 'This rule requires default value to be set for each props that are not marked as `required`',
104104
link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/require-default-prop.md',
105105
default: false,
@@ -111,7 +111,7 @@ module.exports = api => {
111111
name: 'vue/require-prop-types',
112112
type: 'confirm',
113113
message: 'Require types for props',
114-
group: 'Strongly recommended',
114+
group: 'eslint.config.eslint.groups.strongly-recommended',
115115
description: 'In committed code, prop definitions should always be as detailed as possible, specifying at least type(s)',
116116
link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/require-prop-types.md',
117117
default: false,
@@ -123,7 +123,7 @@ module.exports = api => {
123123
name: 'vue/attributes-order',
124124
type: 'confirm',
125125
message: 'Attribute order',
126-
group: 'Recommended',
126+
group: 'eslint.config.eslint.groups.recommended',
127127
description: 'This rule aims to enforce ordering of component attributes (the default order is specified in the Vue style guide)',
128128
link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/attributes-order.md',
129129
default: false,
@@ -135,7 +135,7 @@ module.exports = api => {
135135
name: 'vue/html-quotes',
136136
type: 'list',
137137
message: 'Attribute quote style',
138-
group: 'Recommended',
138+
group: 'eslint.config.eslint.groups.recommended',
139139
description: 'Enforce style of the attribute quotes in templates',
140140
link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-quotes.md',
141141
default: JSON.stringify('off'),
@@ -159,7 +159,7 @@ module.exports = api => {
159159
name: 'vue/order-in-components',
160160
type: 'confirm',
161161
message: 'Component options order',
162-
group: 'Recommended',
162+
group: 'eslint.config.eslint.groups.recommended',
163163
description: 'This rule aims to enforce ordering of component options (the default order is specified in the Vue style guide)',
164164
link: 'https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/order-in-components.md',
165165
default: false,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"vue-webpack": {
3+
"dashboard": {
4+
"title": "Dashboard"
5+
},
6+
"analyzer": {
7+
"title": "Analyzer"
8+
},
9+
"tasks": {
10+
"serve": {
11+
"description": "Compiles and hot-reloads for development"
12+
},
13+
"build": {
14+
"description": "Compiles and minifies for production"
15+
}
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"vue-webpack": {
3+
"dashboard": {
4+
"title": "Tableau de bord"
5+
},
6+
"analyzer": {
7+
"title": "Analyseur"
8+
},
9+
"tasks": {
10+
"serve": {
11+
"description": "Compile et recharge à chaud pour le développement"
12+
},
13+
"build": {
14+
"description": "Compile et minifie pour la production"
15+
}
16+
}
17+
}
18+
}

packages/@vue/cli-service/ui.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ module.exports = api => {
3434
views: [
3535
{
3636
id: 'vue-webpack-dashboard',
37-
label: 'Dashboard',
37+
label: 'vue-webpack.dashboard.title',
3838
icon: 'dashboard',
3939
component: 'vue-webpack-dashboard'
4040
},
4141
{
4242
id: 'vue-webpack-analyzer',
43-
label: 'Analyzer',
43+
label: 'vue-webpack.analyzer.title',
4444
icon: 'donut_large',
4545
component: 'vue-webpack-analyzer'
4646
}
@@ -49,7 +49,7 @@ module.exports = api => {
4949
}
5050
api.describeTask({
5151
match: /vue-cli-service serve/,
52-
description: 'Compiles and hot-reloads for development',
52+
description: 'vue-webpack.tasks.serve.description',
5353
link: 'https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#serve',
5454
prompts: [
5555
{
@@ -121,7 +121,7 @@ module.exports = api => {
121121
})
122122
api.describeTask({
123123
match: /vue-cli-service build/,
124-
description: 'Compiles and minifies for production',
124+
description: 'vue-webpack.tasks.build.description',
125125
link: 'https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#build',
126126
prompts: [
127127
{

packages/@vue/cli-ui-addon-webpack/src/components/AssetList.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<template>
22
<div class="asset-list list-block">
33
<div class="content">
4-
<div class="title">Assets</div>
4+
<div class="title">
5+
{{ $t('vue-webpack.dashboard.asset-list.title') }}
6+
</div>
57

68
<VueIcon
79
v-if="!assetsSorted.length"

packages/@vue/cli-ui-addon-webpack/src/components/AssetListItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
v-if="!asset.secondary && asset.big"
1818
icon="warning"
1919
class="icon"
20-
v-tooltip="'This asset is big, consider using Code splitting to create smaller assets.'"
20+
v-tooltip="$t('vue-webpack.dashboard.asset-list.size-warning')"
2121
/>
2222
</div>
2323
</div>

packages/@vue/cli-ui-addon-webpack/src/components/BuildStatus.vue

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,49 @@
22
<div class="build-status">
33
<div class="content">
44
<div class="info-block status">
5-
<div class="label">Status</div>
6-
<div class="value">{{ status || 'Idle' }}</div>
5+
<div class="label">
6+
{{ $t('vue-webpack.dashboard.build-status.labels.status') }}
7+
</div>
8+
<div class="value">{{ $t(`vue-webpack.dashboard.webpack-status.${status || 'Idle'}`) }}</div>
79
</div>
810
<div class="info-block errors">
9-
<div class="label">Errors</div>
11+
<div class="label">
12+
{{ $t('vue-webpack.dashboard.build-status.labels.errors') }}
13+
</div>
1014
<div class="value">{{ errors.length }}</div>
1115
</div>
1216
<div class="info-block warnings">
13-
<div class="label">Warnings</div>
17+
<div class="label">
18+
{{ $t('vue-webpack.dashboard.build-status.labels.warnings') }}
19+
</div>
1420
<div class="value">{{ warnings.length }}</div>
1521
</div>
1622
<div class="info-block assets">
17-
<div class="label">Assets</div>
23+
<div class="label">
24+
{{ $t('vue-webpack.dashboard.build-status.labels.assets') }}
25+
</div>
1826
<div class="value">
1927
{{ assetsTotalSize | size('B') }}
20-
<span class="secondary">({{ sizeField }})</span>
28+
<span class="secondary">
29+
({{ $t(`vue-webpack.sizes.${sizeField}`) }})
30+
</span>
2131
</div>
2232
</div>
2333
<div class="info-block modules">
24-
<div class="label">Modules</div>
34+
<div class="label">
35+
{{ $t('vue-webpack.dashboard.build-status.labels.modules') }}
36+
</div>
2537
<div class="value">
2638
{{ modulesTotalSize | size('B') }}
27-
<span class="secondary">({{ sizeField }})</span>
39+
<span class="secondary">
40+
({{ $t(`vue-webpack.sizes.${sizeField}`) }})
41+
</span>
2842
</div>
2943
</div>
3044
<div class="info-block dep-modules">
31-
<div class="label">Dependencies</div>
45+
<div class="label">
46+
{{ $t('vue-webpack.dashboard.build-status.labels.deps') }}
47+
</div>
3248
<div class="value">
3349
{{ depModulesTotalSize | size('B') }}
3450
<span class="secondary">

packages/@vue/cli-ui-addon-webpack/src/components/ModuleList.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<template>
22
<div class="module-list list-block">
33
<div class="content">
4-
<div class="title">Dependencies</div>
4+
<div class="title">
5+
{{ $t('vue-webpack.dashboard.module-list.title') }}
6+
</div>
57

68
<VueIcon
79
v-if="!depModules.length"

packages/@vue/cli-ui-addon-webpack/src/components/SpeedStats.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<template>
22
<div class="speed-stats">
33
<div class="content">
4-
<div class="title">Speed stats</div>
4+
<div class="title">
5+
{{ $t('vue-webpack.dashboard.speed-stats.title') }}
6+
</div>
57

68
<VueIcon
79
v-if="!assetsTotalSize"

0 commit comments

Comments
 (0)