aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils/i18n.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/utils/i18n.js')
-rw-r--r--src/js/utils/i18n.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/js/utils/i18n.js b/src/js/utils/i18n.js
new file mode 100644
index 00000000..758ed695
--- /dev/null
+++ b/src/js/utils/i18n.js
@@ -0,0 +1,47 @@
+// ==========================================================================
+// Plyr internationalization
+// ==========================================================================
+
+import is from './is';
+import { getDeep } from './objects';
+import { replaceAll } from './strings';
+
+// Skip i18n for abbreviations and brand names
+const resources = {
+ pip: 'PIP',
+ airplay: 'AirPlay',
+ html5: 'HTML5',
+ vimeo: 'Vimeo',
+ youtube: 'YouTube',
+};
+
+const i18n = {
+ get(key = '', config = {}) {
+ if (is.empty(key) || is.empty(config)) {
+ return '';
+ }
+
+ let string = getDeep(config.i18n, key);
+
+ if (is.empty(string)) {
+ if (Object.keys(resources).includes(key)) {
+ return resources[key];
+ }
+
+ 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;