SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
4/30/2010                                  JavaScript Internationalization for effic…




   JavaScript Internationalization – the Good, the Bad, and the Ugly
   Internationalization Articles                                                                             March 27th, 2008

   Given JavaScript’s status as the de facto browser client scripting language, and given the international nature of the
   Internet, it was inevitable that JavaScript and internationalization (i18n) would eventually cross paths. At Lingoport,
   we see a good deal of JavaScript in our client’s code that we internationalize. While JavaScript is not completely
   without international capabilities and functionality, it does have its share of challenges and faults. This article briefly
   discusses some of what to expect of JavaScript in an international web application – what works (the good), what to
   watch out for (the bad), and what to avoid (the ugly).

   The Good – Unicode

   Probably the best news about JavaScript and i18n is that it supports Unicode. This means you should never have to
   worry about character corruption provided you take care to make sure that JavaScript is using it.

   If a JavaScript script block is embedded in an HTM L file, it will automatically assume the character encoding of the
   enclosing page. Thus, if you have defined your HTM L character set as UTF-8 you have done all you need to do. If
   your JavaScript is included as a separate .js file, you can add a charset attribute to your script tag to specify the
   character encoding of the included file. For example, a JavaScript file called functions.js that is encoded in UTF-8
   would be included like this:




   You can also include Unicode characters in any JavaScript regardless of encoding by defining the characters using
   Unicode escape definitions (u + 4 hexadecimal values that specify the Unicode character value in big-endian order).
   For example, you could define a string with a smiley face character like this:




   JavaScript is even smart enough to know the length of Unicode strings in terms of characters and not bytes. For
   example, smiley.length would return 1.

   The Bad – Strings

   One of the more annoying issues with JavaScript and i18n is dealing with embedded strings. As with any other
   programming language, embedded strings in an application’s code make it difficult if not impossible to localize.
   Unfortunately, JavaScript does not have the concept of a resource file, and strings that will be generated by
   JavaScript must be defined in the code.

   The easiest approach to deal with this issue is to define your JavaScript strings dynamically in server-side code
   (Java/JSP, ASPX, PHP, etc.). The following example defines some string resources in a JavaScript script block at the
   top of a JSP page:




lingoport.com/javascript-internationali…                                                                                         1/5
4/30/2010                                  JavaScript Internationalization for effic…




   Assuming the currentLocale object is set to English (US), the resulting block should look like this:




   When currentLocale is set to German (Germany) it should change to this:




   For French (France):




   You get the idea.

   There are a couple things to keep in mind with this approach. First, any strings that are embedded in the files,
   whether JSP/ASPX/PHP/etc. or JavaScript .js files, must be externalized, i.e. the strings should be moved into the
   string resource block as demonstrated below, and replaced in the code with their variable names. Second, the
   JavaScript string resource block should be defined before any other embedded blocks or .js file includes that make
   use of these externalized strings. For example, the resource block should be defined before the following function
   is called:




lingoport.com/javascript-internationali…                                                                                2/5
4/30/2010                                  JavaScript Internationalization for effic…




   Note that this simple example doesn’t deal with more sophisticated functionality such as locale fallback, but this
   basic approach solves the simpler string resource-related issues common in JavaScript.

   The Ugly – Language, Dates/Times

   When it comes to language, JavaScript knows enough to be dangerous. That is, it knows what the browser’s default
   language is (it’s defined in navigator.language for Netscape-descendent browsers such as Firefox and in
   navigator.browserLanguage for Internet Explorer). On my English (US) system these get reported as “en-us” or
   “en_US.” It is tempting to think that this information is a useful indication of the preferred language of the user, and
   in many cases it will be, but it doesn’t allow for the possibility of a user preferring a language other than the
   browser default.

   On a related note, there are a small number of “locale-specific” methods in JavaScript, which deal with the
   presentation of dates and times as strings, but these are always formatted in a single format for the browser’s
   default locale. This also applies to the ability to parse date and time strings; they will only be parsed correctly if the
   strings are formatted according to the conventions of the browser’s default locale.

   Although these provide some minimal language support, it is actually best to ignore these and instead rely on the
   server to provide this functionality as much as possible.

   With the advent of AJAX, a higher level of i18n functionality becomes possible because of the ability to interact with
   the server in a more seamless fashion. Using AJAX to achieve this higher functionality in JavaScript will be discussed
   in a future article.




            Resources
                  Internationalization Articles
                  Internationalization Newsletter
                  Internationalization Whitepapers
                  Videos
                  Webinars



   Subscribe
   Subscribe to our newsletter and white papers for free internationalization news, articles, and Webinar
   announcements sent via email.
   Click Here to Subscribe



