SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

En vedette

Daily Freeman digital initiatives 2012
Daily Freeman digital initiatives 2012Daily Freeman digital initiatives 2012
Daily Freeman digital initiatives 2012
Ivan Lajara
 
[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)
[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)
[고시]책임감리 현장참여자 업무지침서_개정_전문(최종)
보훈 현
 
Mount Soccer[1]
Mount Soccer[1]Mount Soccer[1]
Mount Soccer[1]
stack2k
 
資策會未來領袖卓越成長營
資策會未來領袖卓越成長營資策會未來領袖卓越成長營
資策會未來領袖卓越成長營
Shih Wu
 
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
drmccreedy
 
Journalism and social media
Journalism and social mediaJournalism and social media
Journalism and social media
Ivan Lajara
 
[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)
[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)
[고시]시공감리 현장참여자 업무지침서_개정_전문(최종)
보훈 현
 
2 humanreproductionsystem-130922023408-phpapp01
2 humanreproductionsystem-130922023408-phpapp012 humanreproductionsystem-130922023408-phpapp01
2 humanreproductionsystem-130922023408-phpapp01
Thusara Karunathilake
 
Digital initiatives
Digital initiativesDigital initiatives
Digital initiatives
Ivan Lajara
 

En vedette (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
 

Similaire à I18n share

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
 
Silme & compare-locales
Silme & compare-localesSilme & compare-locales
Silme & compare-locales
Adrianer
 
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
Hiroshi SHIBATA
 

Similaire à 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
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

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