SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Destacado

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
 

Destacado (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
 

Similar a 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
 

Similar a 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
 

Último

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Último (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

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