lingoport.com/javascript-internationali…                                                                                        3/5
4/30/2010                                  JavaScript Internationalization for effic…

   Contact Us
         Phone: +1.303.444.8020
              Email: info@lingoport.com




lingoport.com/javascript-internationali…                                                4/5
4/30/2010                                  JavaScript Internationalization for effic…




lingoport.com/javascript-internationali…                                                5/5

Weitere ähnliche Inhalte

Andere mochten auch

Kitab mutammimah ajrumiyah
Kitab mutammimah ajrumiyahKitab mutammimah ajrumiyah
Kitab mutammimah ajrumiyahTobe Amisare
 
Internationalization Conference, Webinars, Events, Book Discount and More!
Internationalization Conference, Webinars, Events, Book Discount and More!Internationalization Conference, Webinars, Events, Book Discount and More!
Internationalization Conference, Webinars, Events, Book Discount and More!Lingoport (www.lingoport.com)
 
Saurabh Gupta Ctran Consulting Pvt. Ltd
Saurabh Gupta Ctran Consulting Pvt. LtdSaurabh Gupta Ctran Consulting Pvt. Ltd
Saurabh Gupta Ctran Consulting Pvt. LtdIIT Kharagpur
 
Project I Nt Upret V2
Project I Nt Upret   V2Project I Nt Upret   V2
Project I Nt Upret V2Ng
 

Andere mochten auch (7)

Keyboards and Internationalization
Keyboards and InternationalizationKeyboards and Internationalization
Keyboards and Internationalization
 
IPAD
IPADIPAD
IPAD
 
Kitab mutammimah ajrumiyah
Kitab mutammimah ajrumiyahKitab mutammimah ajrumiyah
Kitab mutammimah ajrumiyah
 
Internationalization Conference, Webinars, Events, Book Discount and More!
Internationalization Conference, Webinars, Events, Book Discount and More!Internationalization Conference, Webinars, Events, Book Discount and More!
Internationalization Conference, Webinars, Events, Book Discount and More!
 
Saurabh Gupta Ctran Consulting Pvt. Ltd
Saurabh Gupta Ctran Consulting Pvt. LtdSaurabh Gupta Ctran Consulting Pvt. Ltd
Saurabh Gupta Ctran Consulting Pvt. Ltd
 
Project I Nt Upret V2
Project I Nt Upret   V2Project I Nt Upret   V2
Project I Nt Upret V2
 
KPI und ROI
KPI und ROIKPI und ROI
KPI und ROI
 

Ähnlich wie JavaScript i18n - Good, Bad and Ugly

Java script Basic
Java script BasicJava script Basic
Java script BasicJaya Kumari
 
Unit 4 Java script.pptx
Unit 4 Java script.pptxUnit 4 Java script.pptx
Unit 4 Java script.pptxGangesh8
 
Internationalize your JavaScript Application: Prepare for "the next billion" ...
Internationalize your JavaScript Application: Prepare for "the next billion" ...Internationalize your JavaScript Application: Prepare for "the next billion" ...
Internationalize your JavaScript Application: Prepare for "the next billion" ...Kevin Hakanson
 
Apache Flex and the imperfect Web
Apache Flex and the imperfect WebApache Flex and the imperfect Web
Apache Flex and the imperfect Webmasuland
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scriptsch samaram
 
JavaScript & Enterprise BED-Con 2014 Berlin German
JavaScript & Enterprise BED-Con 2014 Berlin GermanJavaScript & Enterprise BED-Con 2014 Berlin German
JavaScript & Enterprise BED-Con 2014 Berlin GermanAdam Boczek
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothBhavsingh Maloth
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHBhavsingh Maloth
 
8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentationJohnLagman3
 
WEB MODULE 3.pdf
WEB MODULE 3.pdfWEB MODULE 3.pdf
WEB MODULE 3.pdfDeepika A B
 
Session vii(java scriptbasics)
Session vii(java scriptbasics)Session vii(java scriptbasics)
Session vii(java scriptbasics)Shrijan Tiwari
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | IntroductionJohnTaieb
 

Ähnlich wie JavaScript i18n - Good, Bad and Ugly (20)

Introduction to Java Scripting
Introduction to Java ScriptingIntroduction to Java Scripting
Introduction to Java Scripting
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Unit 4 Java script.pptx
Unit 4 Java script.pptxUnit 4 Java script.pptx
Unit 4 Java script.pptx
 
