使用Closure.js,node.js,handlebars和Cordova时,require未定义错误

时间:2015-06-27 17:27:47

标签: node.js cordova handlebars.js google-closure

我正在使用Cordova构建Android和iOS应用程序。我正在使用Google closure.jsnode.jshandlebars作为模板渲染。我想使用this指南实现国际化。我的编译过程正在使用grunt。要在把手中添加助手,我正在使用

goog.provide('myproject.cat.HandlebarsHelpers');   // {{alias HandlebarsHelpers}}

goog.scope(function () {

    // {{strict_and_dependency_aliases}}

    /**
     * The HandlebarsHelpers module defines and registers
     * Handlebars helper functions.
     *
     * @const
     * @see handlebarsjs.com/#helpers
     * @public
     */
    myproject.cat.HandlebarsHelpers = {};

    // {{module_alias}}


    /**
     * TODO
     * @param
     * @return {string}          - translated string
     * @private
     */
    function i18nTranslation() {
        //return "hi";

        // I will show you later how to really load a catalog
        // + some more specific cases
        var mySpanishCatalog = require('fr');  << - ERROR

        var i18n = new Jed(mySpanishCatalog);
        var translation = i18n.gettext('Hello world!');
        return "Hola";

        // arguments = in template params + a handlebars hash
        // this = in template context
        //var value = Array.prototype.slice.call(
        //            arguments, 0, arguments.length - 1);
        //return i18n.gettext.apply(i18n, value);

    }


    /**
     * Enum which maps helper names to functions.
     *
     * @enum {!Function}
     * @private
     */
    var helpers = {
        'i18n': i18nTranslation
    };

    /**
     * Initialise.
     *
     * @public
     */
    HandlebarsHelpers.init = function () {

        var helperName, helperFunction;

        for (helperName in helpers) {
            if (helpers.hasOwnProperty(helperName)) {
                helperFunction = helpers[helperName];
                window.Handlebars.registerHelper(helperName, helperFunction);
            }
        }

    };

});

0 个答案:

没有答案