(id, ...args)
| 27 | * @returns {string} - The formatted translation |
| 28 | */ |
| 29 | export function getString(id, ...args) { |
| 30 | let translation = translations[id] || (baseTranslations && baseTranslations[id]) || id; |
| 31 | if (args.length === 0) return translation; |
| 32 | |
| 33 | let argIndex = 0; |
| 34 | return translation.replace(/%(?:(\d+)\$)?([%sdfx])/g, (match, index, type) => { |
| 35 | if (type === '%') return '%'; |
| 36 | if (index) { |
| 37 | const i = parseInt(index) - 1; |
| 38 | return args[i] !== undefined ? args[i] : match; |
| 39 | } else { |
| 40 | return args[argIndex++] !== undefined ? args[argIndex - 1] : match; |
| 41 | } |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Parse XML translation file into a JavaScript object |
no outgoing calls
no test coverage detected