Internationalize your JavaScript Application: Prepare for "the next billion" ...
Internationalize your JavaScript Application: Prepare for "the next billion" ...Internationalize your JavaScript Application: Prepare for "the next billion" ...
Internationalize your JavaScript Application: Prepare for "the next billion" ...
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
 
Apache Flex and the imperfect Web
Apache Flex and the imperfect WebApache Flex and the imperfect Web
Apache Flex and the imperfect Web
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
 
emerging
emergingemerging
emerging
 
emerging
emergingemerging
emerging
 
JavaScript & Enterprise BED-Con 2014 Berlin German
JavaScript & Enterprise BED-Con 2014 Berlin GermanJavaScript & Enterprise BED-Con 2014 Berlin German
JavaScript & Enterprise BED-Con 2014 Berlin German
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh Maloth
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
 
8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation
 
WEB MODULE 3.pdf
WEB MODULE 3.pdfWEB MODULE 3.pdf
WEB MODULE 3.pdf
 
Session vii(java scriptbasics)
Session vii(java scriptbasics)Session vii(java scriptbasics)
Session vii(java scriptbasics)
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
 
WTA-MODULE-4.pptx
WTA-MODULE-4.pptxWTA-MODULE-4.pptx
WTA-MODULE-4.pptx
 
Analysis
AnalysisAnalysis
Analysis
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
 

Mehr von Lingoport (www.lingoport.com)

LocWorld: Building an Internationalization Plan; October 2011
LocWorld: Building an Internationalization Plan; October 2011LocWorld: Building an Internationalization Plan; October 2011
LocWorld: Building an Internationalization Plan; October 2011Lingoport (www.lingoport.com)
 
Leading Globalized Software Effort: An Expert Discussion
Leading Globalized Software Effort: An Expert DiscussionLeading Globalized Software Effort: An Expert Discussion
Leading Globalized Software Effort: An Expert DiscussionLingoport (www.lingoport.com)
 
Wordware 2011: Lingoport i18n Planning & Static Analysis
Wordware 2011: Lingoport i18n Planning & Static AnalysisWordware 2011: Lingoport i18n Planning & Static Analysis
Wordware 2011: Lingoport i18n Planning & Static AnalysisLingoport (www.lingoport.com)
 
Lingoport internationalization-i18n-and-localization-l10n-e newsletter-septem...
Lingoport internationalization-i18n-and-localization-l10n-e newsletter-septem...Lingoport internationalization-i18n-and-localization-l10n-e newsletter-septem...
Lingoport internationalization-i18n-and-localization-l10n-e newsletter-septem...Lingoport (www.lingoport.com)
 
Internationalization (i18n) Primer: Solving Coding Issues Equals Competitive ...
Internationalization (i18n) Primer: Solving Coding Issues Equals Competitive ...Internationalization (i18n) Primer: Solving Coding Issues Equals Competitive ...
Internationalization (i18n) Primer: Solving Coding Issues Equals Competitive ...Lingoport (www.lingoport.com)
 
Worldware: Software internationalization and globalization conference summary...
Worldware: Software internationalization and globalization conference summary...Worldware: Software internationalization and globalization conference summary...
Worldware: Software internationalization and globalization conference summary...Lingoport (www.lingoport.com)
 
Enhancing Internationalization Productivity: I18n Tools Support Software Loca...
Enhancing Internationalization Productivity: I18n Tools Support Software Loca...Enhancing Internationalization Productivity: I18n Tools Support Software Loca...
Enhancing Internationalization Productivity: I18n Tools Support Software Loca...Lingoport (www.lingoport.com)
 
Internationalization (I18n) and Localization (L10n): A Study
Internationalization (I18n) and Localization (L10n): A StudyInternationalization (I18n) and Localization (L10n): A Study
Internationalization (I18n) and Localization (L10n): A StudyLingoport (www.lingoport.com)
 
Business Perspectives on Internationalization (i18n)
Business Perspectives on Internationalization (i18n)Business Perspectives on Internationalization (i18n)
Business Perspectives on Internationalization (i18n)Lingoport (www.lingoport.com)
 
Internationalization (i18n) and Localization (l10n) - Partners in Successful ...
Internationalization (i18n) and Localization (l10n) - Partners in Successful ...Internationalization (i18n) and Localization (l10n) - Partners in Successful ...
Internationalization (i18n) and Localization (l10n) - Partners in Successful ...Lingoport (www.lingoport.com)
 

