-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2972 from n8n-io/um/i18n-nds
support i18n in nds
- Loading branch information
Showing
15 changed files
with
264 additions
and
69 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const hasOwnProperty = Object.prototype.hasOwnProperty; | ||
|
||
export function hasOwn(obj, key) { | ||
return hasOwnProperty.call(obj, key); | ||
}; | ||
|
||
|
||
const RE_NARGS = /(%|)\{([0-9a-zA-Z_]+)\}/g; | ||
/** | ||
* String format template | ||
* - Inspired: | ||
* https://github.com/ElemeFE/element/blob/dev/src/locale/format.js | ||
* https://github.com/Matt-Esch/string-template/index.js | ||
*/ | ||
export default function(Vue) { | ||
|
||
/** | ||
* template | ||
* | ||
* @param {String | Function} string | ||
* @param {Array} ...args | ||
* @return {String} | ||
*/ | ||
|
||
function template(value, ...args) { | ||
if (typeof value === 'function') { | ||
return value(args); | ||
} | ||
const string = value; | ||
if (args.length === 1 && typeof args[0] === 'object') { | ||
args = args[0]; | ||
} | ||
|
||
if (!args || !args.hasOwnProperty) { | ||
args = {}; | ||
} | ||
|
||
return string.replace(RE_NARGS, (match, prefix, i, index) => { | ||
let result; | ||
|
||
if (string[index - 1] === '{' && | ||
string[index + match.length] === '}') { | ||
return i; | ||
} else { | ||
result = hasOwn(args, i) ? args[i] : null; | ||
if (result === null || result === undefined) { | ||
return ''; | ||
} | ||
|
||
return result; | ||
} | ||
}); | ||
} | ||
|
||
return template; | ||
} |
Oops, something went wrong.