Dynamic output does not work with hoganjs templates #13

Open
yar0d opened this Issue Oct 19, 2012 · 4 comments

Comments

Projects
None yet
3 participants

yar0d commented Oct 19, 2012

Hello,

I'm using Express + Hogan + Lingua for my application. Static translations works well, but dynamic output always results in an empty translation.

Can you help me, please ?

Here is my template test.hjs

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>{{lingua.application.title}}</title>
</head>
<body>
    <div>{{lingua.application.title}}</div>
    <div>{{lingua.application.name(app)}}</div>
</body>
</html>

And the nodejs module test.js

exports.dialog = function () {
    var show = function (req, res) {
        res.render('test', {
            app: {
                version: '0.0.1'
            }
        });
    }

    return {
        show: show
    };
};

My en.json file

{
    "application": {
        "title": "My i18n test app",
        "name": "Test version {version}"
    }
}

The rendered result :

My i18n test app

Thanks

Owner

akoenig commented Oct 19, 2012

Hello yar0d,

thank you for your response. Is good to see that people using lingua with different template engines. One aim of lingua is to make it compatible with as much template engines as possible.

I never used hogan.js in any of my projects before so that I have to create a testcase to see what really happens. Give me a little bit of time to do some research as I'm pretty busy with other stuff at the moment.

//André

Hi.

I'm also interested in using express-lingua with Hogan. Is there any chance that this issue was resolved?

Many thanks,
Sheldon

Owner

akoenig commented Nov 22, 2013

express-lingua does not support Hogan.js. After some research I do not see a way to support this template engine in the near future. There might be a possibility in using the "lambda expression" like

{{#lingua.greeting}}{{/lingua.greeting}}

but it does not really execute the respective compile function within lingua. I do not use Hogan in any of my projects. So there might be a way. Any idea regarding this topic is much appreciated.

This might not directly relate to lingua, but we did get this working with i18n-node / Express.js / Hogan.js by using Hogan lambdas.

Express.js config:

//Internationalization
viewLocale = require('../middleware/view-locale');
var i18n = require('i18n');
this.use(i18n.init);
this.use(viewLocale(i18n)); //Register middleware for using {{#__}} and {{#localize}} in views

Contents of "view-locale" file:

//Capture localization lambda to i18n its contents
module.exports = function (i18n){
    //register helper function for views
    return function(req, res, next) {
        // View helper: {{#__}} and {{#localize}} will both be used to localize text in views
        res.locals.localize = res.locals.__ =  function localizeInView() {
            return function(text, render) {
                return i18n.__.apply(req, arguments);
            };
        };
        next();
    };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment