| 10 | import translations from 'translations'; |
| 11 | |
| 12 | function gettextForTranslation(translations, ...replaceArgs) { |
| 13 | const text = replaceArgs[0]; |
| 14 | let rawTranslation = translations[text] ? translations[text] : text; |
| 15 | |
| 16 | if(arguments.length == 2) { |
| 17 | return rawTranslation; |
| 18 | } |
| 19 | |
| 20 | try { |
| 21 | return rawTranslation.split('%s') |
| 22 | .map(function(w, i) { |
| 23 | if(i > 0) { |
| 24 | if(i < replaceArgs.length) { |
| 25 | return [replaceArgs[i], w].join(''); |
| 26 | } else { |
| 27 | return ['%s', w].join(''); |
| 28 | } |
| 29 | } else { |
| 30 | return w; |
| 31 | } |
| 32 | }) |
| 33 | .join(''); |
| 34 | } catch(e) { |
| 35 | console.error(e); |
| 36 | return rawTranslation; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | export default function gettext(text, ...args) { |
| 41 | return gettextForTranslation(translations, text, ...args); |