import en from './en' ; import ru from './ru' ; import es from './es' ; import pl from './pl' ; import fr from './fr' ; import uk from './uk' ; import ptbr from './ptbr' ; import tr from './tr' ; import he from './he' ; import nl from './nl' ; import ja from './ja' ; import de from './de' ; import ko from './ko' ; import zh from './zh' ; import fa from './fa' ; import sv from './sv' ; import cs from './cs' ; import it from './it' ; import el from './el' ; import ConsoleLogger from '~/logging/ConsoleLogger' ; import { TiptapVuetifyPlugin } from '~/main' ; export const defaultLanguage = 'en' ; export const dictionary = { en , ru , es , pl , fr , uk , ptbr , tr , he , nl , ja , de , ko , zh , zhHans : zh , fa , sv , cs , it , el } ; export function getCurrentLang ( ) { return TiptapVuetifyPlugin . vuetifyLang || defaultLanguage ; } export function getMsg ( path , args ? , lang = null ) { let currentLang = lang || getCurrentLang ( ) ; if ( ! dictionary [ currentLang ] ) { ConsoleLogger . warn ( `The current language "${ currentLang }" is not yet available. Using language "${ defaultLanguage }" by default. Contribution to github is welcome.` ) ; currentLang = defaultLanguage ; } const dictionaryByLang = dictionary [ currentLang ] ; let target ; try { target = path . split ( '.' ) . reduce ( ( prev , curr ) => { return prev [ curr ] ; } , dictionaryByLang ) ; if ( target === undefined ) { throw new Error ( `${ path } is undefined.` ) ; } } catch ( e ) { ConsoleLogger . warn ( `Cannot get translation "${ path }" for language "${ currentLang }". Fallback "${ defaultLanguage }" is used instead. Contribution to github is welcome.` ) ; return getMsg ( path , args , defaultLanguage ) ; } if ( target instanceof Function ) { return target ( args ) ; } return target ; }