funktionswerk / hapi-i18n

Translation module for hapi based on mashpie's i18n module
MIT License
39 stars 22 forks source link

How I can use it with a dynamic field on handlebars? #7

Closed odorisioe closed 8 years ago

odorisioe commented 8 years ago

I have the file ./locales/en.json { "hello": "Hello, {{name}}!" }

This work well in the controller if I do this: return reply(request.i18n.__( "hello", {name: 'Emma'}));

But I can not make work on the template. I can use it without set the name
<p>{{__ 'hello' }}</p> But in this example, this will look like "Hello, __!"

Is there any way to add the field name on the template of handlebars? Thanks

funktionswerk commented 8 years ago

I am not sure how handlebars works. You might have to register a helper for the translation: http://stackoverflow.com/questions/7760332/how-to-make-i18n-with-handlebars-js-mustache-templates

odorisioe commented 8 years ago

Hi, thanks for the reply. The function works because when I use {{ 'hello' }} on the template, I can see "Hello, !" It looks like missing parameters or I am not setting properly. Also I am trying in Nunjucks and I have the same result

I tried in a lot of ways like {{ 'hello' name="TestName" }} {{ 'hello' "TestName" }}

Do you know how is the syntax for Jade ? Is the next template engine to test

funktionswerk commented 8 years ago

There is an example of how to use it with Jade in the README at the beginning: https://github.com/codeva/hapi-i18n

odorisioe commented 8 years ago

I did it a pull request to the README with information about how use dynamic variables on Jade and Nunjucks. #8 I could not find the way for Handlebars

funktionswerk commented 8 years ago

I have merged your pull request.. Thanks for the contribution.