1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-06 22:30:57 +00:00

The Great Webpack Update.

* Update to version 4 of webpack.
* For that matter, update *every dependency* to the latest available version.
* Remove the babel build target for Edge, as it doesn't seem to be necessary with webpack 4 and tenser.
* Add support for optional chaining and nullish coalescing via Babel transformations.
* Update the clips domain version to work better. Or at all, really.
* Remove unused code from i18n.
* Remove the last `<style>` from vue component files. They don't work that way now anyways.
* Fix a bug in Raven's report handler.
* Fix a bug with the menu button in browsers that don't understand `:scope` within `querySelector()`.
This commit is contained in:
SirStendec 2019-06-19 20:57:14 -04:00
parent 567708b7f1
commit 014eb203c3
31 changed files with 3106 additions and 5715 deletions

View file

@ -12,7 +12,6 @@ import Module from 'utilities/module';
import NewTransCore from 'utilities/translation-core';
const FACES = ['(・`ω´・)', ';;w;;', 'owo', 'ono', 'oAo', 'oxo', 'ovo;', 'UwU', '>w<', '^w^', '> w >', 'v.v'],
transformText = (ast, fn) => {
@ -428,203 +427,12 @@ export class TranslationManager extends Module {
}
// ============================================================================
// TranslationCore
// ============================================================================
const REPLACE = String.prototype.replace; /*,
SPLIT = String.prototype.split;
const DEFAULT_FORMATTERS = {
en_plural: n => n !== 1 ? 's' : '',
number: (n, locale) => n.toLocaleString(locale)
}
export default class TranslationCore {
constructor(options) {
options = options || {};
this.warn = options.warn;
this.phrases = new Map;
this.extend(options.phrases);
this.locale = options.locale || 'en';
this.defaultLocale = options.defaultLocale || this.locale;
this.transformation = null;
const allowMissing = options.allowMissing ? transformPhrase : null;
this.onMissingKey = typeof options.onMissingKey === 'function' ? options.onMissingKey : allowMissing;
this.transformPhrase = typeof options.transformPhrase === 'function' ? options.transformPhrase : transformPhrase;
this.transformList = typeof options.transformList === 'function' ? options.transformList : transformList;
this.delimiter = options.delimiter || /\s*\|\|\|\|\s/;
this.tokenRegex = options.tokenRegex || /%\{(.*?)(?:\|(.*?))?\}/g;
this.formatters = Object.assign({}, DEFAULT_FORMATTERS, options.formatters || {});
}
formatNumber(value) {
return value.toLocaleString(this.locale);
}
extend(phrases, prefix) {
const added = [];
for(const key in phrases)
if ( has(phrases, key) ) {
let phrase = phrases[key];
const pref_key = prefix ? key === '_' ? prefix : `${prefix}.${key}` : key;
if ( typeof phrase === 'object' )
added.push(...this.extend(phrase, pref_key));
else {
if ( typeof phrase === 'string' && phrase.indexOf(this.delimiter) !== -1 )
phrase = SPLIT.call(phrase, this.delimiter);
this.phrases.set(pref_key, phrase);
added.push(pref_key);
}
}
return added;
}
unset(phrases, prefix) {
if ( typeof phrases === 'string' )
phrases = [phrases];
const keys = Array.isArray(phrases) ? phrases : Object.keys(phrases);
for(const key of keys) {
const pref_key = prefix ? `${prefix}.${key}` : key;
const phrase = phrases[key];
if ( typeof phrase === 'object' )
this.unset(phrase, pref_key);
else
this.phrases.delete(pref_key);
}
}
has(key) {
return this.phrases.has(key);
}
set(key, phrase) {
if ( typeof phrase === 'string' && phrase.indexOf(this.delimiter) !== -1 )
phrase = SPLIT.call(phrase, this.delimiter);
this.phrases.set(key, phrase);
}
clear() {
this.phrases.clear();
}
replace(phrases) {
this.clear();
this.extend(phrases);
}
preT(key, phrase, options, use_default) {
const opts = options == null ? {} : options;
let p, locale;
if ( use_default ) {
p = phrase;
locale = this.defaultLocale;
} else if ( key === undefined && phrase ) {
p = phrase;
locale = this.defaultLocale;
if ( this.warn )
this.warn(`Translation key not generated with phrase "${phrase}"`);
} else if ( this.phrases.has(key) ) {
p = this.phrases.get(key);
locale = this.locale;
} else if ( phrase ) {
if ( this.warn && this.locale !== this.defaultLocale )
this.warn(`Missing translation for key "${key}" in locale "${this.locale}"`);
p = phrase;
locale = this.defaultLocale;
} else if ( this.onMissingKey )
return this.onMissingKey(key, opts, this.locale, this.tokenRegex, this.formatters);
else {
if ( this.warn )
this.warn(`Missing translation for key "${key}" in locale "${this.locale}"`);
return key;
}
if ( this.transformation )
p = this.transformation(key, p, opts, locale, this.tokenRegex);
return [p, opts, locale];
}
t(key, phrase, options, use_default) {
const [p, opts, locale] = this.preT(key, phrase, options, use_default);
return this.transformPhrase(p, opts, locale, this.tokenRegex, this.formatters);
}
tList(key, phrase, options, use_default) {
const [p, opts, locale] = this.preT(key, phrase, options, use_default);
return this.transformList(p, opts, locale, this.tokenRegex, this.formatters);
}
}*/
// ============================================================================
// Transformations
// ============================================================================
const DOLLAR_REGEX = /\$/g;
export function transformList(phrase, substitutions, locale, token_regex, formatters) {
const is_array = Array.isArray(phrase);
if ( substitutions == null )
return is_array ? phrase[0] : phrase;
let p = phrase;
const options = typeof substitutions === 'number' ? {count: substitutions} : substitutions;
if ( is_array )
p = p[0];
const result = [];
token_regex.lastIndex = 0;
let idx = 0, match;
while((match = token_regex.exec(p))) {
const nix = match.index,
arg = match[1],
fmt = match[2];
if ( nix !== idx )
result.push(p.slice(idx, nix));
let val = get(arg, options);
if ( val != null ) {
const formatter = formatters[fmt];
if ( typeof formatter === 'function' )
val = formatter(val, locale, options);
else if ( typeof val === 'string' )
val = REPLACE.call(val, DOLLAR_REGEX, '$$');
result.push(val);
}
idx = nix + match[0].length;
}
if ( idx < p.length )
result.push(p.slice(idx));
return result;
}
const REPLACE = String.prototype.replace;
export function transformPhrase(phrase, substitutions, locale, token_regex, formatters) {
const is_array = Array.isArray(phrase);