1
0
Fork 0
freesewing/packages/plugin-i18n/src/index.js

25 lines
714 B
JavaScript
Raw Normal View History

2019-08-03 15:03:33 +02:00
import { version, name } from '../package.json'
2018-08-28 07:28:21 +02:00
export default {
name: name,
version: version,
hooks: {
2018-12-17 15:56:47 +01:00
preRender: function(svg) {
2019-08-03 15:03:33 +02:00
if (svg.attributes.get('freesewing:plugin-i18n') === false) {
svg.attributes.set('freesewing:plugin-i18n', version)
2018-12-17 15:56:47 +01:00
}
2018-08-28 07:28:21 +02:00
},
2018-12-17 15:56:47 +01:00
insertText: function(locale, text, data) {
2019-08-03 15:03:33 +02:00
if (data === false) {
console.log(
"No data was passed to the i18n plugin. This plugin won't do much without injecting data into it"
)
return text
}
2019-08-03 15:03:33 +02:00
let prefix = data.prefix || ''
if (typeof data.strings[locale][prefix + text] === 'undefined') return text
else return data.strings[locale][prefix + text]
2018-08-28 07:28:21 +02:00
}
}
2019-08-03 15:03:33 +02:00
}