Mehr von Lingoport (www.lingoport.com) (19)

Staying Global in an Agile World Presentation
Staying Global in an Agile World PresentationStaying Global in an Agile World Presentation
Staying Global in an Agile World Presentation
 
Internationalizing a Multi-Layered Application
Internationalizing a Multi-Layered ApplicationInternationalizing a Multi-Layered Application
Internationalizing a Multi-Layered Application
 
Shifting Left Webinar Slideshow
Shifting Left Webinar SlideshowShifting Left Webinar Slideshow
Shifting Left Webinar Slideshow
 
Shifting Left Webinar Slides
Shifting Left Webinar SlidesShifting Left Webinar Slides
Shifting Left Webinar Slides
 
LocWorld: Building an Internationalization Plan; October 2011
LocWorld: Building an Internationalization Plan; October 2011LocWorld: Building an Internationalization Plan; October 2011
LocWorld: Building an Internationalization Plan; October 2011
 
Leading Globalized Software Effort: An Expert Discussion
Leading Globalized Software Effort: An Expert DiscussionLeading Globalized Software Effort: An Expert Discussion
Leading Globalized Software Effort: An Expert Discussion
 
Unicode Primer for the Uninitiated
Unicode Primer for the UninitiatedUnicode Primer for the Uninitiated
Unicode Primer for the Uninitiated
 
Static analysis for multiple programming languages
Static analysis for multiple programming languagesStatic analysis for multiple programming languages
Static analysis for multiple programming languages
 
Wordware 2011: Lingoport i18n Planning & Static Analysis
Wordware 2011: Lingoport i18n Planning & Static AnalysisWordware 2011: Lingoport i18n Planning & Static Analysis
Wordware 2011: Lingoport i18n Planning & Static Analysis
 
Lingoport internationalization-i18n-and-localization-l10n-e newsletter-septem...
Lingoport internationalization-i18n-and-localization-l10n-e newsletter-septem...Lingoport internationalization-i18n-and-localization-l10n-e newsletter-septem...
Lingoport internationalization-i18n-and-localization-l10n-e newsletter-septem...
 
Internationalization (i18n) Primer: Solving Coding Issues Equals Competitive ...
Internationalization (i18n) Primer: Solving Coding Issues Equals Competitive ...Internationalization (i18n) Primer: Solving Coding Issues Equals Competitive ...
Internationalization (i18n) Primer: Solving Coding Issues Equals Competitive ...
 
Introduction to Internationalization (I18n)
Introduction to Internationalization (I18n)Introduction to Internationalization (I18n)
Introduction to Internationalization (I18n)
 
Worldware: Software internationalization and globalization conference summary...
Worldware: Software internationalization and globalization conference summary...Worldware: Software internationalization and globalization conference summary...
Worldware: Software internationalization and globalization conference summary...
 
Enhancing Internationalization Productivity: I18n Tools Support Software Loca...
Enhancing Internationalization Productivity: I18n Tools Support Software Loca...Enhancing Internationalization Productivity: I18n Tools Support Software Loca...
Enhancing Internationalization Productivity: I18n Tools Support Software Loca...
 
Outsourcing Internationalization (i18n) Services
Outsourcing Internationalization (i18n) ServicesOutsourcing Internationalization (i18n) Services
Outsourcing Internationalization (i18n) Services
 
Internationalization (I18n) and Localization (L10n): A Study
Internationalization (I18n) and Localization (L10n): A StudyInternationalization (I18n) and Localization (L10n): A Study
Internationalization (I18n) and Localization (L10n): A Study
 
Business Perspectives on Internationalization (i18n)
Business Perspectives on Internationalization (i18n)Business Perspectives on Internationalization (i18n)
Business Perspectives on Internationalization (i18n)
 
Internationalization (i18n) Primer
Internationalization (i18n) PrimerInternationalization (i18n) Primer
Internationalization (i18n) Primer
 
Internationalization (i18n) and Localization (l10n) - Partners in Successful ...
Internationalization (i18n) and Localization (l10n) - Partners in Successful ...Internationalization (i18n) and Localization (l10n) - Partners in Successful ...
Internationalization (i18n) and Localization (l10n) - Partners in Successful ...
 

