Skip to content

Commit d90976c

Browse files
committed
📝 docs: update docs
1 parent 2053a5a commit d90976c

File tree

1 file changed

+185
-2
lines changed

1 file changed

+185
-2
lines changed

README.md

Lines changed: 185 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,185 @@
11
# vue-i18n-locale-message
22

3-
i18n locale messages management tool for vue-i18n
3+
i18n locale messages management tool / library for vue-i18n
44

5-
:construction_worker: WIP
5+
## :cd: Installation
6+
7+
### npm
8+
9+
```sh
10+
npm install --save-dev vue-i18n-locale-message
11+
```
12+
13+
If you can globally use CLI only, you need `-g` option the below command.
14+
15+
```sh
16+
npm install -g vue-i18n-locale-message
17+
```
18+
19+
### yarn
20+
21+
```sh
22+
yarn add -D vue-i18n-locale-message
23+
```
24+
25+
If you can globally use CLI, you need `global` option the below command.
26+
27+
```sh
28+
yarn global vue-i18n-locale-message
29+
```
30+
31+
## :star: Features
32+
33+
- API
34+
- squeeze the locale messages from `i18n` custom block
35+
- infuse the locale messages to `i18n` custom block
36+
- CLI
37+
- squeeze the locale messages from `i18n` custom block
38+
- infuse the locale messages to `i18n` custom block
39+
40+
## :rocket: Usages
41+
42+
### API
43+
44+
```js
45+
const fs = require('fs')
46+
const { squeeze, infuse } = require('vue-i18n-locale-message')
47+
48+
// read single-file component contents
49+
// NOTE: about scheme of target contents, see the `SFCInfo` type at `types/index.d.ts
50+
const files = [
51+
{
52+
path: '/path/to/src/components/Modal.vue',
53+
content: `<template>
54+
...
55+
<i18n>
56+
{
57+
...
58+
}
59+
<i18n>`
60+
},
61+
// ...
62+
]
63+
64+
// squeeze locale messages i18n locale messages of from single-file components
65+
const messages = squeeze('/path/to/src', files)
66+
67+
// write squeezed locale messages
68+
fs.writeFileSync('/path/to/src/messages.json')
69+
70+
// after update locale messages with translation service or your code, it read locale messsages
71+
const translatedMessages = require'/path/to/src/translated')
72+
73+
// infuse locale message to single-file components
74+
const updatedFiles = infuse('/path/to/src', files, translatedMessages)
75+
76+
// write updated single-file component
77+
updateFiles.forEach(file => {
78+
fs.writeFileSync(file.path, file.content)
79+
})
80+
```
81+
82+
### CLI
83+
#### Squeeze
84+
85+
```sh
86+
vue-i18n-locale-message squeeze --target=./src --output=./messages.json
87+
```
88+
89+
#### Infuse
90+
91+
```sh
92+
vue-i18n-locale-message infuse --target=./src --message=./translated.json
93+
```
94+
95+
## :raising_hand: Motivations
96+
97+
The big motivation is as follows.
98+
99+
- :tired_face: Hard to integrate locale messages for localization services
100+
- :tired_face: Hard to maintain consistency of locale message keys (`eslint-plugin-vue-i18n` need it!)
101+
- :tired_face: Requested by third bender tools (`vue-i18n-ally` and etc ...)
102+
103+
## :notebook: Locale message squeezing rules
104+
105+
The structure of locale messages to be squeezed is layered with the **directory structure** and **single-file component (`.vue`) filename**.
106+
107+
This repotitory `demo` project directory structure:
108+
109+
```sh
110+
cd demo
111+
tree src
112+
src
113+
├── App.vue
114+
├── components
115+
│   ├── Modal.vue
116+
│   └── nest
117+
│   └── RankingTable.vue
118+
├── i18n.js
119+
├── locales
120+
│   ├── en.json
121+
│   └── ja.json
122+
├── main.js
123+
└── pages
124+
└── Login.vue
125+
126+
4 directories, 8 files
127+
```
128+
129+
You use `vue-cli-locale-message` CLI, run `squeeze` command as follows:
130+
131+
```sh
132+
vue-i18n-locale-message squeeze --target=./src --output=./messages.json
133+
cat ./messages.json
134+
```
135+
136+
You will get the following JSON structure (the following output results are commented To make it easier to understand):
137+
138+
```json5
139+
{
140+
"ja": { // for `ja` locale`
141+
"App": { // src/App.vue
142+
"title": "アプリケーション",
143+
"lang": "言語切り替え"
144+
},
145+
"components": { // src/components
146+
"Modal": { // src/components/Modal.vue
147+
"ok": "OK",
148+
"cancel": "キャンセル"
149+
}
150+
},
151+
"pages": { // src/pages
152+
"Login": { // src/pages/Login.vue
153+
"id": "ユーザーID",
154+
"password": "パスワード",
155+
"confirm": "パスワードの確認入力",
156+
"button": "ログイン"
157+
}
158+
}
159+
},
160+
"en": { // for `en` locale
161+
"App": { // src/App.vue
162+
"title": "Application",
163+
"lang": "Change languages"
164+
},
165+
"components": { // src/components
166+
"Modal": { // src/components/Modal.vue
167+
"ok": "OK",
168+
"cancel": "Cancel"
169+
},
170+
"nest": { // src/components/nest
171+
"RankingTable": { // src/components/nest/RankingTable.vue
172+
"headers": {
173+
"rank": "Rank",
174+
"name": "Name",
175+
"score": "Score"
176+
}
177+
}
178+
}
179+
}
180+
}
181+
}
182+
```
6183

7184
## :white_check_mark: TODO
8185
- [x] API design
@@ -11,6 +188,12 @@ i18n locale messages management tool for vue-i18n
11188
- [x] CLI tool
12189
- [ ] integrate vue-cli-plugin-i18n
13190
- [ ] documentation
191+
- [ ] duplicate locale message keys checking
192+
- [ ] rollup duplicate locale messages
193+
- [ ] delete duplicate locale messages
194+
- [ ] caml/snake case option of locale messages hierarcy name for squeezer
195+
- [ ] sort option for locale messages keys for squeezer
196+
- [ ] locale message yaml outputing
14197

15198
## :copyright: License
16199

0 commit comments

Comments
 (0)