mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-09-15 17:46:55 +00:00
4.33.0
* Added: Formatters for chat action variables. (Closes #1199) * Changed: By default, open the user card to a badge when clicking a badge in chat. (Closes #1195) * Fixed: The settings bridge functioning incorrectly for users without a set storage provider, causing pages that rely on the settings bridge including the Stream Dashboard to never correctly load FFZ.
This commit is contained in:
parent
084a3ee5e0
commit
2af7d5618b
8 changed files with 186 additions and 21 deletions
43
src/i18n.js
43
src/i18n.js
|
@ -191,7 +191,7 @@ export class TranslationManager extends Module {
|
|||
},
|
||||
data: () => {
|
||||
const out = [], now = new Date;
|
||||
for (const [key,fmt] of Object.entries(this._.formats.date)) {
|
||||
for (const [key, fmt] of Object.entries(this._.formats.date)) {
|
||||
out.push({
|
||||
value: key, title: `${this.formatDate(now, key)} (${key})`
|
||||
})
|
||||
|
@ -815,6 +815,28 @@ export class TranslationManager extends Module {
|
|||
const DOLLAR_REGEX = /\$/g;
|
||||
const REPLACE = String.prototype.replace;
|
||||
|
||||
const FORMAT_REGEX = /^\s*([^(]+?)\s*(?:\(\s*([^)]+?)\s*\))?\s*$/;
|
||||
|
||||
export function parseFormatters(fmt) {
|
||||
if (!fmt || ! fmt.length)
|
||||
return;
|
||||
|
||||
const result = [];
|
||||
|
||||
for(const token of fmt.split(/\|/g)) {
|
||||
const match = FORMAT_REGEX.exec(token);
|
||||
if (!match)
|
||||
continue;
|
||||
|
||||
result.push({
|
||||
fmt: match[1],
|
||||
extra: match[2]
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function transformPhrase(phrase, substitutions, locale, token_regex, formatters) {
|
||||
const is_array = Array.isArray(phrase);
|
||||
if ( substitutions == null )
|
||||
|
@ -828,14 +850,23 @@ export function transformPhrase(phrase, substitutions, locale, token_regex, form
|
|||
|
||||
if ( typeof result === 'string' )
|
||||
result = REPLACE.call(result, token_regex, (expr, arg, fmt) => {
|
||||
let val = get(arg, options);
|
||||
let val = get(arg.trim(), options);
|
||||
if ( val == null )
|
||||
return '';
|
||||
|
||||
const formatter = formatters[fmt];
|
||||
if ( typeof formatter === 'function' )
|
||||
val = formatter(val, locale, options);
|
||||
else if ( typeof val === 'string' )
|
||||
const fmts = parseFormatters(fmt);
|
||||
let formatted = false;
|
||||
if (fmts) {
|
||||
for(const format of fmts) {
|
||||
const formatter = formatters[format.fmt];
|
||||
if (typeof formatter === 'function') {
|
||||
val = formatter(val, locale, options, format.extra);
|
||||
formatted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! formatted && typeof val === 'string' )
|
||||
val = REPLACE.call(val, DOLLAR_REGEX, '$$');
|
||||
|
||||
return val;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue