Search code examples
javascriptunderscore.jsgettext

Underscorejs and gettext name conflict


How do you mix underscorejs and gettext for _("")?

What do you think is better to give gettext another function name or rename underscorejs?


Solution

  • You can use Underscore's noConflict method, for example:

    // gettext is already loaded here,
    // so _ variable points to Gettext instance
    
    var underscore = _.noConflict();
    

    Now you can access Underscore's methods from underscore variable and gettext's from _.

    UPD: Excuse me, misunderstood. Personally, I think the one should reserve _ for Underscore and use gt for Gettext. The reason behind it is that using Underscore and seeing it as _ seems to be more common for JS developers.