Creating own Plugins
backend
{
type: 'backend',
init: function(services, backendOptions, i18nextOptions) {
/* use services and options */
},
read: function(language, namespace, callback) {
/* return resources */
callback(null, {
key: 'value'
});
/* if method fails/returns an error, call this: */
/* callback(truthyValue, null); */
},
// or new since i18next v22.1.0
// read: function(language, namespace) {
// return new Promise((resolve) => {
// resolve({
// key: 'value'
// })
// })
// },
// optional
readMulti: function(languages, namespaces, callback) {
/* return multiple resources - useful eg. for bundling loading in one xhr request */
callback(null, {
en: {
translations: {
key: 'value'
}
},
de: {
translations: {
key: 'value'
}
}
});
/* if method fails/returns an error, call this: */
/* callback(truthyValue, null); */
},
// or new since i18next-multiload-backend-adapter v2.1.0
// readMulti: function(languages, namespaces) {
// return new Promise((resolve) => {
// resolve({
// en: {
// translations: {
// key: 'value'
// }
// },
// de: {
// translations: {
// key: 'value'
// }
// }
// })
// })
// },
// only used in backends acting as cache layer
save: function(language, namespace, data) {
// store the translations
},
create: function(languages, namespace, key, fallbackValue) {
/* save the missing translation */
}
}languageDetector
post processor
logger
formatter
Helpful tips
Make sure to set the plugin type
Create a private method to initialize your plugin
Last updated