├── babel.config.js
├── public
├── favicon.ico
└── index.html
├── screenshots
└── vue.gif
├── src
├── assets
│ └── logo.png
├── main.js
├── plugins
│ └── i18n.js
├── App.vue
└── components
│ └── HelloWorld.vue
├── .gitignore
├── README.md
└── package.json
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | '@vue/app'
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ratracegrad/vue-internationalization/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/screenshots/vue.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ratracegrad/vue-internationalization/HEAD/screenshots/vue.gif
--------------------------------------------------------------------------------
/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ratracegrad/vue-internationalization/HEAD/src/assets/logo.png
--------------------------------------------------------------------------------
/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import App from './App.vue';
3 | import i18n from '@/plugins/i18n';
4 | import FlagIcon from 'vue-flag-icon';
5 |
6 | Vue.use(FlagIcon);
7 | Vue.config.productionTip = false;
8 |
9 | new Vue({
10 | i18n,
11 | render: h => h(App),
12 | }).$mount('#app');
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist
4 |
5 | # local env files
6 | .env.local
7 | .env.*.local
8 |
9 | # Log files
10 | npm-debug.log*
11 | yarn-debug.log*
12 | yarn-error.log*
13 |
14 | # Editor directories and files
15 | .idea
16 | .vscode
17 | *.suo
18 | *.ntvs*
19 | *.njsproj
20 | *.sln
21 | *.sw*
22 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | vue-internationalization
9 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vue-internationalization
2 |
3 | This is the source code for an article I wrote about adding internationalization to a Vue application. You can [read the article here](https://medium.com/p/d9cfdcabb03b/).
4 |
5 | In the article I show how to take the default app created from the @vue/cli and add internationalization to it.
6 | Here is what it looks like:
7 |
8 | 
9 |
10 | ## Project setup
11 | ```
12 | npm install
13 | ```
14 |
15 | ### Compiles and hot-reloads for development
16 | ```
17 | npm run serve
18 | ```
19 |
20 | ### Compiles and minifies for production
21 | ```
22 | npm run build
23 | ```
24 |
25 | ### Run your tests
26 | ```
27 | npm run test
28 | ```
29 |
30 | ### Lints and fixes files
31 | ```
32 | npm run lint
33 | ```
34 |
--------------------------------------------------------------------------------
/src/plugins/i18n.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import VueI18n from 'vue-i18n';
3 |
4 | Vue.use(VueI18n);
5 |
6 | const messages = {
7 | 'en': {
8 | welcomeMsg: 'Welcome to Your Vue.js App',
9 | guide: 'For a guide and recipes on how to configure / customize this project,',
10 | checkout: 'check out the',
11 | plugins: 'Installed CLI Plugins',
12 | links: 'Essential Links',
13 | ecosystem: 'Ecosystem'
14 | },
15 | 'es': {
16 | welcomeMsg: 'Bienvenido a tu aplicación Vue.js',
17 | guide: 'Para una guía y recetas sobre cómo configurar / personalizar este proyecto,',
18 | checkout: 'revisar la',
19 | plugins: 'Plugins de CLI instalados',
20 | links: 'Enlaces esenciales',
21 | ecosystem: 'Ecosistema'
22 | }
23 | };
24 |
25 | const i18n = new VueI18n({
26 | locale: 'en', // set locale
27 | fallbackLocale: 'es', // set fallback locale
28 | messages, // set locale messages
29 | });
30 |
31 | export default i18n;
32 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-internationalization",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "serve": "vue-cli-service serve",
7 | "build": "vue-cli-service build",
8 | "lint": "vue-cli-service lint"
9 | },
10 | "dependencies": {
11 | "vue": "^2.5.17",
12 | "vue-flag-icon": "^1.0.6",
13 | "vue-i18n": "^8.3.1"
14 | },
15 | "devDependencies": {
16 | "@vue/cli-plugin-babel": "^3.0.5",
17 | "@vue/cli-plugin-eslint": "^3.0.5",
18 | "@vue/cli-service": "^3.0.5",
19 | "babel-eslint": "^10.0.1",
20 | "eslint": "^5.8.0",
21 | "eslint-plugin-vue": "^5.0.0-0",
22 | "vue-template-compiler": "^2.5.17"
23 | },
24 | "eslintConfig": {
25 | "root": true,
26 | "env": {
27 | "node": true
28 | },
29 | "extends": [
30 | "plugin:vue/essential",
31 | "eslint:recommended"
32 | ],
33 | "rules": {},
34 | "parserOptions": {
35 | "parser": "babel-eslint"
36 | }
37 | },
38 | "postcss": {
39 | "plugins": {
40 | "autoprefixer": {}
41 | }
42 | },
43 | "browserslist": [
44 | "> 1%",
45 | "last 2 versions",
46 | "not ie <= 8"
47 | ]
48 | }
49 |
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |

10 |
11 |
12 |
13 |
14 |
38 |
39 |
55 |
--------------------------------------------------------------------------------
/src/components/HelloWorld.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{{ $t('welcomeMsg') }}
4 |
5 | {{ $t('guide') }}
6 | {{ $t('checkout') }}
7 | vue-cli documentation.
8 |
9 |
{{ $t('plugins') }}
10 |
16 |
{{ $t('links') }}
17 |
24 |
{{ $t('ecosystem') }}
25 |
33 |
34 |
35 |
36 |
44 |
45 |
46 |
65 |
--------------------------------------------------------------------------------