question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi,

I didn’t got it right how to make custom helpers to use i18n without using handlebars direct

im getting this error when i start my application.

exphbs.registerHelper('__', function () {
       ^
TypeError: undefined is not a function

Otherwise the templates are rendering just fine, so im must be doing almost everything ok… 😃

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
gzurbachcommented, Feb 17, 2016

Figured it out! The solution simply consists in using the data.root.locale from the last argument of the helper.

app.use(function(req, res, next) {
  hbs.handlebars.registerHelper('i18n', function() {
    var args = Array.prototype.slice.call(arguments);
    var options = args.pop();
    return i18n.__.apply(options.data.root, args);
  });
  next();
});
1reaction
travnelscommented, May 3, 2016

using data.root.locale worked for me too. I however am only using it when this.locale is not set for optimization.

    if(!this.locale){
      var args = Array.prototype.slice.call(arguments)
      var options = args.pop()
      return i18n.__.apply(options.data.root, args)
    }
    return i18n.__.apply(this, arguments)
Read more comments on GitHub >

github_iconTop Results From Across the Web

i18n-helpers - npm
A set of helpers for performing i18n translations. Latest version: 0.1.2, last published: 5 years ago. Start using i18n-helpers in your ...
Read more >
tenfold/i18n-helpers: Helpers for preparing i18n translations
This module is useful when searching for missing keys or when one wants to provide placeholders for missing keys. It also finds any...
Read more >
Rails Internationalization (I18n) API - Ruby on Rails Guides
Every helper method dependent on url_for (e.g. helpers for named routes like root_path or root_url , resource routes like books_path or books_url ,...
Read more >
Localization Helpers - Lyften
Localization Helpers is a set of tools to help you manage translations with in your Laravel application. It's parses all translations in application ......
Read more >
Introduction - laminas-i18n - Laminas Docs
Abstract Translator Helper. The AbstractTranslatorHelper view helper is used as a base abstract class for any helpers that need to translate content. It ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found