-
-
Notifications
You must be signed in to change notification settings - Fork 860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
silence fallback warnings #510
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e92b51d
:zap: improvement(option): silentFallbackWarn (#139)
db26d27
adding typescript property declaration
2dbd95f
:pencil: docs(options): document silentFallbackWarn
8764925
Update vuepress/api/README.md
kazupon 9a9da76
:zap: improvement(option): silentFallbackWarn
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,168 @@ | ||
describe('silent', () => { | ||
it('should be suppressed translate warnings', () => { | ||
const vm = new Vue({ | ||
i18n: new VueI18n({ | ||
locale: 'en', | ||
silentTranslationWarn: true, | ||
let spy | ||
beforeEach(() => { | ||
spy = sinon.spy(console, 'warn') | ||
}) | ||
afterEach(() => { | ||
spy.restore() | ||
}) | ||
|
||
describe('silentTranslationWarn', () => { | ||
it('should be suppressed translate warnings', () => { | ||
const vm = new Vue({ | ||
i18n: new VueI18n({ | ||
locale: 'en', | ||
silentTranslationWarn: true, | ||
messages: { | ||
en: { who: 'root' }, | ||
ja: { who: 'ルート' } | ||
} | ||
}) | ||
}) | ||
|
||
vm.$t('foo.bar.buz') | ||
assert(spy.notCalled === true) | ||
|
||
// change | ||
vm.$i18n.silentTranslationWarn = false | ||
vm.$t('foo.bar.buz') | ||
assert(spy.callCount === 2) | ||
}) | ||
}) | ||
|
||
describe('silentFallbackWarn', () => { | ||
let i18n | ||
beforeEach(() => { | ||
i18n = new VueI18n({ | ||
locale: 'hu', | ||
fallbackLocale: 'en', | ||
silentFallbackWarn: true, | ||
messages: { | ||
en: { who: 'root' }, | ||
ja: { who: 'ルート' } | ||
en: { winner: 'winner' }, | ||
hu: { chickenDinner: 'csirkevacsora' } | ||
} | ||
}) | ||
}) | ||
|
||
const spy = sinon.spy(console, 'warn') | ||
vm.$t('foo.bar.buz') | ||
assert(spy.notCalled === true) | ||
it('should suppress `Fall back to ${fallback} locale` warnings', () => { | ||
const vm = new Vue({ i18n }) | ||
const warningRegex = /Fall back to .* 'en' locale./ | ||
vm.$t('winner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === false) | ||
|
||
// change | ||
vm.$i18n.silentTranslationWarn = false | ||
vm.$t('foo.bar.buz') | ||
assert(spy.callCount === 2) | ||
vm.$i18n.silentFallbackWarn = false | ||
vm.$t('winner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === true) | ||
}) | ||
|
||
spy.restore() | ||
it('should suppress `Fall back to root locale` warnings.', () => { | ||
const el = document.createElement('div') | ||
const root = new Vue({ | ||
i18n, | ||
components: { | ||
subComponent: { | ||
i18n: { messages: { hu: { name: 'Név' } } }, | ||
render (h) { return h('p') } | ||
} | ||
}, | ||
render (h) { return h('sub-component') } | ||
}).$mount(el) | ||
const vm = root.$children[0] | ||
const warningRegex = /Fall back to .* root locale./ | ||
|
||
vm.$t('chickenDinner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === false) | ||
|
||
vm.$i18n.silentFallbackWarn = false | ||
vm.$t('chickenDinner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === true) | ||
}) | ||
|
||
describe('if first try is null or undefined,', () => { | ||
it('should suppress `not a string` warnings for fallback to fallbackLocale.', () => { | ||
const vm = new Vue({ i18n }) | ||
const warningRegex = /Value of .* is not a string./ | ||
vm.$t('winner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === false) | ||
|
||
vm.$i18n.silentFallbackWarn = false | ||
vm.$t('winner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === true) | ||
}) | ||
|
||
it('should supress `not a string` warnings for fallback to root.', () => { | ||
const el = document.createElement('div') | ||
const root = new Vue({ | ||
i18n, | ||
components: { | ||
subComponent: { | ||
i18n: { messages: { hu: { name: 'Név' } } }, | ||
render (h) { return h('p') } | ||
} | ||
}, | ||
render (h) { return h('sub-component') } | ||
}).$mount(el) | ||
const vm = root.$children[0] | ||
const warningRegex = /Value of .* is not a string./ | ||
vm.$t('chickenDinner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === false) | ||
|
||
vm.$i18n.silentFallbackWarn = false | ||
vm.$t('chickenDinner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === true) | ||
}) | ||
}) | ||
|
||
describe('if first try is not null, undefined, array, plain object or string,', () => { | ||
it('should suppress `not a string` warnings for fallback to fallbackLocale.', () => { | ||
const vm = new Vue({ | ||
i18n: new VueI18n({ | ||
locale: 'hu', | ||
fallbackLocale: 'en', | ||
silentFallbackWarn: true, | ||
messages: { | ||
en: { winner: 'winner' }, | ||
hu: { winner: true } // translation value is boolean | ||
} | ||
}) | ||
}) | ||
const warningRegex = /Value of .* is not a string./ | ||
vm.$t('winner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === false) | ||
|
||
vm.$i18n.silentFallbackWarn = false | ||
vm.$t('winner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === true) | ||
}) | ||
|
||
it('should supress `not a string` warnings for fallback to root.', () => { | ||
const el = document.createElement('div') | ||
const root = new Vue({ | ||
i18n, | ||
components: { | ||
subComponent: { | ||
i18n: { messages: { hu: { chickenDinner: 11 } } }, // translation value is number | ||
render (h) { return h('p') } | ||
} | ||
}, | ||
render (h) { return h('sub-component') } | ||
}).$mount(el) | ||
const vm = root.$children[0] | ||
const warningRegex = /Value of .* is not a string./ | ||
vm.$t('chickenDinner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === false) | ||
|
||
vm.$i18n.silentFallbackWarn = false | ||
vm.$t('chickenDinner') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === true) | ||
}) | ||
}) | ||
|
||
it('should not suppress `not a string` warnings when no further fallback is possible.', () => { | ||
const vm = new Vue({ i18n }) | ||
const warningRegex = /Value of .* is not a string./ | ||
vm.$t('loser') | ||
assert(spy.getCalls().some(call => call.args[0].match(warningRegex)) === true) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kazupon is it the right use case?
boolean
,number
etc?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.