From 2f016ff22fe3a1742fa830e7c5f2f69e499a27d0 Mon Sep 17 00:00:00 2001 From: Emile Bergeron Date: Wed, 31 Jan 2018 22:50:36 -0500 Subject: [PATCH] :zap: improvement(index): Fixes global auto installation (#291) by @emileber --- .gitignore | 1 + src/index.js | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) 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) -}