11import warn from './warn'
22import Format from './format'
33import Path from './path'
4-
4+ import { isNil } from './util'
55
66/**
77 * extend
@@ -40,8 +40,9 @@ export default function (Vue) {
4040 function interpolate ( locale , key , args ) {
4141 if ( ! locale ) { return null }
4242
43- let val = getValue ( locale , key ) || locale [ key ]
44- if ( ! val ) { return null }
43+ let val = getValue ( locale , key )
44+ if ( isNil ( val ) ) val = locale [ key ]
45+ if ( isNil ( val ) ) { return null }
4546
4647 // Check for the existance of links within the translated string
4748 if ( val . indexOf ( '@:' ) >= 0 ) {
@@ -70,10 +71,10 @@ export default function (Vue) {
7071 function translate ( getter , lang , fallback , key , params ) {
7172 let res = null
7273 res = interpolate ( getter ( lang ) , key , params )
73- if ( res ) { return res }
74+ if ( ! isNil ( res ) ) { return res }
7475
7576 res = interpolate ( getter ( fallback ) , key , params )
76- if ( res ) {
77+ if ( ! isNil ( res ) ) {
7778 if ( process . env . NODE_ENV !== 'production' ) {
7879 warn ( 'Fall back to translate the keypath "' + key + '" with "'
7980 + fallback + '" language.' )
@@ -85,7 +86,8 @@ export default function (Vue) {
8586 }
8687
8788
88- function warnDefault ( lang , key , vm ) {
89+ function warnDefault ( lang , key , vm , result ) {
90+ if ( ! isNil ( result ) ) { return result }
8991 if ( process . env . NODE_ENV !== 'production' ) {
9092 warn ( 'Cannot translate the value of keypath "' + key + '". '
9193 + 'Use the value of keypath as default' )
@@ -134,8 +136,7 @@ export default function (Vue) {
134136 Vue . t = ( key , ...args ) => {
135137 if ( ! key ) { return '' }
136138 const { lang, fallback, params } = parseArgs ( ...args )
137- return translate ( getAssetLocale , lang , fallback , key , params )
138- || warnDefault ( lang , key , null )
139+ return warnDefault ( lang , key , null , translate ( getAssetLocale , lang , fallback , key , params ) )
139140 }
140141
141142 /**
@@ -169,8 +170,7 @@ export default function (Vue) {
169170 )
170171 if ( res ) { return res }
171172 }
172- return translate ( getAssetLocale , lang , fallback , key , params )
173- || warnDefault ( lang , key , this )
173+ return warnDefault ( lang , key , this , translate ( getAssetLocale , lang , fallback , key , params ) )
174174 }
175175
176176 /**
0 commit comments