const out = { currentlang: 'en', } const i18n = { lang_change_long: ['Skipta yfir á íslensku', 'Change to english'], lang_current: ['en', 'is'], header_title: ['Fíladelfia archival center', 'Fíladelfia myndhvelfing'], header_logout: ['Log out', 'Skrá út'], title: ['Title', 'Titill'], date: ['Date', 'Dagsetning'], language: ['EN', 'IS'], upload_goto: ['Upload', 'Upphlaða'], login_error: ['Error while logging in: {0}', 'Villa við innskráningu: {0}'], login_error_auth: ['Unknown error from server. Try again later.', 'Óþekkt villa frá vefþjóni. Reyndu aftur seinna.'], login_missing_email: ['Email is missing', 'Email eða nafn vantar'], login_missing_password: ['Password is missing', 'Lykilorð vantar'], login_email: ['Email or name', 'Email eða nafn'], login_password: ['Password', 'Lykilorð'], login_submit: ['Log in', 'Skrá inn'], login_footer: ['Photo by {0} on {1}', 'Mynd eftir {0} frá {1}'], } const langs = { 'en': 0, 'is': 1, } const regexNumber = new RegExp('^\\d+$') out.langset = function(lang) { out.currentlang = lang let index = langs[lang] let keys = Object.keys(i18n) for (let key of keys) { out[key] = i18n[key][index] } } out.langtoggle = function() { out.langset(out.currentlang === 'en' ? 'is' : 'en') return false } out.format = function(str, ...args) { return out.mformat(str, ...args).join('') } out.mformat = function(str, ...args) { let split = (str || '').split(/\{|\}/) return split.map(function(item) { if (regexNumber.test(item)) { return args[Number(item)] || item } return item }) } out.langset('is') module.exports = out