From b8f86fe48fca13fa4d4bf1499cf73aa032a9bca7 Mon Sep 17 00:00:00 2001 From: SirStendec Date: Tue, 24 Jul 2018 16:11:02 -0400 Subject: [PATCH] 4.0.0-rc8.6 * Fixed: Update Fine to deal with changes to how the React Root is stored in the DOM. Behind the Scenes * Working on the UI for Translation Editing * Refactor some of the main menu dialog logic into a more generic Dialog class --- package.json | 7 +- src/i18n.js | 69 ++++++- src/main.js | 2 +- .../main_menu/components/main-menu.vue | 2 +- src/modules/main_menu/index.js | 155 ++++----------- .../components/translation-ui.vue | 130 +++++++++++++ src/modules/translation_ui/index.js | 118 +++++++++++ src/modules/translation_ui/nondex.js | 42 ---- src/sites/twitch-clips/index.js | 7 +- src/sites/twitch-twilight/index.js | 23 ++- src/utilities/compat/fine.js | 5 +- src/utilities/dialog.js | 184 ++++++++++++++++++ styles/{main_menu.scss => dialog.scss} | 4 +- styles/main.scss | 2 +- 14 files changed, 570 insertions(+), 180 deletions(-) create mode 100644 src/modules/translation_ui/components/translation-ui.vue create mode 100644 src/modules/translation_ui/index.js delete mode 100644 src/modules/translation_ui/nondex.js create mode 100644 src/utilities/dialog.js rename styles/{main_menu.scss => dialog.scss} (92%) 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 @@