File tree Expand file tree Collapse file tree 1 file changed +31
-7
lines changed Expand file tree Collapse file tree 1 file changed +31
-7
lines changed Original file line number Diff line number Diff line change 1- const path = require ( 'path' )
2-
31import Vue from 'vue'
42import VueI18n from 'vue-i18n'
3+ import axios from 'axios'
54
65Vue . use ( VueI18n )
76
8- export default ( { app, store } ) => {
7+ function generateUrl ( language ) {
8+ const path = '/i18n/<%= options.outputFilePrefix %>' + '-' + language + '.json'
9+
10+ let url = path
11+ const host = process . env . HOST || process . env . npm_package_config_nuxt_host || 'localhost'
12+ const port = process . env . PORT || process . env . npm_package_config_nuxt_port || 3000
13+
14+ return 'http://' + host + ':' + port + url
15+ }
16+
17+ export default async ( { app, store, beforeNuxtRender } ) => {
918 const languages = '<%= options.languages %>' . split ( ',' )
10- const languagesSrc = { }
19+ let languagesSrc = { }
20+
21+ // On server side
22+ if ( process . server ) {
23+ for ( const language of languages ) {
24+ const { data } = await axios ( generateUrl ( language ) )
25+
26+ languagesSrc [ language ] = data
27+ }
28+
29+ beforeNuxtRender ( ( { nuxtState } ) => {
30+ nuxtState . i18n = languagesSrc
31+ } )
32+ }
33+
34+ // On client side
35+ if ( process . client ) {
36+ languagesSrc = window . __NUXT__ . i18n
37+ }
1138
12- languages . forEach ( ( language ) => {
13- languagesSrc [ language ] = require ( '<%= options.path %>' + '/' + '<%= options.outputFilePrefix %>' + '-' + language + '.json' )
14- } )
1539 // Set i18n instance on app
1640 app . i18n = new VueI18n ( {
1741 locale : store . state [ '<%= options.localeNamespaceStore %>' ] . locale ,
You can’t perform that action at this time.
0 commit comments