diff --git a/.gitignore b/.gitignore index 2284c8f17..1fc25c39f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ test/e2e/report test/e2e/screenshots node_modules .DS_Store +.idea .vscode *.log *.swp diff --git a/src/index.js b/src/index.js index 1e2d18c81..95c77fac7 100644 --- a/src/index.js +++ b/src/index.js @@ -39,6 +39,13 @@ export default class VueI18n { _dataListeners: Array constructor (options: I18nOptions = {}) { + // Auto install if it is not done yet and `window` has `Vue`. + // To allow users to avoid auto-installation in some cases, + // this code should be placed here. See #290 + if (!Vue && typeof window !== 'undefined' && window.Vue) { + install(window.Vue) + } + const locale: Locale = options.locale || 'en-US' const fallbackLocale: Locale = options.fallbackLocale || 'en-US' const messages: LocaleMessages = options.messages || {} @@ -585,8 +592,3 @@ VueI18n.availabilities = { } VueI18n.install = install VueI18n.version = '__VERSION__' - -/* istanbul ignore if */ -if (typeof window !== 'undefined' && window.Vue) { - window.Vue.use(VueI18n) -}