Skip to content

Commit

Permalink
change vue-i18n and core es module for bundler (#247)
Browse files Browse the repository at this point in the history
* change vue-i18n and core es module for bundler

* update e2e

* update warning message
  • Loading branch information
kazupon authored Dec 21, 2020
1 parent 5228b0a commit bcc4423
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 41 deletions.
4 changes: 2 additions & 2 deletions docs/essentials/fallback.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Output:
By default, falling back to `fallbackLocale` generates two console warnings:

```
[vue-i18n] Not found 'hello' key in 'ja' locale messages.
[vue-i18n] Fall back to translate 'hello' key with 'en' locale.
[intlify] Not found 'hello' key in 'ja' locale messages.
[intlify] Fall back to translate 'hello' key with 'en' locale.
```

The first warning message is printed the key, due to given to the translation function `$t` is not in the `ja` locale messages and the second warning message that comes out when you fall back to resolve localized messages from `en` locale messages. These warning messages are output to support debugging using Vue I18n.
Expand Down
4 changes: 2 additions & 2 deletions docs/essentials/local.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ As in the example above, if the component doesn’t have the locale message, it
And also, as explained the [here](fallback#explicit-fallback-with-one-locale), note that, by default, falling back to global scope generates two warnings in the console:

```
[vue-i18n] Not found 'message.greeting' key in 'ja' locale messages.
[vue-i18n] Fall back to translate 'message.greeting' with root locale.
[intlify] Not found 'message.greeting' key in 'ja' locale messages.
[intlify] Fall back to translate 'message.greeting' with root locale.
```

If you want to localize using the component locale, you can do that with `sync: false` and `locale` in the `i18n` component option.
Expand Down
4 changes: 2 additions & 2 deletions e2e/fallback/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line
test('warning', () => {
// missing warning
expect(warnings[0]).toEqual(
`[vue-i18n] Not found 'message.hello' key in 'ja' locale messages.`
`[intlify] Not found 'message.hello' key in 'ja' locale messages.`
)
// fallback warning
expect(warnings[1]).toEqual(
`[vue-i18n] Fall back to translate 'message.hello' key with 'en' locale.`
`[intlify] Fall back to translate 'message.hello' key with 'en' locale.`
)
})

Expand Down
18 changes: 9 additions & 9 deletions e2e/fallback/default-format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line

test('warning', () => {
expect(warnings).toEqual([
`[vue-i18n] Not found 'messages.hello' key in 'ja' locale messages.`,
`[vue-i18n] Fall back to translate 'messages.hello' key with 'en' locale.`,
`[vue-i18n] Not found 'messages.hello' key in 'en' locale messages.`,
`[vue-i18n] Not found 'messages.hello' key in 'ja' locale messages.`,
`[vue-i18n] Fall back to translate 'messages.hello' key with 'en' locale.`,
`[vue-i18n] Not found 'messages.hello' key in 'en' locale messages.`,
`[vue-i18n] Not found 'good morning, {name}!' key in 'ja' locale messages.`,
`[vue-i18n] Fall back to translate 'good morning, {name}!' key with 'en' locale.`,
`[vue-i18n] Not found 'good morning, {name}!' key in 'en' locale messages.`
`[intlify] Not found 'messages.hello' key in 'ja' locale messages.`,
`[intlify] Fall back to translate 'messages.hello' key with 'en' locale.`,
`[intlify] Not found 'messages.hello' key in 'en' locale messages.`,
`[intlify] Not found 'messages.hello' key in 'ja' locale messages.`,
`[intlify] Fall back to translate 'messages.hello' key with 'en' locale.`,
`[intlify] Not found 'messages.hello' key in 'en' locale messages.`,
`[intlify] Not found 'good morning, {name}!' key in 'ja' locale messages.`,
`[intlify] Fall back to translate 'good morning, {name}!' key with 'en' locale.`,
`[intlify] Not found 'good morning, {name}!' key in 'en' locale messages.`
])
})

Expand Down
2 changes: 1 addition & 1 deletion e2e/fallback/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line
test('warning', () => {
// missing warning only
expect(warnings[0]).toEqual(
`[vue-i18n] Not found 'hello, {name}!' key in 'ja' locale messages.`
`[intlify] Not found 'hello, {name}!' key in 'ja' locale messages.`
)
})

Expand Down
2 changes: 1 addition & 1 deletion e2e/fallback/option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line
test('warning', () => {
// missing warning only!
expect(warnings[0]).toEqual(
`[vue-i18n] Not found 'message.hello' key in 'ja' locale messages.`
`[intlify] Not found 'message.hello' key in 'ja' locale messages.`
)
})

Expand Down
2 changes: 1 addition & 1 deletion e2e/fallback/suppress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line
test('warning', () => {
// missing warning only!
expect(warnings[0]).toEqual(
`[vue-i18n] Not found 'message.hello' key in 'ja' locale messages.`
`[intlify] Not found 'message.hello' key in 'ja' locale messages.`
)
})

Expand Down
2 changes: 1 addition & 1 deletion e2e/missing/handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line
expect(warnings[0]).toEqual(`detect 'message.hello' key missing in 'ja'`)
// fallback warning
expect(warnings[1]).toEqual(
`[vue-i18n] Fall back to translate 'message.hello' key with 'en' locale.`
`[intlify] Fall back to translate 'message.hello' key with 'en' locale.`
)
})

Expand Down
2 changes: 1 addition & 1 deletion e2e/missing/option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line
test('warning', () => {
// fallback warning only
expect(warnings[0]).toEqual(
`[vue-i18n] Fall back to translate 'message.hello' key with 'en' locale.`
`[intlify] Fall back to translate 'message.hello' key with 'en' locale.`
)
})

Expand Down
2 changes: 1 addition & 1 deletion e2e/missing/suppress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line
test('warning', () => {
// fallback warning only
expect(warnings[0]).toEqual(
`[vue-i18n] Fall back to translate 'message.hello' key with 'en' locale.`
`[intlify] Fall back to translate 'message.hello' key with 'en' locale.`
)
})

Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ module.exports = {
__BROWSER__: false,
__GLOBAL__: false,
__RUNTIME__: false,
__WARN_LABEL__: `'vue-i18n'`,
__BUNDLE_FILENAME__: 'test.bundle.js',
__ESM_BUNDLER__: true,
__ESM_BROWSER__: false,
Expand Down
12 changes: 10 additions & 2 deletions packages/core-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"bugs": {
"url": "https://github.com/intlify/vue-i18n-next/issues"
},
"files": ["index.js", "dist"],
"files": [
"index.js",
"dist"
],
"main": "index.js",
"module": "dist/core-base.esm-bundler.js",
"unpkg": "dist/core-base.global.js",
Expand All @@ -40,7 +43,12 @@
},
"buildOptions": {
"name": "IntlifyCoreBase",
"formats": ["esm-bundler", "esm-browser", "cjs", "global"]
"formats": [
"esm-bundler",
"esm-browser",
"cjs",
"global"
]
},
"sideEffects": false
}
5 changes: 4 additions & 1 deletion packages/core-base/src/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ export function translate<Messages, Message = string>(

if (__DEV__ && isString(format) && context.messageCompiler == null) {
warn(
`Message format compilation is not supported in this build, because message compiler isn't included, you need to pre-compilation all message format.`
`The message format compilation is not supported in this build. ` +
`Because message compiler isn't included. ` +
`You need to pre-compilation all message format. ` +
`So translate function return '${key}'.`
)
return key as MessageType<Message>
}
Expand Down
7 changes: 5 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
"bugs": {
"url": "https://github.com/intlify/vue-i18n-next/issues"
},
"files": ["index.js", "dist"],
"files": [
"index.js",
"dist"
],
"main": "index.js",
"module": "dist/core.esm-bundler.js",
"module": "dist/core.runtime.esm-bundler.js",
"unpkg": "dist/core.global.js",
"jsdelivr": "dist/core.global.js",
"types": "dist/core.d.ts",
Expand Down
1 change: 0 additions & 1 deletion packages/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ declare let __RUNTIME__: boolean
declare let __ESM_BUNDLER__: boolean
declare let __NODE_JS__: boolean
declare let __VERSION__: string
declare let __WARN_LABEL__: string
declare let __BUNDLE_FILENAME__: string
declare let __COMMIT__: string

Expand Down
12 changes: 10 additions & 2 deletions packages/message-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"bugs": {
"url": "https://github.com/intlify/vue-i18n-next/issues"
},
"files": ["index.js", "dist"],
"files": [
"index.js",
"dist"
],
"main": "index.js",
"module": "dist/message-compiler.esm-bundler.js",
"unpkg": "dist/message-compiler.global.js",
Expand All @@ -39,7 +42,12 @@
},
"buildOptions": {
"name": "IntlifyMessageCompiler",
"formats": ["esm-bundler", "esm-browser", "cjs", "global"]
"formats": [
"esm-bundler",
"esm-browser",
"cjs",
"global"
]
},
"sideEffects": false
}
17 changes: 14 additions & 3 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "@intlify/runtime",
"version": "9.0.0-beta.14",
"description": "@intlify/runtime",
"keywords": ["i18n", "internationalization", "intlify", "runtime"],
"keywords": [
"i18n",
"internationalization",
"intlify",
"runtime"
],
"license": "MIT",
"author": {
"name": "kazuya kawaguchi",
Expand All @@ -17,7 +22,10 @@
"bugs": {
"url": "https://github.com/intlify/vue-i18n-next/issues"
},
"files": ["index.js", "dist"],
"files": [
"index.js",
"dist"
],
"main": "index.js",
"module": "dist/runtime.esm-bundler.js",
"types": "dist/runtime.d.ts",
Expand All @@ -31,7 +39,10 @@
},
"buildOptions": {
"name": "IntlifyRuntime",
"formats": ["esm-bundler", "cjs"]
"formats": [
"esm-bundler",
"cjs"
]
},
"sideEffects": false
}
3 changes: 1 addition & 2 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export const isEmptyObject = (val: unknown): val is boolean =>

export function warn(msg: string, err?: Error): void {
if (typeof console !== 'undefined') {
const label = __WARN_LABEL__ ? __WARN_LABEL__ : 'intlify'
console.warn(`[${label}] ` + msg)
console.warn(`[intlify] ` + msg)
/* istanbul ignore if */
if (err) {
console.warn(err.stack)
Expand Down
7 changes: 5 additions & 2 deletions packages/vue-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
"bugs": {
"url": "https://github.com/intlify/vue-i18n-next/issues"
},
"files": ["index.js", "dist"],
"files": [
"index.js",
"dist"
],
"main": "index.js",
"module": "dist/vue-i18n.esm-bundler.js",
"module": "dist/vue-i18n.runtime.esm-bundler.js",
"unpkg": "dist/vue-i18n.global.js",
"jsdelivr": "dist/vue-i18n.global.js",
"types": "dist/vue-i18n.d.ts",
Expand Down
4 changes: 0 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ function createConfig(format, output, plugins = []) {
isGlobalBuild,
isNodeBuild,
isRuntimeOnlyBuild,
name === 'vue-i18n' ? name : 'intlify',
path.parse(output.file).base || ''
),
...nodePlugins,
Expand All @@ -200,7 +199,6 @@ function createReplacePlugin(
isGlobalBuild,
isNodeBuild,
isRuntimeOnlyBuild,
warnLabel,
bundleFilename
) {
const replacements = {
Expand All @@ -218,8 +216,6 @@ function createReplacePlugin(
__GLOBAL__: isGlobalBuild,
// for runtime only
__RUNTIME__: isRuntimeOnlyBuild,
// warning label
__WARN_LABEL__: `'${warnLabel}'`,
// bundle filename
__BUNDLE_FILENAME__: `'${bundleFilename}'`,
__ESM_BUNDLER__: isBundlerESMBuild,
Expand Down

0 comments on commit bcc4423

Please sign in to comment.