Skip to content

Commit

Permalink
raidboss: improve translation of timeline netregex (#5962)
Browse files Browse the repository at this point in the history
Follow-up to #5939.

This translates each parameter (only if needed) rather than the entire
sync. It also prints out only the untranslated parameters in the find
missing translations script / coverage report. This also improves the
output of the translated timeline utility to use translated parameters
and fixes a bug where it wouldn't have output any translated sync lines
at all for netregex lines.
  • Loading branch information
quisquous authored Nov 30, 2023
1 parent b58db1b commit 86f5ae1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 20 deletions.
39 changes: 29 additions & 10 deletions ui/raidboss/timeline_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import logDefinitions, { LogDefinitionTypes } from '../../resources/netlog_defs'
import { buildNetRegexForTrigger } from '../../resources/netregexes';
import { UnreachableCode } from '../../resources/not_reached';
import Regexes from '../../resources/regexes';
import { translateRegex, translateText } from '../../resources/translations';
import {
AnonNetRegexParams,
translateRegex,
translateRegexBuildParamAnon,
translateText,
} from '../../resources/translations';
import { NetParams } from '../../types/net_props';
import { LooseTimelineTrigger, TriggerAutoConfig } from '../../types/trigger';

Expand Down Expand Up @@ -80,7 +85,7 @@ export type Error = {

export type Sync = {
id: number;
origRegexStr: string;
origInput: string | AnonNetRegexParams;
regexType: 'parsed' | 'net';
regex: RegExp;
start: number;
Expand Down Expand Up @@ -500,13 +505,17 @@ export class TimelineParser {
});
return line;
}

const translatedParams = translateRegexBuildParamAnon(
params,
this.options.ParserLanguage,
this.replacements,
).params;
return this.buildRegexSync(
uniqueid,
'net',
`${netRegexType} ${syncCommand.netRegex}`,
// TODO: Use `translateRegexBuildParam` instead, store off params for use elsewhere.
// See https://github.com/quisquous/cactbot/pull/5939#discussion_r1399453530
Regexes.parse(this.GetReplacedSync(buildNetRegexForTrigger(netRegexType, params))),
params,
Regexes.parse(buildNetRegexForTrigger(netRegexType, translatedParams)),
syncCommand.args,
seconds,
lineNumber,
Expand Down Expand Up @@ -545,7 +554,7 @@ export class TimelineParser {
private buildRegexSync(
uniqueid: number,
regexType: 'parsed' | 'net',
regex: string,
origInput: string | AnonNetRegexParams,
parsedRegex: RegExp,
args: string | undefined,
seconds: number,
Expand All @@ -555,7 +564,7 @@ export class TimelineParser {
) {
const sync: Sync = {
id: uniqueid,
origRegexStr: regex,
origInput: origInput,
regexType: regexType,
regex: parsedRegex,
start: seconds - 2.5,
Expand Down Expand Up @@ -680,8 +689,18 @@ export class TimelineParser {
if (lineText)
line = line.replace(` "${lineText.name}"`, ` "${lineText.text}"`);
const lineSync = lineToSync[lineNumber];
if (lineSync)
line = line.replace(`sync /${lineSync.origRegexStr}/`, `sync /${lineSync.regex.source}/`);
if (lineSync) {
if (typeof lineSync.origInput === 'string') {
line = line.replace(`sync /${lineSync.origInput}/`, `sync /${lineSync.regex.source}/`);
} else {
const translatedParams = translateRegexBuildParamAnon(
lineSync.origInput,
timeline.options.ParserLanguage,
timeline.replacements,
).params;
line = line.replace(/{[^}]*}/, `{ ${JSON.stringify(translatedParams)} }`);
}
}

if (syncErrors?.[lineNumber])
line += ' #MISSINGSYNC';
Expand Down
36 changes: 26 additions & 10 deletions util/find_missing_timeline_translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const findMissingTimeline = (
{
type: 'replaceSync',
items: new Set(
timeline.syncStarts.map((x) => ({ text: x.regex.source, line: x.lineNumber })),
timeline.syncStarts.map((x) => ({ text: x.origInput, line: x.lineNumber })),
),
replace: trans.replaceSync || {},
label: 'sync',
Expand Down Expand Up @@ -185,16 +185,32 @@ const findMissingTimeline = (

for (const testCase of testCases) {
for (const item of testCase.items) {
if (isIgnored(item.text))
continue;
let matched = false;
for (const regex in testCase.replace) {
if (item.text.match(Regexes.parse(regex))) {
matched = true;
break;
const origInput = item.text;
let errorStr: string | undefined;
if (typeof origInput === 'string') {
let matched = false;
if (isIgnored(origInput))
continue;
for (const regex in testCase.replace) {
if (!origInput.match(Regexes.parse(regex))) {
matched = true;
break;
}
}
if (!matched)
errorStr = `"${origInput}"`;
} else {
const result = translateRegexBuildParamAnon(origInput, locale, [trans]);
const missingFields = result.missingFields;
if (!result.wasTranslated && missingFields !== undefined) {
const outputObj: { [key: string]: AnonNetRegexParams['string'] } = {};
for (const field of missingFields)
outputObj[field] = origInput[field];
errorStr = JSON.stringify(outputObj);
}
}
if (!matched) {

if (errorStr !== undefined) {
// Because we handle syncs separately from texts, in order to
// sort them all properly together, create a key to be used with sort().
const sortKey = String(item.line).padStart(8, '0') + testCase.label;
Expand All @@ -203,7 +219,7 @@ const findMissingTimeline = (
item.line,
testCase.label,
locale,
`"${item.text}"`,
errorStr,
];
}
}
Expand Down

0 comments on commit 86f5ae1

Please sign in to comment.