diff options
author | Sam Potts <sam@potts.es> | 2018-08-13 21:39:16 +1000 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2018-08-13 21:39:16 +1000 |
commit | 297f297d181b694446e04f653da694660e9971b4 (patch) | |
tree | 1a3da50b1cb0e48d9ddfcd4bc2f399b084762310 /src/js/utils/i18n.js | |
parent | 059205c378161c59bc7e7ab7798122a0fff0edbb (diff) | |
download | plyr-297f297d181b694446e04f653da694660e9971b4.tar.lz plyr-297f297d181b694446e04f653da694660e9971b4.tar.xz plyr-297f297d181b694446e04f653da694660e9971b4.zip |
Moved i18n to utils
Diffstat (limited to 'src/js/utils/i18n.js')
-rw-r--r-- | src/js/utils/i18n.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/js/utils/i18n.js b/src/js/utils/i18n.js new file mode 100644 index 00000000..f71e1a42 --- /dev/null +++ b/src/js/utils/i18n.js @@ -0,0 +1,34 @@ +// ========================================================================== +// Plyr internationalization +// ========================================================================== + +import is from './is'; +import { getDeep } from './objects'; +import { replaceAll } from './strings'; + +const i18n = { + get(key = '', config = {}) { + if (is.empty(key) || is.empty(config)) { + return ''; + } + + let string = getDeep(config.i18n, key); + + if (is.empty(string)) { + return ''; + } + + const replace = { + '{seektime}': config.seekTime, + '{title}': config.title, + }; + + Object.entries(replace).forEach(([key, value]) => { + string = replaceAll(string, key, value); + }); + + return string; + }, +}; + +export default i18n; |