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

23 lines
695 B
JavaScript
Raw Normal View History

2018-08-28 07:28:21 +02:00
import { version, name } from "../package.json";
export default {
name: name,
version: version,
hooks: {
2018-12-17 15:56:47 +01:00
preRender: function(svg) {
if(svg.attributes.get('freesewing:plugin-i18n') === false) {
svg.attributes.set('freesewing:plugin-i18n', version);
}
2018-08-28 07:28:21 +02:00
},
2018-12-17 15:56:47 +01:00
insertText: function(locale, text, data) {
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;
}
2018-12-17 15:56:47 +01: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
}
}
};