All files / core/blong-browser/src/i18n menu.ts

100% Statements 10/10
100% Branches 11/11
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40      9x                     12x 3x 12x   1x       1x       12x 2x                        
import type {IMenuItem, IPortalConfig} from '../types/portal.js';
 
/** The component method that opens the untranslated-strings page. */
export const TRANSLATION_REPORT_METHOD = 'ui.i18n.missing';
 
/**
 * Add the untranslated-strings page to a portal that collects.
 *
 * The entry exists only while `translation.collect` is on, so a normal portal
 * — and every screenshot baseline taken from one — never grows a menu group it
 * cannot explain (`D-634`). Idempotent: composing the config twice must not list
 * the page twice.
 */
export function withTranslationReport(config: IPortalConfig): IPortalConfig {
    if (!config.translation?.collect) return config;
    const menu = (config.menu ?? []) as IMenuItem[];
    const present = menu.some(
        entry =>
            typeof entry !== 'string' &&
            'items' in entry &&
            (entry.items as unknown[]).some(
                item =>
                    typeof item === 'string' ||
                    (item as {method?: string}).method === TRANSLATION_REPORT_METHOD,
            ),
    );
    if (present) return config;
    return {
        ...config,
        menu: [
            ...menu,
            {
                id: 'i18n',
                title: 'Translations',
                items: [{method: TRANSLATION_REPORT_METHOD} as IMenuItem],
            },
        ],
    };
}