Skip to content

Commit f5a67a9

Browse files
author
wangsw
committed
init 1.0.0
0 parents  commit f5a67a9

26 files changed

+4323
-0
lines changed

.eslintrc.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"standard"
8+
],
9+
"parser": "@typescript-eslint/parser",
10+
"parserOptions": {
11+
"ecmaVersion": 12,
12+
"sourceType": "module"
13+
},
14+
"plugins": [
15+
"@typescript-eslint"
16+
],
17+
"rules": {
18+
}
19+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.vscode

LICENSE

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
The MIT License
3+
4+
Copyright webkong
5+
6+
This software consists of voluntary contributions made by many
7+
individuals. For exact contribution history, see the revision history
8+
available at https://github.com/webkong/vue3-i18n
9+
10+
The following license applies to all parts of this software except as
11+
documented below:
12+
13+
====
14+
15+
Permission is hereby granted, free of charge, to any person obtaining
16+
a copy of this software and associated documentation files (the
17+
"Software"), to deal in the Software without restriction, including
18+
without limitation the rights to use, copy, modify, merge, publish,
19+
distribute, sublicense, and/or sell copies of the Software, and to
20+
permit persons to whom the Software is furnished to do so, subject to
21+
the following conditions:
22+
23+
The above copyright notice and this permission notice shall be
24+
included in all copies or substantial portions of the Software.
25+
26+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33+
34+
====
35+
36+
Copyright and related rights for sample code are waived via CC0. Sample
37+
code is defined as all source code displayed within the prose of the
38+
documentation.
39+
40+
CC0: http://creativecommons.org/publicdomain/zero/1.0/
41+
42+
====
43+
44+
Files located in the node_modules and vendor directories are externally
45+
maintained libraries used by this software which have their own
46+
licenses; we recommend you read them, as their terms may differ from the
47+
terms above.

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# vue3-i18n
2+
3+
![Vue 3.x](https://img.shields.io/badge/vue-3.x-green.svg "Vue 3 Compatible")
4+
5+
I18n for vue3.
6+
7+
**Note:**
8+
9+
Issue/PR is welcomed, I'll response as soon as possible.
10+
11+
If you like this pack, can give a star.
12+
13+
## Usage
14+
15+
### install
16+
`npm install vue3-i18n --save`
17+
18+
### Quickstart
19+
```javascript
20+
// i18n.js
21+
import { createI18n } from "vue3-i18n";
22+
23+
const messages = {
24+
en: {
25+
menu: ["Home"],
26+
test: "test",
27+
},
28+
zh: {
29+
menu: ["首页"],
30+
test: "测试",
31+
},
32+
};
33+
34+
const i18n = createI18n({
35+
locale: "en",
36+
messages: messages,
37+
});
38+
39+
export default i18n;
40+
```
41+
```javascript
42+
43+
// main.js
44+
import { createApp } from "vue";
45+
import i18n from "./i18n";
46+
47+
const app = createApp(App);
48+
49+
app
50+
.use(i18n)
51+
.mount("#app");
52+
```
53+
54+
### Usage
55+
56+
```html
57+
<p>{{ $t("test") }}</p>
58+
<!-- array -->
59+
<p>{{ $t("test[1]") }}</p>
60+
<!-- object -->
61+
<p>{{ $t("test.a") }}</p>
62+
```
63+
64+
```javascript
65+
<script>
66+
import { useI18n } from "vue3-i18n";
67+
export default {
68+
setup() {
69+
const i18n = useI18n();
70+
const setLocale = (lang) => {
71+
i18n.setLocale(lang);
72+
};
73+
74+
return {
75+
setLocale,
76+
};
77+
},
78+
};
79+
</script>
80+
```
81+
82+
#### TODO
83+
- [ ] directive
84+
- [ ] Named formatting
85+
86+
## License
87+
MIT

dist/i18n.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { I18nInstance, I18nConfig } from "./types";
2+
export declare const i18nSymbol: unique symbol;
3+
export declare const createI18n: (config: I18nConfig) => I18nInstance;

dist/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { Messages, I18nConfig, I18nInstance } from "./types";
2+
export { createI18n, i18nSymbol } from "./i18n";
3+
export { useI18n } from "./useApi";

dist/index.esm.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.umd.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { App } from "vue";
2+
export interface Messages {
3+
[key: string]: any;
4+
}
5+
export interface I18nConfig {
6+
locale?: string;
7+
messages: Messages;
8+
}
9+
export interface I18nInstance {
10+
messages: Messages;
11+
t: (key: string) => string;
12+
setLocale: (locale: string) => void;
13+
getLocale: () => string;
14+
install(app: App): void;
15+
}

dist/useApi.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { I18nInstance } from "./types";
2+
export declare function useI18n(): I18nInstance;

0 commit comments

Comments
 (0)