Kürzlich hochgeladen

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Kürzlich hochgeladen (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

JavaScript i18n - Good, Bad and Ugly

  • 1. 4/30/2010 JavaScript Internationalization for effic… JavaScript Internationalization – the Good, the Bad, and the Ugly Internationalization Articles March 27th, 2008 Given JavaScript’s status as the de facto browser client scripting language, and given the international nature of the Internet, it was inevitable that JavaScript and internationalization (i18n) would eventually cross paths. At Lingoport, we see a good deal of JavaScript in our client’s code that we internationalize. While JavaScript is not completely without international capabilities and functionality, it does have its share of challenges and faults. This article briefly discusses some of what to expect of JavaScript in an international web application – what works (the good), what to watch out for (the bad), and what to avoid (the ugly). The Good – Unicode Probably the best news about JavaScript and i18n is that it supports Unicode. This means you should never have to worry about character corruption provided you take care to make sure that JavaScript is using it. If a JavaScript script block is embedded in an HTM L file, it will automatically assume the character encoding of the enclosing page. Thus, if you have defined your HTM L character set as UTF-8 you have done all you need to do. If your JavaScript is included as a separate .js file, you can add a charset attribute to your script tag to specify the character encoding of the included file. For example, a JavaScript file called functions.js that is encoded in UTF-8 would be included like this: You can also include Unicode characters in any JavaScript regardless of encoding by defining the characters using Unicode escape definitions (u + 4 hexadecimal values that specify the Unicode character value in big-endian order). For example, you could define a string with a smiley face character like this: JavaScript is even smart enough to know the length of Unicode strings in terms of characters and not bytes. For example, smiley.length would return 1. The Bad – Strings One of the more annoying issues with JavaScript and i18n is dealing with embedded strings. As with any other programming language, embedded strings in an application’s code make it difficult if not impossible to localize. Unfortunately, JavaScript does not have the concept of a resource file, and strings that will be generated by JavaScript must be defined in the code. The easiest approach to deal with this issue is to define your JavaScript strings dynamically in server-side code (Java/JSP, ASPX, PHP, etc.). The following example defines some string resources in a JavaScript script block at the top of a JSP page: lingoport.com/javascript-internationali… 1/5
  • 2. 4/30/2010 JavaScript Internationalization for effic… Assuming the currentLocale object is set to English (US), the resulting block should look like this: When currentLocale is set to German (Germany) it should change to this: For French (France): You get the idea. There are a couple things to keep in mind with this approach. First, any strings that are embedded in the files, whether JSP/ASPX/PHP/etc. or JavaScript .js files, must be externalized, i.e. the strings should be moved into the string resource block as demonstrated below, and replaced in the code with their variable names. Second, the JavaScript string resource block should be defined before any other embedded blocks or .js file includes that make use of these externalized strings. For example, the resource block should be defined before the following function is called: lingoport.com/javascript-internationali… 2/5
  • 3. 4/30/2010 JavaScript Internationalization for effic… Note that this simple example doesn’t deal with more sophisticated functionality such as locale fallback, but this basic approach solves the simpler string resource-related issues common in JavaScript. The Ugly – Language, Dates/Times When it comes to language, JavaScript knows enough to be dangerous. That is, it knows what the browser’s default language is (it’s defined in navigator.language for Netscape-descendent browsers such as Firefox and in navigator.browserLanguage for Internet Explorer). On my English (US) system these get reported as “en-us” or “en_US.” It is tempting to think that this information is a useful indication of the preferred language of the user, and in many cases it will be, but it doesn’t allow for the possibility of a user preferring a language other than the browser default. On a related note, there are a small number of “locale-specific” methods in JavaScript, which deal with the presentation of dates and times as strings, but these are always formatted in a single format for the browser’s default locale. This also applies to the ability to parse date and time strings; they will only be parsed correctly if the strings are formatted according to the conventions of the browser’s default locale. Although these provide some minimal language support, it is actually best to ignore these and instead rely on the server to provide this functionality as much as possible. With the advent of AJAX, a higher level of i18n functionality becomes possible because of the ability to interact with the server in a more seamless fashion. Using AJAX to achieve this higher functionality in JavaScript will be discussed in a future article. Resources Internationalization Articles Internationalization Newsletter Internationalization Whitepapers Videos Webinars Subscribe Subscribe to our newsletter and white papers for free internationalization news, articles, and Webinar announcements sent via email. Click Here to Subscribe lingoport.com/javascript-internationali… 3/5
  • 4. 4/30/2010 JavaScript Internationalization for effic… Contact Us Phone: +1.303.444.8020 Email: info@lingoport.com lingoport.com/javascript-internationali… 4/5
  • 5. 4/30/2010 JavaScript Internationalization for effic… lingoport.com/javascript-internationali… 5/5