Skip to content

Instantly share code, notes, and snippets.

@3dd13
Created April 3, 2014 01:52
Show Gist options
  • Select an option

  • Save 3dd13/9946929 to your computer and use it in GitHub Desktop.

Select an option

Save 3dd13/9946929 to your computer and use it in GitHub Desktop.

Revisions

  1. 3dd13 created this gist Apr 3, 2014.
    7 changes: 7 additions & 0 deletions application.html.ejs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <!-- app/views/layouts/application.html.ejs -->

    <!-- generate a link with to switch locale -->
    <ul>
    <li><%- linkTo(i18n.getText("nav.links.switch_to_english"), {locale: "en-us"}) %></li>
    <li><%- linkTo(i18n.getText("nav.links.switch_to_chinese"), {locale: "zh-tw"}) %></li>
    </ul>
    10 changes: 10 additions & 0 deletions application.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    // app/controllers/application.js

    // decide the locale to be used in view, inside application controller before filter
    var Application = function () {
    this.before(function() {
    this.i18n.setLocale(this.params.locale);
    });
    };

    exports.Application = Application;
    5 changes: 5 additions & 0 deletions en-us.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    // config/locales/en-us.json

    {
    "main.header.courses": "courses",
    }
    11 changes: 11 additions & 0 deletions environment.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    // config/environment.js

    // set default locale when no locale is provided
    var config = {
    generatedByVersion: '0.12.7',
    i18n: {
    defaultLocale: 'en-us'
    }
    }

    module.exports = config;
    7 changes: 7 additions & 0 deletions index.html.ejs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <!-- app/views/main/index.html.ejs -->

    <!-- show translated text -->
    <h1><%= i18n.getText('main.header.courses') %></h1>

    <!-- generate a link with current locale -->
    <%- linkTo(i18n.getText("faq.question.when"), {controller: "about", action: "index", anchor: "faq", locale: i18n.getLocale()}) %>
    5 changes: 5 additions & 0 deletions zh-tw.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    // config/locales/zh-tw.json

    {
    "main.header.courses": "課程",
    }