0

I have downloaded require.js i18n plugin to give some translation to the views, they use handlebars templates but the strings between the html tags are not enclosed in curly braces. The templates are loades using hbs!

I'm a beginner and after much thinking any of my attempts have been fruitful. How can my view render the translated strings? thanks a lot for real.

    // my View
    View = Marionette.ItemView.extend({

        template: theTmpl,

     //some events and logic

        initialize: function() {

        }

    });
JjAA
  • 13
  • 2

1 Answers1

0

To get translated string you can use custom Handlebar helpers like

   Handlebars.registerHelper('$', function() {
    var args = Array.prototype.slice.apply(arguments),
      options = args.pop();

    // If multiple params are present then use sprintf
    if (args.length > 1) {
      return i18next.translate.apply(null, args);
    }

    // Otherwise pass in any hash params
    return i18next.translate(args[0], options.hash);
  });

and in the hbs template you can write like

{{$ 'Hello world'}}

and if you have mapped Hello World to Bonjour le monde then you will see Bonjour le monde in your browser.

Pratik
  • 1,531
  • 3
  • 25
  • 57