• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
I18n   share
 

I18n share

on

  • 1,048 views

 

Statistics

Views

Total Views
1,048
Views on SlideShare
1,048
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    I18n   share I18n share Presentation Transcript

    • i18n and L10n in Node.js Kai livdea.com
    • • Resource file support• View template support• Language detection
    • but we are greedy….No using external resource, nor serviceRecently UpdateDocumentation
    • i18n-node• has all we need!• gets updated!!• is documented!!!!!!
    • So…it’s like 我懂正體中文我也說中文 {‘zh-tw’} {‘我也說中文’}
    • Or…. mitä kuuluuHow are you? {‘fi’} {‘How are you?’} Oops…..
    • That’s it. Let’s do it.Build your own https://github.com/kaijan/nodejs-taiwan-i18n.git
    • Installation and Configuration1. Installation $: npm install i18n2. Require var i18n = require("i18n");3. app.configure() app.use(i18n.init); //language detection4. i18n configuration i18n.configure({ locales:[zh-tw,zh] // prefered language, and resource file });
    • Installation and Configuration5. For view app.locals({ __i: i18n.__ // so we can use i18n method in view });6. Resource file i18n module will create a locales folder within the directorywhere you execute your node server
    • app.use(i18n.init)? Language detectionLoot at http request headers request[headers][accept-language] zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4would mean: "I prefer Chinese-Taiwan, but will accept United States Englishand other types of English."(http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)guessLanguage(request)
    • Easy to codeCode in node.jsconsole.log(i18n.__(HelloWorld));console.log(i18n.__(HelloGroup, Node.js, 30));Code in view (using Jade)div #{__i(HelloWorld)}div #{__i(HelloGroup, node.js, 30)}
    • Hi, TaiwanWe need zh-TW rather than zh(Chinese)in i18n.js, add the region detectionrequest.language_region = request.language ;if (request.region){ request.language_region = request.language_region +-+ request.region;}i18n.setLocale(request, request.language_region);
    • Hi, Mr. TroubleCan’t switch language? Because defaultLocale ischanged, but we can fix itif (locales[target_locale]) { request.locale = target_locale; defaultLocale = target_locale; } else { defaultLocale = en; request.locale = defaultLocale; }
    • Built on Node.js, MongodDB, Nginx and EC2