{"id":436,"date":"2022-08-30T15:01:19","date_gmt":"2022-08-30T15:01:19","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/about-the-language-globalization-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:01:19","modified_gmt":"2022-08-30T15:01:19","slug":"about-the-language-globalization-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/about-the-language-globalization-collection-of-common-programming-errors\/","title":{"rendered":"About the language globalization-Collection of common programming errors"},"content":{"rendered":"<p>How to make the meteor application support multiple languages ? for example \uff1aChinese,English.<\/p>\n<p>The first,I try to use the Handlebars.registerHelper and Session ,but I&#8217;m failed.<\/p>\n<p>The test.js code :<\/p>\n<pre>\n\n    Handlebars.registerHelper('language',function(arg){\n        var nalization = Session.get('nalization');\n        console.log(nalization);\n        var language = Session.get(\"language\")[nalization];\n        if (!language){\n            console.log(\"nalization\"+nalization+\" is undefined\");\n            return \"\";\n        }\n        console.log(arg);\n        return language[arg] ? language[arg] : \"undefined\";\n    });\n\n    Template.hello.created = function(){\n        Session.set('nalization','cn');\n    }\n\n    Deps.autorun(function (c) {\n        Session.set(\"language\",{\n            cn : {\n                hello: \"\u4f60\u597d\",\n                language: \"Language\"\n            },\n            en : {\n                hello: \"Hello\",\n                language: \"\u8bed\u8a00\"\n            }\n        });\n        c.stop();\n    });\n    Template.hello.events = {\n        \"click #language_cn\":function(){\n            Session.get(\"nalization\") !== \"cn\" ? Session.set(\"nalization\",\"cn\") : 1=1;\n        },\n        \"click #language_en\":function(){\n            Session.set(\"nalization\",\"en\");\n            console.log();\n        }\n\n    }\n\n<\/pre>\n<p>The test.html code :<\/p>\n<pre><code>\n  {{&gt; hello}}\n\n\n\n<\/code><\/pre>\n<h1><code>{{#language \"hello\"}}{{\/language}}<\/code><\/h1>\n<pre>\n {{#language \"language\"}}{{\/language}}\n  \u4e2d\u6587\n  English\n\n<\/pre>\n<p><code>changed the value 'nalization' in Seesion by click events\uff0cbut the value is not change in registerHeloer .nothing happen on html.<\/code><\/p>\n<p><code>Any idea about the language globalization ? Thanks.<\/code><\/p>\n<ol>\n<li>\n<pre><code><code>Language = new Meteor.Collection();\n\nsession.setDeafault(\"language\",\"EN_US\");\n\nDeps.autorun(function(c){\n  var languages = [\n    {\n      name:\"EN_US\",\n      value:{\n         username:\"username\",\n         password:\"password\"\n      }\n    },\n    {\n      name:\"ZH_CN\",\n      value:{\n         username:\"yonghu\",\n         password:\"mima\"\n      }\n    }\n  ];\n  if(Language.find({}).fetch().length)\n      Language.remove({});\n  for(index in languages){\n    Language.insert(languages[index]);\n  }\n  c.stop();\n});\n\nHandlebars.helpers('language',function(){\n  return Language.findOne({name:Session.get(\"language\")}).value;\n});\n\n\/**\n    Change  language by click events\n    for example:\n    \"click #chooseLanguage\":function(){\n          Session.set(\"language\",\"ZH_CN\");\n    }\n\n    in the html:\n    {{language.username}}\n    {{language.password}}\n\n*\/\n<\/code><\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 19:42:32. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>How to make the meteor application support multiple languages ? for example \uff1aChinese,English. The first,I try to use the Handlebars.registerHelper and Session ,but I&#8217;m failed. The test.js code : Handlebars.registerHelper(&#8216;language&#8217;,function(arg){ var nalization = Session.get(&#8216;nalization&#8217;); console.log(nalization); var language = Session.get(&#8220;language&#8221;)[nalization]; if (!language){ console.log(&#8220;nalization&#8221;+nalization+&#8221; is undefined&#8221;); return &#8220;&#8221;; } console.log(arg); return language[arg] ? language[arg] : &#8220;undefined&#8221;; }); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-436","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=436"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/436\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}