Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic output does not work with hoganjs templates #13

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

Dynamic output does not work with hoganjs templates #13

yar0d opened this issue Oct 19, 2012 · 4 comments

Comments

@yar0d
Copy link

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

@akoenig
Copy link
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é

@SheldonPacotti
Copy link

Hi.

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

Many thanks,
Sheldon

@akoenig
Copy link
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.

@SheldonPacotti
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants