SlideShare ist ein Scribd-Unternehmen logo
1 von 16
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 service
Recently Update
Documentation
i18n-node
• has all we need!
• gets updated!!
• is documented!!!!!!
So…it’s like
                    我懂正體中文




我也說中文



                             {‘zh-tw’}




        {‘我也說中文’}
Or….
                                  mitä kuuluu




How 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 Configuration
1. Installation
        $: npm install i18n

2. Require
       var i18n = require("i18n");

3. app.configure()
       app.use(i18n.init);           //language detection

4. i18n configuration
        i18n.configure({
         locales:['zh-tw','zh']      // prefered language, and
        resource file
        });
Installation and Configuration
5. 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 directory
where you execute your node server
app.use(i18n.init)? Language detection

Loot at http request headers
         request['headers']['accept-language']
         zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4

would mean: "I prefer Chinese-Taiwan, but will accept United States English
and other types of English."
(http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)




guessLanguage(request)
Easy to code
Code in node.js
console.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, Taiwan
We need zh-TW rather than zh(Chinese)
in i18n.js, add the region detection


request.language_region = request.language ;

if (request.region){
     request.language_region = request.language_region +'-'+ request.region;
}

i18n.setLocale(request, request.language_region);
Hi, Mr. Trouble

Can’t switch language? Because defaultLocale is
changed, but we can fix it


if (locales[target_locale]) {
      request.locale = target_locale;
      defaultLocale = target_locale;
 }
 else {
      defaultLocale = 'en';
      request.locale = defaultLocale;
 }
Built on Node.js, MongodDB, Nginx and EC2

Weitere ähnliche Inhalte

Andere mochten auch

Daily Freeman digital initiatives 2012
Daily Freeman digital initiatives 2012Daily Freeman digital initiatives 2012
Daily Freeman digital initiatives 2012Ivan Lajara
 
[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)
[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)
[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)보훈 현
 
Mount Soccer[1]
Mount Soccer[1]Mount Soccer[1]
Mount Soccer[1]stack2k
 
資策會未來領袖卓越成長營
資策會未來領袖卓越成長營資策會未來領袖卓越成長營
資策會未來領袖卓越成長營Shih Wu
 
Creativu Cebit Crs4
Creativu Cebit Crs4Creativu Cebit Crs4
Creativu Cebit Crs4mauromereu
 
First in the Hearts of His Countrymen
First in the Hearts of His CountrymenFirst in the Hearts of His Countrymen
First in the Hearts of His CountrymenVince Harris
 
Photo engagement in journalism
Photo engagement in journalismPhoto engagement in journalism
Photo engagement in journalismIvan Lajara
 
Stages of stress applied to academic testing
Stages of stress applied to academic testingStages of stress applied to academic testing
Stages of stress applied to academic testingdrmccreedy
 
Journalism and social media
Journalism and social mediaJournalism and social media
Journalism and social mediaIvan Lajara
 
[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)
[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)
[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)보훈 현
 
2 humanreproductionsystem-130922023408-phpapp01
2 humanreproductionsystem-130922023408-phpapp012 humanreproductionsystem-130922023408-phpapp01
2 humanreproductionsystem-130922023408-phpapp01Thusara Karunathilake
 
Digital initiatives
Digital initiativesDigital initiatives
Digital initiativesIvan Lajara
 

Andere mochten auch (20)

Daily Freeman digital initiatives 2012
Daily Freeman digital initiatives 2012Daily Freeman digital initiatives 2012
Daily Freeman digital initiatives 2012
 
Fineschool
FineschoolFineschool
Fineschool
 
[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)
[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)
[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)
 
Stress
StressStress
Stress
 
Mount Soccer[1]
Mount Soccer[1]Mount Soccer[1]
Mount Soccer[1]
 
資策會未來領袖卓越成長營
資策會未來領袖卓越成長營資策會未來領袖卓越成長營
資策會未來領袖卓越成長營
 
Creativu Cebit Crs4
Creativu Cebit Crs4Creativu Cebit Crs4
Creativu Cebit Crs4
 
First in the Hearts of His Countrymen
First in the Hearts of His CountrymenFirst in the Hearts of His Countrymen
First in the Hearts of His Countrymen
 
Photo engagement in journalism
Photo engagement in journalismPhoto engagement in journalism
Photo engagement in journalism
 
Un día típico
Un día típicoUn día típico
Un día típico
 
The changing voice_of_women
The changing voice_of_womenThe changing voice_of_women
The changing voice_of_women
 
Stages of stress applied to academic testing
Stages of stress applied to academic testingStages of stress applied to academic testing
Stages of stress applied to academic testing
 
Journalism and social media
Journalism and social mediaJournalism and social media
Journalism and social media
 
Hair proposals
Hair proposalsHair proposals
Hair proposals
 
Modas
ModasModas
Modas
 
[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)
[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)
[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)
 
2 humanreproductionsystem-130922023408-phpapp01
2 humanreproductionsystem-130922023408-phpapp012 humanreproductionsystem-130922023408-phpapp01
2 humanreproductionsystem-130922023408-phpapp01
 
Digital initiatives
Digital initiativesDigital initiatives
Digital initiatives
 
Peter and paul fortress
Peter and paul fortressPeter and paul fortress
Peter and paul fortress
 
92/93 dental batch
92/93 dental batch92/93 dental batch
92/93 dental batch
 

Ähnlich wie I18n share

Easy contributable internationalization process with Sphinx @ PyCon APAC 2016
Easy contributable internationalization process with Sphinx @ PyCon APAC 2016Easy contributable internationalization process with Sphinx @ PyCon APAC 2016
Easy contributable internationalization process with Sphinx @ PyCon APAC 2016Takayuki Shimizukawa
 
Living in a multiligual world: Internationalization for Web 2.0 Applications
Living in a multiligual world: Internationalization for Web 2.0 ApplicationsLiving in a multiligual world: Internationalization for Web 2.0 Applications
Living in a multiligual world: Internationalization for Web 2.0 ApplicationsLars Trieloff
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsDerek Anderson
 
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...adunne
 
Easy contributable internationalization process with Sphinx @ pyconmy2015
Easy contributable internationalization process with Sphinx @ pyconmy2015Easy contributable internationalization process with Sphinx @ pyconmy2015
Easy contributable internationalization process with Sphinx @ pyconmy2015Takayuki Shimizukawa
 
Silme & compare-locales
Silme & compare-localesSilme & compare-locales
Silme & compare-localesAdrianer
 
Easy contributable internationalization process with Sphinx @ pyconsg2015
Easy contributable internationalization process with Sphinx @ pyconsg2015Easy contributable internationalization process with Sphinx @ pyconsg2015
Easy contributable internationalization process with Sphinx @ pyconsg2015Takayuki Shimizukawa
 
Fullstack workshop
Fullstack workshopFullstack workshop
Fullstack workshopAssaf Gannon
 
Writing multi-language documentation using Sphinx
Writing multi-language documentation using SphinxWriting multi-language documentation using Sphinx
Writing multi-language documentation using SphinxMarkus Zapke-Gründemann
 
How to distribute Ruby to the world
How to distribute Ruby to the worldHow to distribute Ruby to the world
How to distribute Ruby to the worldHiroshi SHIBATA
 
How to discover the Ruby's defects with web application
How to discover the Ruby's defects with web applicationHow to discover the Ruby's defects with web application
How to discover the Ruby's defects with web applicationHiroshi SHIBATA
 
Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!Ivan Chernoff
 
CPANTS: Kwalitative website and its tools
CPANTS: Kwalitative website and its toolsCPANTS: Kwalitative website and its tools
CPANTS: Kwalitative website and its toolscharsbar
 
Modern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettextModern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettextAlexander Mostovenko
 

Ähnlich wie I18n share (20)

Easy contributable internationalization process with Sphinx @ PyCon APAC 2016
Easy contributable internationalization process with Sphinx @ PyCon APAC 2016Easy contributable internationalization process with Sphinx @ PyCon APAC 2016
Easy contributable internationalization process with Sphinx @ PyCon APAC 2016
 
Living in a multiligual world: Internationalization for Web 2.0 Applications
Living in a multiligual world: Internationalization for Web 2.0 ApplicationsLiving in a multiligual world: Internationalization for Web 2.0 Applications
Living in a multiligual world: Internationalization for Web 2.0 Applications
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCats
 
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
 
