diff --git a/package.json b/package.json index 64616f93..e60b0bd0 100755 --- a/package.json +++ b/package.json @@ -10,9 +10,10 @@ "dev": "webpack-dev-server --config webpack.web.dev.js", "dev:clips": "webpack-dev-server --config webpack.clips.dev.js", "dev:babel": "webpack-dev-server --config webpack.web.dev.babel.js", - "build:all": "npm run build && npm run build:babel && npm run build:clips && npm run build:clips:babel", - "build": "webpack --config webpack.web.prod.js --define process.env.NODE_ENV='production'", - "build:clips": "webpack --config webpack.clips.prod.js --define process.env.NODE_ENV='production'", + "build:all": "npm run build && npm run build:clips", + "build": "npm run build:prod && npm run build:babel", + "build:clips": "npm run build:clips:prod && npm run build:clips:babel", + "build:clips:prod": "webpack --config webpack.clips.prod.js --define process.env.NODE_ENV='production'", "build:clips:babel": "webpack --config webpack.clips.babel.js --define process.env.NODE_ENV='production'", "build:stats": "webpack --config webpack.web.prod.js --define process.env.NODE_ENV='production' --json > stats.json", "build:babel": "webpack --config webpack.web.babel.js --define process.env.NODE_ENV='production'", diff --git a/src/i18n.js b/src/i18n.js index e96563a2..80eda296 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -7,7 +7,7 @@ // ============================================================================ import {SERVER} from 'utilities/constants'; -import {get, pick_random, has} from 'utilities/object'; +import {get, pick_random, has, timeout} from 'utilities/object'; import Module from 'utilities/module'; @@ -69,6 +69,8 @@ export class TranslationManager extends Module { super(...args); this.inject('settings'); + this._seen = new Set; + this.availableLocales = ['en']; //, 'de', 'ja']; this.localeData = { @@ -141,6 +143,12 @@ export class TranslationManager extends Module { } }); + if ( window.BroadcastChannel ) { + const bc = this._broadcaster = new BroadcastChannel('ffz-i18n'); + bc.addEventListener('message', + this._boundHandleMessage = this.handleMessage.bind(this)); + } + this._.transformation = TRANSFORMATIONS[this.settings.get('i18n.debug.transform')]; this.locale = this.settings.get('i18n.locale'); } @@ -154,6 +162,55 @@ export class TranslationManager extends Module { } + handleMessage(event) { + const msg = event.data; + if ( msg.type === 'seen' ) + this.see(msg.key, true); + + else if ( msg.type === 'request-keys' ) { + this.broadcast({type: 'keys', keys: Array.from(this._seen)}) + } + + else if ( msg.type === 'keys' ) + this.emit(':receive-keys', msg.keys); + } + + + async getKeys() { + this.broadcast({type: 'request-keys'}); + + let data; + + try { + data = await timeout(this.waitFor(':receive-keys'), 100); + } catch(err) { /* no-op */ } + + if ( data ) + for(const val of data) + this._seen.add(val); + + return this._seen; + } + + + broadcast(msg) { + if ( this._broadcaster ) + this._broadcaster.postMessage(msg) + } + + + see(key, from_broadcast = false) { + if ( this._seen.has(key) ) + return; + + this._seen.add(key); + this.emit(':seen', key); + + if ( ! from_broadcast ) + this.broadcast({type: 'seen', key}); + } + + toLocaleString(thing) { if ( thing && thing.toLocaleString ) return thing.toLocaleString(this._.locale); @@ -363,12 +420,14 @@ export class TranslationManager extends Module { return this._.formatNumber(...args); } - t(...args) { - return this._.t(...args); + t(key, ...args) { + this.see(key); + return this._.t(key, ...args); } - tList(...args) { - return this._.tList(...args); + tList(key, ...args) { + this.see(key); + return this._.tList(key, ...args); } } diff --git a/src/main.js b/src/main.js index c774cd5a..dafa1f13 100644 --- a/src/main.js +++ b/src/main.js @@ -100,7 +100,7 @@ class FrankerFaceZ extends Module { FrankerFaceZ.Logger = Logger; const VER = FrankerFaceZ.version_info = { - major: 4, minor: 0, revision: 0, extra: '-rc8.5', + major: 4, minor: 0, revision: 0, extra: '-rc8.6', commit: __git_commit__, build: __webpack_hash__, toString: () => diff --git a/src/modules/main_menu/components/main-menu.vue b/src/modules/main_menu/components/main-menu.vue index bec9bac4..ba5b9ecb 100644 --- a/src/modules/main_menu/components/main-menu.vue +++ b/src/modules/main_menu/components/main-menu.vue @@ -1,7 +1,7 @@