internationalization - How to read variables from locals in Swig custom tag/filter? -


I'm trying to create i18n modules for my app because I'm using swing so that's why I use the custom tag " Transposed "so that such translated results can be cached.

I am using Express.js 4 as the base for my app.

How can I read the variable from the request of a custom tag or filter? I do not know how to read them (especially inside the filter) I can not even see the variable reaching the template. For example:

  swig template index.swig ------------------------------- {% Trans%} This is Sparta {% endtrans%} {% trans "fr"%} It is Sparta {% endtrans%} --------------------- - ---------  

I work on line 2. I pass the locale for "trans" and in my code, changes the text passed by the user from a French translation.

But I do not want to pass locale on every trans tag. I would like to do something like this:

  function (rik, race, next) {res.locals.locale = req.session.user.getLocale (); } // should now be the locale variable to see // and the trans should use the correct translation to the table {% trans%}, this Sparta {% endtrans%}  

A tutorial or an explanation? The document is non existent for that part of Swig. The problem is that each user can have a different language, so long code is chosen as requested and I should have access to that internal slice custom tag.

The template will be automatically written to app.local and res.local reads to the local people from both. Therefore, as mentioned, you can add middleware to locally set response on local people:

  app.use (function (req, res, next) {res .locals.locale = req Session.user.getLocale (); Next ();});  

This will expose locale as the global inside of your view.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -