ern `webext-perms-description-${permission}` * where `permission` is sanitized to be a valid Fluent identifier. * * This is exported to allow builds (e.g. Thunderbird) to extend or modify the map. */ export const PERMISSION_L10N_ID_OVERRIDES = new Map(); /** * Maps a permission name to its l10n identifier. * * Returns `null` for permissions not in `PERMISSIONS_WITH_MESSAGE`. * * The default `webext-perms-description-${permission}` mapping * may be overridden by entries in `PERMISSION_L10N_ID_OVERRIDES`. * * @param {string} permission * A permission name. * @param {boolean} [short=false] short * An optional parameter to indicate whether to * get l10n IDs for short-form or long-form * strings. The default is to return short-form * string IDs. * @returns {string | null} */ export function permissionToL10nId(permission, short = false) { if (DATA_COLLECTION_PERMISSIONS.has(permission)) { const prefix = short ? "short" : "long"; return `webext-perms-description-data-${prefix}-${permission}`; } if (!PERMISSIONS_WITH_MESSAGE.has(permission)) { return null; } if (PERMISSION_L10N_ID_OVERRIDES.has(permission)) { return PERMISSION_L10N_ID_OVERRIDES.get(permission); } // Sanitize input to end up with a valid l10n id. // E.g. "" to "all-urls", "downloads.open" to "downloads-open". const sanitized = permission .replace(/[^a-zA-Z0-9]+/g, "-") .replace(/^-|-$/g, ""); return `webext-perms-description-${sanitized}`; } PK