2022-09-09 12:13:52 -05:00
|
|
|
import { name, version } from '../data.mjs'
|
2018-08-28 07:28:21 +02:00
|
|
|
|
2022-08-28 12:44:22 +02:00
|
|
|
export const plugin = {
|
|
|
|
name,
|
|
|
|
version,
|
2018-08-28 07:28:21 +02:00
|
|
|
hooks: {
|
2023-07-02 19:42:19 +02:00
|
|
|
insertText: (locale, text, t, pattern) => {
|
2023-07-04 20:28:09 +02:00
|
|
|
if (t instanceof Function) return t(text, locale)
|
|
|
|
else if (typeof t[locale] === 'object') return t[locale][text] || text
|
2023-07-02 19:42:19 +02:00
|
|
|
else {
|
|
|
|
const msg =
|
2023-07-04 20:28:09 +02:00
|
|
|
"No translation method or object was passed to the i18n plugin. This plugin won't do anything without that"
|
2023-07-02 19:42:19 +02:00
|
|
|
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)
|
|
|
|
|
2019-08-03 15:03:33 +02:00
|
|
|
return text
|
2018-12-20 08:30:34 +01:00
|
|
|
}
|
2021-04-24 10:16:31 +02:00
|
|
|
},
|
|
|
|
},
|
2019-08-03 15:03:33 +02:00
|
|
|
}
|
2022-08-28 12:44:22 +02:00
|
|
|
|
|
|
|
// More specifically named exports
|
|
|
|
export const i18nPlugin = plugin
|
|
|
|
export const pluginI18n = plugin
|