'use strict'; function createI18n() { const t = (key, ...args) => { let sub; let count; args.forEach((arg, i) => { if (arg == null) ; else if (typeof arg === "number") { count = arg; } else if (Array.isArray(arg)) { sub = arg; } else { throw Error( `Unknown argument at index ${i}. Must be a number for pluralization, substitution array, or options object.` ); } }); if (count != null && sub == null) { sub = [String(count)]; } let message; if (sub?.length) { const stringSubs = sub?.map((sub2) => String(sub2)); message = chrome.i18n.getMessage(key.replaceAll(".", "_"), stringSubs); } else { message = chrome.i18n.getMessage(key.replaceAll(".", "_")); } if (!message) { console.warn(`[i18n] Message not found: "${key}"`); } if (count == null) return message; const plural = message.split(" | "); switch (plural.length) { case 1: return plural[0]; case 2: return plural[count === 1 ? 0 : 1]; case 3: return plural[count === 0 || count === 1 ? count : 2]; default: throw Error("Unknown plural formatting"); } }; return { t }; } exports.createI18n = createI18n;