Skip to content

Commit c191636

Browse files
authored
feat: move to GA from experimental for petite-vue-i18n (#1862)
* feat: move to GA from experimental for petite-vue-i18n * docs: add docs for petite-vue-i18n * fix: textlint errors
1 parent 23f5134 commit c191636

File tree

6 files changed

+281
-29
lines changed

6 files changed

+281
-29
lines changed

.textlintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ module.exports = {
3636
'SFC',
3737
'PHP',
3838
'SSR',
39-
'MIT'
39+
'MIT',
40+
'PNPM'
4041
]
4142
},
4243
'abbr-within-parentheses': true,

docs/.vitepress/config.mts

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ function sidebarGuide() {
177177
{
178178
text: 'Custom Message Format',
179179
link: '/guide/advanced/format'
180+
},
181+
{
182+
text: 'Petite Vue I18n',
183+
link: '/guide/advanced/lite'
180184
}
181185
]
182186
},

docs/guide/advanced/lite.md

+229
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
# Small size subset of Vue I18n
2+
3+
:::warning NOTICE
4+
`petite-vue-i18n` **is not still GA.
5+
It will be GA with the release of Vue I18n v10.
6+
:::
7+
8+
`petite-vue-i18n` is an alternative distribution of Vue I18n, which provides only minimal features.
9+
10+
## What is the difference from Vue I18n ?
11+
12+
- The Size is smaller than vue-i18n
13+
- CDN or without a Bundler
14+
- Package reduce size: runtime + compiler `~32%`, runtime only `~45%`
15+
- `petite-vue-i18n`: runtime + compiler `~9.61KB`, runtime only `~5.51KB` (production build, brotli compression)
16+
- `vue-i18n`: runtime + compiler `~14.18KB`, runtime only `~10.12KB` (production build, brotli compression)
17+
- ES Modules for browser
18+
- Package reduce size: runtime + compiler `~32%`, runtime only `~45%`
19+
- `petite-vue-i18n`: runtime + compiler `~10.51KB`, runtime only `~6.20KB` (production build, brotli compression)
20+
- `vue-i18n`: runtime + compiler `~15.40KB`, runtime only `~11.12KB` (production build, brotli compression)
21+
- Application bundle size
22+
- Reduce size from `vue-i18n`: `~10%` (Code size check measurement of [vue-i18n](https://github.com/intlify/vue-i18n-next/tree/master/packages/size-check-vue-i18n) and [petite-vue-i18n](https://github.com/intlify/vue-i18n-next/tree/master/packages/size-check-petite-vue-i18n))
23+
- The legacy API is not supported, **only the composition API**
24+
- The APIs for the following DateTime Formats, Number Formats, and utilities aren’t included. **Translation only**
25+
- `n`, `$n`
26+
- `d`, `$d`
27+
- `rt`, `$rt`
28+
- `tm`, `$tm`
29+
- `getDateTimeFormat`, `setDateTimeFormat`, `mergeDateTimeFormat`
30+
- `getNumberFormat`, `setNumberFormat`, `mergeNumberFormat`
31+
- **The only locale messages that can be handled are simple key-values**. if you can handle hierarchical locale messages, you need to customize them using the API
32+
- The algorithm of local fallback is **the array order** specified in `fallbackLocale`
33+
- Custom directive `v-t` isn’t included
34+
- The following components provided by `vue-i18n` aren’t included
35+
- Translation `i18n-t`
36+
- DatetimeFormat `i18n-d`
37+
- NumberFormat `i18n-n`
38+
39+
## The use case of `petite-vue-i18n`
40+
41+
`vue-i18n` includes various i18n features such as translation, datetimes format and number formats. Some projects may only use translation and not datetime formats. At the moment, even in that case, the code for that feature is included.
42+
43+
If your project only uses `t` or `$t` API for translation, so we recommended you would use `petite-vue-i18n` better than `vue-i18n`. And your project needs the features of `vue-i18n`, you can smoothly migrate from `petite-vue-i18n` to `vue-i18n`. This means that it’s progressive enhancement.
44+
45+
## Installation
46+
47+
Basically, it’s the same as installing `vue-i18n`. The only difference is that the part of URL or part of path are changed from `vue-i18n` to `petite-vue-i18n`.
48+
49+
### CDN
50+
You need to insert the following scripts to end of `<head>`:
51+
52+
```html
53+
<script src="https://unpkg.com/vue@next"></script>
54+
<script src="https://unpkg.com/petite-vue-i18n"></script>
55+
```
56+
57+
The following is the application code with the script tag:
58+
59+
```html
60+
<script>
61+
const { createApp } = Vue
62+
const { createI18n } = PetiteVueI18n
63+
64+
const i18n = createI18n({
65+
// something vue-i18n options here ...
66+
})
67+
68+
const app = createApp({
69+
// something vue options here ...
70+
})
71+
72+
app.use(i18n)
73+
app.mount('#app')
74+
</script>
75+
```
76+
77+
### Package managers
78+
79+
::: code-group
80+
81+
```sh [npm]
82+
npm install petite-vue-i18n@next --save
83+
```
84+
85+
```sh [yarn]
86+
yarn add petite-vue-i18n@next
87+
```
88+
89+
```sh [pnpm]
90+
pnpm add petite-vue-i18n@next
91+
```
92+
:::
93+
94+
95+
```js
96+
import { createApp } from 'vue'
97+
import { createI18n } from 'petite-vue-i18n'
98+
99+
const i18n = createI18n({
100+
// something vue-i18n options here ...
101+
})
102+
103+
const app = createApp({
104+
// something vue options here ...
105+
})
106+
107+
app.use(i18n)
108+
app.mount('#app')
109+
```
110+
111+
## Usages
112+
113+
### Hello world
114+
115+
Template:
116+
```html
117+
<div id="app">
118+
<h1>{{ t('hello world') }}</h1>
119+
</div>
120+
```
121+
122+
Scripts:
123+
```js
124+
const { createApp } = Vue
125+
const { createI18n, useI18n } = PetiteVueI18n
126+
// or for ES modules
127+
// import { createApp } from 'vue'
128+
// import { createI18n } from 'petite-vue-i18n'
129+
130+
const i18n = createI18n({
131+
locale: 'en',
132+
messages: {
133+
en: {
134+
'hello world': 'Hello world!'
135+
},
136+
ja: {
137+
'hello world': 'こんにちは、世界!'
138+
}
139+
}
140+
})
141+
142+
// define App component
143+
const App = {
144+
setup() {
145+
const { t } = useI18n()
146+
return { t }
147+
}
148+
}
149+
150+
const app = createApp(App)
151+
152+
app.use(i18n)
153+
app.mount('#app')
154+
```
155+
156+
### Use the same message resolver and locale fallbacker as `vue-i18n`
157+
158+
In `petite-vue-i18n`, the message resolver and locale fallbacker use simple implementations to optimize code size, as described in the [differences section](https://github.com/intlify/vue-i18n-next/tree/master/packages/petite-vue-i18n#question-what-is-the-difference-from-vue-i18n-), as the belows:
159+
160+
- message resolver
161+
- Resolves key-value style locale messages
162+
- About implementation, see the [here](https://github.com/intlify/vue-i18n-next/blob/2d4d2a342f8bae134665a0b7cd945fb8b638839a/packages/core-base/src/resolver.ts#L305-L307)
163+
- locale fallbacker
164+
- Fallback according to the array order specified in `fallbackLocale`
165+
- If a simple string locale is specified, fallback to that locale
166+
- About implementation, see the [here](https://github.com/intlify/vue-i18n-next/blob/2d4d2a342f8bae134665a0b7cd945fb8b638839a/packages/core-base/src/fallbacker.ts#L40-L58)
167+
168+
If you want to use the same message resolver and locale fallbacker as `vue-i18n`, you can change them using the API.
169+
170+
Note that at this time, only bundlers like vite and webpack are supported.
171+
172+
You need to install `@intlify/core-base` to your project with package manager.
173+
174+
::: code-group
175+
176+
```sh [npm]
177+
npm install --save @intlify/core-base@next
178+
```
179+
180+
```sh [yarn]
181+
yarn add @intlify/core-base@next
182+
```
183+
184+
```sh [pnpm]
185+
pnpm add @intlify/core-base@next
186+
```
187+
:::
188+
189+
Then, at the entry point of the application, configure the message resolver and locale fallbacker using the API as the below:
190+
191+
```js
192+
import { createApp } from 'vue'
193+
import { createI18n } from 'petite-vue-i18n'
194+
import {
195+
registerMessageResolver, // register the message resolver API
196+
resolveValue, // message resolver of vue-i18n which is used by default
197+
registerLocaleFallbacker, // register the locale fallbacker API
198+
fallbackWithLocaleChain // locale fallbacker of vue-i18n which is used by default
199+
} from '@intlify/core-base'
200+
201+
// register message resolver of vue-i18n
202+
registerMessageResolver(resolveValue)
203+
204+
// register locale fallbacker of vue-i18n
205+
registerLocaleFallbacker(fallbackWithLocaleChain)
206+
207+
// some thing code ...
208+
// ...
209+
```
210+
211+
With the above settings, locale message resolving and locale fallbacking will be handled in the same way as in vue-i18n, note that the code size will increase slightly.
212+
213+
### Switch without changing import id
214+
215+
You can switch from vue-i18n to petite-vue-i18n in your application using npm alias without changing the import id.
216+
217+
package.json:
218+
```diff
219+
{
220+
// ...
221+
"dependencies": {
222+
"vue": "^3.4.14",
223+
- "vue-i18n": "^10.0.0"
224+
+ "vue-i18n": "npm:petite-vue-i18n@^10.0.0"
225+
},
226+
}
227+
```
228+
229+
You need `@intlify/unplugin-vue-i18n` to build your application.

packages/petite-vue-i18n/README.md

+42-25
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ Small size subset of Vue I18n
44

55
`petite-vue-i18n` is an alternative distribution of Vue I18n, which provides only minimal features.
66

7-
## :question: What is the difference from Vue I18n ?
7+
## What is the difference from Vue I18n ?
88

99
- The Size is smaller than vue-i18n
1010
- CDN or without a Bundler
11-
- Reduce size: runtime + compiler `~36%`, runtime only `~49%`
12-
- `petite-vue-i18n`: runtime + compiler `~7.48KB`, runtime only `~4.07KB` (production build, brotli compression)
13-
- `vue-i18n`: runtime + compiler `~11.71KB`, runtime only `~8.30KB` (production build, brotli compression)
11+
- Package reduce size: runtime + compiler `~32%`, runtime only `~45%`
12+
- `petite-vue-i18n`: runtime + compiler `~9.61KB`, runtime only `~5.51KB` (production build, brotli compression)
13+
- `vue-i18n`: runtime + compiler `~14.18KB`, runtime only `~10.12KB` (production build, brotli compression)
1414
- ES Modules for browser
15-
- Reduce size: runtime + compiler `~35%`, runtime only `~49%`
16-
- `petite-vue-i18n`: runtime + compiler `~7.51KB`, runtime only `~4.09KB` (production build, brotli compression)
17-
- `vue-i18n`: runtime + compiler `~11.73KB`, runtime only `~8.34KB` (production build, brotli compression)
18-
- Bundle size
19-
- Reduce size from `vue-i18n`: runtime + compiler `~14%`, runtime only `~22%` (Code size check measurement of [vue-i18n](https://github.com/intlify/vue-i18n-next/tree/master/packages/size-check-vue-i18n) and [petite-vue-i18n](https://github.com/intlify/vue-i18n-next/tree/master/packages/size-check-petite-vue-i18n))
15+
- Package reduce size: runtime + compiler `~32%`, runtime only `~45%`
16+
- `petite-vue-i18n`: runtime + compiler `~10.51KB`, runtime only `~6.20KB` (production build, brotli compression)
17+
- `vue-i18n`: runtime + compiler `~15.40KB`, runtime only `~11.12KB` (production build, brotli compression)
18+
- Application bundle size
19+
- Reduce size from `vue-i18n`: `~10%` (Code size check measurement of [vue-i18n](https://github.com/intlify/vue-i18n-next/tree/master/packages/size-check-vue-i18n) and [petite-vue-i18n](https://github.com/intlify/vue-i18n-next/tree/master/packages/size-check-petite-vue-i18n))
2020
- The legacy API is not supported, **only the composition API**
2121
- The APIs for the following DateTime Formats, Number Formats, and utilities aren’t included. **Translation only**
2222
- `n`, `$n`
@@ -33,21 +33,13 @@ Small size subset of Vue I18n
3333
- DatetimeFormat `i18n-d`
3434
- NumberFormat `i18n-n`
3535

36-
## :hammer: The use case of `petite-vue-i18n`
36+
## 🔨 The use case of `petite-vue-i18n`
3737

3838
`vue-i18n` includes various i18n features such as translation, datetimes format and number formats. Some projects may only use translation and not datetime formats. At the moment, even in that case, the code for that feature is included.
3939

4040
If your project only uses `t` or `$t` API for translation, so we recommended you would use `petite-vue-i18n` better than `vue-i18n`. And your project needs the features of `vue-i18n`, you can smoothly migrate from `petite-vue-i18n` to `vue-i18n`. This means that it’s progressive enhancement.
4141

42-
## :warning: About the supporting of `petite-vue-i18n`
43-
44-
Note that `petite-vue-i18n` is still experimental, and you may encounter bugs and unsupported use cases. Proceed at your own risk.
45-
46-
However, please don’t worry about it. Depending on the usage of `petite-vue-i18n` and the feedback, we would like to use it refer to the development of the next version of `vue-i18n`. This means we will to maintain it.
47-
48-
We welcome your feedback on `petite-vue-i18n`.
49-
50-
## :cd: Installation
42+
## 💿 Installation
5143

5244
Basically, it’s the same as installing `vue-i18n`. The only difference is that the part of URL or part of path are changed from `vue-i18n` to `petite-vue-i18n`.
5345

@@ -83,7 +75,12 @@ app.mount('#app')
8375

8476
NPM:
8577
```sh
86-
npm install petite-vue-i18n
78+
npm install petite-vue-i18n --save
79+
```
80+
81+
PNPM:
82+
```sh
83+
pnpm add petite-vue-i18n
8784
```
8885

8986
Yarn:
@@ -107,7 +104,7 @@ app.use(i18n)
107104
app.mount('#app')
108105
```
109106

110-
## :rocket: Usage
107+
## 🚀 Usages
111108

112109
### Hello world
113110

@@ -171,9 +168,11 @@ Note that at this time, only bundlers like vite and webpack are supported.
171168
You need to install `@intlify/core-base` to your project with package manager.
172169

173170
```sh
174-
$ npm install --save @intlify/core-base@alpha
175-
# or
176-
# yarn add @intlify/core-base@alpha
171+
npm install --save @intlify/core-base
172+
# for pnpm
173+
# pnpm add @intlify/core-base
174+
# for yarn
175+
# yarn add @intlify/core-base
177176
```
178177

179178
Then, at the entry point of the application, configure the message resolver and locale fallbacker using the API as the below:
@@ -200,6 +199,24 @@ registerLocaleFallbacker(fallbackWithLocaleChain)
200199

201200
With the above settings, locale message resolving and locale fallbacking will be handled in the same way as in vue-i18n, note that the code size will increase slightly.
202201

203-
## :copyright: License
202+
### Switch without changing import ID
203+
204+
You can switch from vue-i18n to petite-vue-i18n in your application using npm alias without changing the import ID.
205+
206+
Package.json:
207+
```diff
208+
{
209+
// ...
210+
"dependencies": {
211+
"vue": "^3.4.14",
212+
- "vue-i18n": "^10.0.0"
213+
+ "vue-i18n": "npm:petite-vue-i18n@^10.0.0"
214+
},
215+
}
216+
```
217+
218+
You need `@intlify/unplugin-vue-i18n` to build your application.
219+
220+
## ©️ License
204221

205222
[MIT](https://opensource.org/licenses/MIT)

packages/size-check-petite-vue-i18n/vite.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export default defineConfig({
2424
},
2525
resolve: {
2626
alias: {
27-
'vue-i18n': 'petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js'
27+
'vue-i18n': 'petite-vue-i18n/dist/petite-vue-i18n.runtime.esm-bundler.js'
28+
// 'vue-i18n': 'petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js'
2829
}
2930
},
3031
build: {

packages/size-check-vue-i18n/vite.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export default defineConfig({
2525
},
2626
resolve: {
2727
alias: {
28-
// 'vue-i18n': 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
29-
'vue-i18n': 'vue-i18n/dist/vue-i18n.esm-bundler.js'
28+
'vue-i18n': 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
29+
// 'vue-i18n': 'vue-i18n/dist/vue-i18n.esm-bundler.js'
3030
}
3131
},
3232
build: {

0 commit comments

Comments
 (0)