Sample code from Going Global with JavaScript and Globalize.js

This page contains code samples that you may find useful as building blocks or as starting points. Some codes are more complete than in the book, with minimal markup added to make the sample a complete HTML document.

The links refer to HTML or JavaScript (JS) files, as indicated before each link. In commonly used browsers, you can right-click on a link and then select “Save as File” or equivalent. A ZIP file of all code samples and related files may be downloaded here

The HTML markup used is largely minimized HTML5 markup in HTML serialization. It may require syntactic modifications when used within HTML 4.01 or XHTML markup. If you have questions, you may contact me at

Part I: Globalization, Localization, and JavaScript
Format File name Description
HTML dateoutput.html Date formatting (with Globalize; p. 21)
HTML dateinput.html Date input (conditionally using <input type=date>)
JS $G1.js $G, general localizer function (simple version)
HTMLonelang.html Simple localization for one language (strings and numbers)
HTML timeformatter.html Time format changer (p. 39)
HTML localeplanet.html LocalePlanet demo
HTML dojo.html Dojo demo
Part II: Going Global with Globalize
Format File name Description
HTML locales.html Locales
JS iso8601.js Formatting a date by ISO 8601 (standalone function)
HTML dateformats.html A date and time in four formats
HTML internet.html Internet date format using Globalize
JS arabicdates.js Writing dates in Arabic formats
JS msecs.js Writing time as localized, down to milliseconds
JS multiread.js Reading a date allowing different notations
HTML numberdemo.html Number formatting (with Globalize)
JS scientific.js Writing a number in scientific notation
JS engineering.js Writing a number in engineering notation
HTML arabicdigits.html Arabic digits demo
HTML mformat.html Reading a date in 'M' format
HTML fi-se.html Definition of a new locale (fi-SE)
HTML minus.html Setting minus sign to real (Unicode) minus (p. 95)
HTML colors.html Color name localization
JS $G.js $G, general localizer function, extended version
HTML $Gdemo.html A demo of an error handler using the extended $G
HTML search.html Flight search form
HTML search2.html Flight search form with some French localization
JS language.js Determining environment (browser or system) language
Part III: Managing Languages, Cultures and Characters
Format File name Description
HTML switcher.html Simple language switcher
JS lang.js Determining document language
JS setlang.js Setting document language
HTML plus1.html +1 demo
HTML map.html Map demo, with localized User Interface, p. 123
HTML hyphenation.html Hyphenation demo, using hyphenate.js
HTML dir.html Directionality demo
HTML q.html Quotation demo
HTML trans.html Simple translation demo
HTML transinput.html Translation of user input
HTML ligature.html Ligatures (change character combinations to ligatures)
HTML measures.html Measurement system demo
HTML phone.html Phone number input demo
HTML ssn.html SSN (social security number) input demo
HTML postal.html Postal address demo
HTML colorinput.html Color input
HTML list.html List formatting demo
HTML geolocation.html Geolocation demo
HTML minus-notations.html Minus sign in different notations
HTML turkish-input.html Turkish input widget
JS checkname.js A checkName function for Ascii names
JS ud.js UnicodeDate parsing
JS alphabetic.js Comparison via case folding
JS german.js Comparison for German
JS error.js Localized general error handling