Comparing Javascript Libraries
Total Page:16
File Type:pdf, Size:1020Kb
www.XenCraft.com Comparing JavaScript Libraries Craig Cummings, Tex Texin October 27, 2015 Abstract Which JavaScript library is best for international deployment? This session presents the results of several years of investigation of features of JavaScript libraries and their suitability for international markets. We will show how the libraries were evaluated and compare the results for ECMA, Dojo, jQuery Globalize, Closure, iLib, ibm-js and intl.js. The results may surprise you and will be useful to anyone designing new international or multilingual JavaScript applications or supporting existing ones. 2 Agenda • Background • Evaluation Criteria • Libraries • Results • Q&A 3 Origins • Project to extend globalization - Complex e-Commerce Software - Multiple subsystems - Different development teams - Different libraries already in use • Should we standardize? Which one? - Reduce maintenance - Increase competence 4 Evaluation Criteria • Support for target and future markets • Number of internationalization features • Quality of internationalization features • Maintained? • Widely used? • Ease of migration from existing libraries • Browser compatibility 5 Internationalization Feature Requirements • Encoding Support • Text Support -Unicode -Case, Accent Mapping -Supplementary Chars -Boundary detection -Bidi algorithm, shaping -Character Properties -Transliteration -Charset detection • Message Formatting -Conversion -IDN/IRI -Resource/properties files -Normalization -Collation -Plurals, Gender, et al 6 Internationalization Feature Requirements (more) • Regular Expressions • Data formats -Date, time, calendar • Compression -Time zone -Number, Currency • Locales -Postal Address -Names (BCP 47) -Names, Honorifics -Negotiation -Phone numbers -Fallback -Detection • Measurement systems 7 Candidate Libraries AccDC MooTools Ample SDK PhoneJS CupQ Prototype DHTMLX Pyjamas Dojo qooxdoo Echo3 Rialto Toolkit Enyo Rico Ext JS SmartClient & SmartGWT Google Web Toolkit Wakanda i18next Web Atoms jQuery Webix Midori YUI MochiKit ZK8 I18n Libraries (general libraries left; messages-specific right) ECMA (402+262) jQuery.i18n (Wikimedia) Dojo L20n (Mozilla) jQuery Globalize FormatJS Closure iLib CLDRPluralRuleParser ibm-js I18Next intl-js messageformat.js l10n.js moment.js l10ns numeral.js browser-i18n date.js requirejs-i18n jQuery.now 9 The ECMA I18n Standard • Why not rely on the new standard? - ECMA-402 • 1st Edition released Dec, 2012 • 2nd Edition released Jun, 2015 - ECMA-262 (supplementary character support) • 6th Edition released Jun 2015 - More details at site of one of authors • http://norbertlindenberg.com/2013/10/javascript-internationalization/index.html 10 Desirable Features - Cross-browser compatibility – including Safari • Desktop, Mobile, Node.js, Older versions - Based on CLDR Locale Data - Based on ICU (see next slide) - Ease of data update and customization • Time zone data (Olson/IANA) • CLDR locale corrections and additions - Part of a larger (useful) JS platform - Well-performing (CPU, download size, disk, memory) 11 ICU Value (Skeleton Dates) DateFormat(DateFormat.FULL) SimpleDateFormat ICU Skeleton = JS Results English Wednesday, December 23, 2015 Wednesday December 23 2015Wednesday, December 23, 2015 French mercredi 23 décembre 2015 mercredi décembre 23 2015 mercredi 23 décembre 2015 German Mittwoch, 23. Dezember 2015 Mittwoch Dezember 23 2015 Mittwoch, 23. Dezember 2015 Spanish miércoles 23 de diciembre de 2015 miércoles diciembre 23 2015 miércoles, 23 de diciembre de 2015 Brazilian Portuguese Quarta-feira, 23 de Dezembro de 2015 quarta-feira dezembro 23 2015 quarta-feira, 23 de dezembro de 2015 Japanese 2015年12月23日 水曜日 12月 23 2015 2015年12月23日水曜日 Korean 2015년 12월 23일 수요일 수요일 12월 23 2015 2015년 12월 23일 수요일 Simplified Chinese 2015年12月23日 星期三 星期三 十二月 23 2015 2015年12月23日星期三 12 Scoping • Need to limit investigation • Writing tests and reviewing each feature for each library would take a large effort • Reduced list of libraries (sort of; see next bullet) - Already in use or strongly recommended - ECMA, Dojo, jQuery Globalize, iLib, Closure, ibm- js, intl.js (honorable mention to moment.js & numeral.js) • Plus a plethora of message formatting libs 13 Minimal Feature Requirements (Ideally in one library) • Encodings - Detection, Supplementary characters, Conversion • Locales: European and Asian Markets • Data Formats - Dates, times, numbers, currency - Localized Gregorian calendar • Message formatting, Externalized text • IDN, IRI 14 Updated Goals • Adequate i18n for foreseeable future • Meets minimal i18n requirements • Meets browser requirements • Acceptable to development teams • Part of a larger library • Easy to update data • Easy to migrate to 15 Example Challenge: Dates • 142 different date formats in use • 300+ different date formats in use • Unclear history or requirements for each format • Unclear how to internationalize some formats • Unclear whether to internationalize some formats - A little clearer as some of these derive from different databases, programming languages, and standards. - Still a mess! 16 js-i18n.com http://js-i18n.com 17 Passing Unit Tests Lib DFO DFO All DTF DTF All NF NF All Dojo 124/156 1883/2732 51/624 839/10928 38/39 587/683 Globalize 139 2577 89 1404 37 669 iLib 134 2378 0 0 39 660 Closure 151 2627 72 1235 39 682 ECMA 119 2179 232 1488 39 671 ibm-js 98 2179 168 1672 39 676 Intl.js 119 2179 232 1488 39 671 DFO = Date format only DTF = Date and time format NF = Number format 18 Measure by Caveats • iLib - Comes out-of-the-box with only 20 locales • Instructions about building more are hard to find • Dojo and ibm-js - 600+ additional locales can be built with relative ease. Tools and instructions available per readme files in package. - ibm-js readme lacks links to 2/3 require-related libraries • JQ on server/browser (not node.js) is painful. Even then needs tweaking to remove locales from jQuery require 19 Rafael Xavier Comparison Matrix (https://libraries.io/github/rxaviers/javascript-globalization) 20 Feature Comparison Eye Chart Feature iLib Closure Globalize Dojo ibm-js/Intl.js/ECMA Locale 683 682 683 683 683 CLDR Locale Data ✔ ✔ ✔ ✔ ✔ Date/Time ✔ ✔ ✔ ✔ ✔ Number/Currency/Percentage ✔ ✔ ✔ ✔ ✔ International Calendars ✔ ✔ ✔ ✔ Parsing ✔ partial ✔ Collation ✔ ✔ Bidi ✔ ✔ †iLib additionally has support for time zone, measurement, name, address and phone formats as well as resource files, Unicode normalization, case mapping, encoding conversion and more †† ECMA (and ibm-js & intl.js) has (have) extensive locale detection, negotiation, and fallback support ††† Notably still missing is support for boundary detection/wrapping, Unicode regex, and IDNs/IRIs 21 Message Library Comparison Lib Concat Gender Plural Ordinal Grammar Custom FormatJS ✔ ✔ ✔ ✔ ✔ JQ I18n ✔ ✔ ✔ ✔ L20N ✔ ✔ ✔ ✔ CldrPlural ✔ ✔ JQ Globalize ✔ ✔ ✔ Closure ✔ ✔ ✔ ✔ messageformat.js ✔ ✔ ✔ i18next ✔ ✔ ✔ l10ns ✔ ✔ ✔ ✔ browser-i18n ✔ ✔ iLib ✔ ✔ ✔ ECMA 22 Conclusion • Further investigation and recent changes indicate better i18n coverage in “basic” areas (a problem noted in the past) - Improvements on mobile • ECMA could use more consistent results across browsers • Extensive evaluation is nice to have; scoping to near- term needs is practical - Risks repeating and replacing library in the future 23 Resources • ECMA - ECMA-402 Edition 2 • http://www.ecma-international.org/ecma-402/2.0/ECMA-402.pdf - ECMA-262 Edition 6 (supplementary characters) • http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf - Mozilla Developer Network • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl 24 Resources (other libraries) Dojo https://dojotoolkit.org/ jQuery Globalize https://github.com/jquery/globalize iLib http://sourceforge.net/projects/i18nlib/ Closure https://github.com/google/closure-library ibm-js https://github.com/ibm-js/ecma402 Intl.js https://github.com/andyearnshaw/Intl.js/ 25 Questions? 26 Craig R. Cummings Principal Software Engineer – I18n, Informatica Craig has been working in the field of software globalization for over twenty years. Before his role at Informatica, Craig was at Zynga making games in a variety of languages including Arabic. Before that, at Yahoo! Inc., he helped drive corporate technical strategy for internationalization with a particular focus on Middle Eastern markets. Prior to that, Craig was with Oracle's Applications globalization team where he worked closely with Sun's internationalization team to shape some of the pluggable locale, resource bundle, font, and supplementary character support in Java. 27 Tex Texin Globalization Architect, XenCraft Tex Texin is an industry thought leader specializing in business and software globalization services. His expertise includes global product strategy, Unicode and internationalization architecture, and cost-effective implementation and testing. Over the past two decades, Tex has created numerous global products, led internationalization development teams, and guided companies in taking business to new regional markets. Tex is a contributor to several internationalization standards for software and on the Web. He is on the steering committees of open source products and the program committees for Unicode and other conferences. Tex is a popular speaker at conferences around the world and provides on-site training on Unicode, internationalization, and globalization worldwide. Tex maintains two Web sites for internationalization, the popular, instructional www.I18nGuy.com site and the site for his business www.XenCraft.com. Tex is founder and Chief Globalization Architect for XenCraft. XenCraft provides global business consulting and software design, implementation, test and training services on globalization product strategy and software internationalization architecture. 28.