Easy contributable internationalization process with Sphinx @ pyconmy2015
Easy contributable internationalization process with Sphinx @ pyconmy2015Easy contributable internationalization process with Sphinx @ pyconmy2015
Easy contributable internationalization process with Sphinx @ pyconmy2015
 
Silme & compare-locales
Silme & compare-localesSilme & compare-locales
Silme & compare-locales
 
Easy contributable internationalization process with Sphinx @ pyconsg2015
Easy contributable internationalization process with Sphinx @ pyconsg2015Easy contributable internationalization process with Sphinx @ pyconsg2015
Easy contributable internationalization process with Sphinx @ pyconsg2015
 
Fullstack workshop
Fullstack workshopFullstack workshop
Fullstack workshop
 
I18n
I18nI18n
I18n
 
Writing multi-language documentation using Sphinx
Writing multi-language documentation using SphinxWriting multi-language documentation using Sphinx
Writing multi-language documentation using Sphinx
 
Kubernetes debug like a pro
Kubernetes debug like a proKubernetes debug like a pro
Kubernetes debug like a pro
 
How to distribute Ruby to the world
How to distribute Ruby to the worldHow to distribute Ruby to the world
How to distribute Ruby to the world
 
How to discover the Ruby's defects with web application
How to discover the Ruby's defects with web applicationHow to discover the Ruby's defects with web application
How to discover the Ruby's defects with web application
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!
 
CPANTS: Kwalitative website and its tools
CPANTS: Kwalitative website and its toolsCPANTS: Kwalitative website and its tools
CPANTS: Kwalitative website and its tools
 
Modern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettextModern javascript localization with c-3po and the good old gettext
Modern javascript localization with c-3po and the good old gettext
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Python+gradle
Python+gradlePython+gradle
Python+gradle
 
Rails i18n
Rails i18nRails i18n
Rails i18n
 

Kürzlich hochgeladen

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Kürzlich hochgeladen (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

I18n share

  • 1. i18n and L10n in Node.js Kai livdea.com
  • 2.
  • 3. • Resource file support • View template support • Language detection
  • 4. but we are greedy…. No using external resource, nor service Recently Update Documentation
  • 5. i18n-node • has all we need! • gets updated!! • is documented!!!!!!
  • 6. So…it’s like 我懂正體中文 我也說中文 {‘zh-tw’} {‘我也說中文’}
  • 7. Or…. mitä kuuluu How are you? {‘fi’} {‘How are you?’} Oops…..
  • 8. That’s it. Let’s do it. Build your own https://github.com/kaijan/nodejs-taiwan-i18n.git
  • 9. Installation and Configuration 1. Installation $: npm install i18n 2. Require var i18n = require("i18n"); 3. app.configure() app.use(i18n.init); //language detection 4. i18n configuration i18n.configure({ locales:['zh-tw','zh'] // prefered language, and resource file });
  • 10. Installation and Configuration 5. 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 directory where you execute your node server
  • 11. app.use(i18n.init)? Language detection Loot at http request headers request['headers']['accept-language'] zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4 would mean: "I prefer Chinese-Taiwan, but will accept United States English and other types of English." (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) guessLanguage(request)
  • 12. Easy to code Code in node.js console.log(i18n.__('HelloWorld')); console.log(i18n.__('HelloGroup', 'Node.js', 30)); Code in view (using Jade) div #{__i('HelloWorld')} div #{__i('HelloGroup', 'node.js', 30)}
  • 13. Hi, Taiwan We need zh-TW rather than zh(Chinese) in i18n.js, add the region detection request.language_region = request.language ; if (request.region){ request.language_region = request.language_region +'-'+ request.region; } i18n.setLocale(request, request.language_region);
  • 14. Hi, Mr. Trouble Can’t switch language? Because defaultLocale is changed, but we can fix it if (locales[target_locale]) { request.locale = target_locale; defaultLocale = target_locale; } else { defaultLocale = 'en'; request.locale = defaultLocale; }
  • 15.
  • 16. Built on Node.js, MongodDB, Nginx and EC2