mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-03 16:38:31 +00:00
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
This commit is contained in:
parent
154a587c87
commit
b8f86fe48f
14 changed files with 570 additions and 180 deletions
69
src/i18n.js
69
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue