Un assistant peut-il me dire s'il est possible d'appeler un assistant à l'intérieur d'un autre assistant. J'ai besoin d'appeler un assistant i18n à l'intérieur d'un assistant de format de date. Je n'arrive pas à le faire fonctionner. Je me demandais si c'est encore possible avec ce plugin.NodeJs Handlebars i18next appelant l'aide à l'intérieur d'un autre assistant
voici ma configuration:
const express = require('express');
const i18next = require('i18next');
i18next.init(options);
app.use(i18nextMiddleware.handle(i18next));
app.post(path.join(__dirname,'/locales/add/{{ns}}/{{lng}}'), i18nextMiddleware.missingKeyHandler(i18next));
app.get(path.join(__dirname,'/locales/resources.json'), i18nextMiddleware.getResourcesHandler(i18next));
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.engine('hbs', exphbs({
extname: 'hbs',
defaultLayout: 'main_layout',
layoutDir: path.join(__dirname, 'views/layouts/'),
partialsDir: path.join(__dirname,'views/partials/'),
helpers: {
i18n: function(key, options){
var result = this.t(key, options.hash);
return new Handlebars.SafeString(result);
},
formatExpire: function (namespace, date, format, lang) {
// strText = "expired On";
// strText = Handlebars.i18n.t('namespace:translationString'); // Cannot read property 't' of undefined
// strText = Handlebars.i18n('namespace:translationString'); // Handlebars.i18n is not a function
strText = Handlebars._default_helpers['i18n'].t('namespace:translationString'); // t is not a function
htmlDisplay = "<span class='bg-danger-800 text-highlight'>" + strText + "<span class='text-semibold'></span></span>";
return htmlDisplay;
}
...
....
}
})
)
app.set('view engine', 'hbs');
toute autre chose fonctionne très bien, tous les assistants j'ai aucun problème avec. seulement quand j'appelle le "formatExpire" que j'obtiens les erreurs énumérées comme commentaires dans la fonction d'aide.
Toute aide serait grandement appréciée.
grâce
ne fonctionne pas je reçois: TypeError: Handlebars.helpers.i18n est pas une fonction quand je fais un journal de la console (Handelbars.helpers) je reçois: {blockHelperMissing: [Fonction], chaque : [Fonction], helperMissing: [Fonction], si: [Fonction], à moins que: [Fonction], journal: [Fonction], recherche: [Fonction], avec: [Fonction]} il est qu'afficher le construit en aides de guidon, aucun de mes assistants de cutom est énuméré. – boulepick