function lines(label: string): string[] {
|
return (label || '').replaceAll(/<\\n>|\\n/g, '\n').split('\n');
|
}
|
|
export function getTableChildColumnLabel(parentLabel: string, childLabel: string): string {
|
const [parentName, parentEnglish] = lines(parentLabel);
|
const [childName, ...englishLines] = lines(childLabel);
|
const english = englishLines.join('\n');
|
const prefix = parentEnglish ? `${parentEnglish.trim()} - ` : '';
|
const childEnglish = prefix && english.startsWith(prefix) ? english.slice(prefix.length) : english;
|
return `${parentName}-${childName}${childEnglish ? `\n${childEnglish}` : ''}`;
|
}
|
|
export function getTableChildHeaderLabel(parentLabel: string, columnLabel: string, originalChildLabel = ''): string {
|
const separator = columnLabel.indexOf('-');
|
const childLabel = separator === -1 ? columnLabel : columnLabel.slice(separator + 1);
|
const [, parentEnglish] = lines(parentLabel);
|
const prefix = parentEnglish ? `${parentEnglish.trim()} - ` : '';
|
const [childName, ...englishLines] = lines(childLabel);
|
const english = englishLines.join('\n');
|
const originalEnglish = lines(originalChildLabel).slice(1).join('\n');
|
const childEnglish =
|
originalEnglish && english.endsWith(` - ${originalEnglish}`)
|
? originalEnglish
|
: prefix && english.startsWith(prefix)
|
? english.slice(prefix.length)
|
: english;
|
return `${childName}${childEnglish ? `\n${childEnglish}` : ''}`;
|
}
|