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'], upload_missing_title: ['Title is missing', 'Titill vantar'], upload_missing_date: ['Date is missing', 'Dagsetning vantar'], upload_missing_file: ['Video file missing', 'Myndaskrá vantar'], upload_missing_banner: ['Poster image missing', 'Mynd vantar'], upload_error: ['Error while uploading: {0}', 'Villa við að hlaða upp myndefni: {0}'], unsplash: ['Photo by {0} on {1}', 'Mynd eftir {0} frá {1}'], api_down: ['No internet or browser blocked the request.', 'Ekkert net eða vafri blockaði fyrirspurn.'], months: { '1': ['January', 'Janúar'], '2': ['February', 'Febrúar'], '3': ['March', 'Mars'], '4': ['April', 'Apríl'], '5': ['May', 'Maí'], '6': ['June', 'Júní'], '7': ['July', 'Júlí'], '8': ['August', 'Ágúst'], '9': ['September', 'September'], '10': ['Oktober', 'Október'], '11': ['November', 'Nóvember'], '12': ['December', 'Desember'], }, } const langs = { 'en': 0, 'is': 1, } const regexNumber = new RegExp('^\\d+$') out.langset = function(lang) { out.currentlang = lang let index = langs[lang] for (let key of Object.keys(i18n)) { if (!Array.isArray(i18n[key])) { out[key] = {} for (let subKey of Object.keys(i18n[key])) { out[key][subKey] = i18n[key][subKey][index] } } else { 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