i18ntk
Version:
i18n Tool Kit - Zero-dependency internationalization toolkit for setup, scanning, analysis, validation, auto translation, fixing, reporting, and runtime translation loading.
21 lines (16 loc) • 553 B
JavaScript
/**
* Helpers for language selection menus.
*/
function formatLanguagePrompt(prompt, maxOption) {
const max = String(maxOption);
const fallback = `Select a language (0-${max}):`;
const text = typeof prompt === 'string' && prompt.trim() ? prompt : fallback;
if (text.includes('{max}')) {
return text.replace(/\{max\}/g, max);
}
const updated = text.replace(/\(0\s*[-–—~~]\s*\d+\)/u, `(0-${max})`);
return updated === text ? `${text.replace(/\s*$/, '')} (0-${max}):` : updated;
}
module.exports = {
formatLanguagePrompt
};