1
0
Fork 0
freesewing/plugins/plugin-i18n/src/index.mjs
2023-07-04 20:29:24 +02:00

28 lines
883 B
JavaScript

import { name, version } from '../data.mjs'
export const plugin = {
name,
version,
hooks: {
insertText: (locale, text, t, pattern) => {
if (t instanceof Function) return t(text, locale)
else if (typeof t[locale] === 'object') return t[locale][text] || text
else {
const msg =
"No translation method or object was passed to the i18n plugin. This plugin won't do anything without that"
if (pattern?.store?.log?.warning) {
if (!pattern.store.get(['plugins', 'plugin-i18n', 'missingMethodWarning'])) {
pattern.store.set(['plugins', 'plugin-i18n', 'missingMethodWarning'], true)
pattern.store.log.warning(msg)
}
} else console.log(msg)
return text
}
},
},
}
// More specifically named exports
export const i18nPlugin = plugin
export const pluginI18n = plugin