Created
April 3, 2014 01:52
-
-
Save 3dd13/9946929 to your computer and use it in GitHub Desktop.
Working with i18n in geddy.this example shows how to see chinese translated text in http://localhost:4000/?locale=zh-tw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// config/locales/en-us.json | |
{ | |
"main.header.courses": "courses", | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// config/environment.js | |
// set default locale when no locale is provided | |
var config = { | |
generatedByVersion: '0.12.7', | |
i18n: { | |
defaultLocale: 'en-us' | |
} | |
} | |
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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()}) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// config/locales/zh-tw.json | |
{ | |
"main.header.courses": "課程", | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment