Export 0.1.45
[framework/web/web-ui-fw.git] / libs / js / globalize / README.md
1 # Globalize
2
3 A JavaScript library for globalization and localization. Enables complex
4 culture-aware number and date parsing and formatting, including the raw
5 culture information for hundreds of different languages and countries, as well
6 as an extensible system for localization.
7
8 <hr>
9 <ul>
10 <li><a href="#why">Why Globalization</a></li>
11 <li><a href="#what">What is a Culture?</a></li>
12 <li><a href="#addCultureInfo">Globalize.addCultureInfo</a></li>
13 <li><a href="#cultures">Globalize.cultures</a></li>
14 <li><a href="#culture">Globalize.culture</a></li>
15 <li><a href="#find">Globalize.findClosestCulture</a></li>
16 <li><a href="#format">Globalize.format</a></li>
17 <li><a href="#localize">Globalize.localize</a></li>
18 <li><a href="#parseInt">Globalize.parseInt</a></li>
19 <li><a href="#parseFloat">Globalize.parseFloat</a></li>
20 <li><a href="#parseDate">Globalize.parseDate</a></li>
21 <li><a href="#extend">Utilizing and Extending Cultures</a></li>
22 <li><a href="#defining">Defining Culture Information</a></li>
23 <li><a href="#numbers">Number Formatting</a></li>
24 <li><a href="#dates">Date Formatting</a></li>
25 <li><a href="#generating">Generating Culture Files</a></li>
26 </ul>
27
28 <a name="why"></a>
29 <h2 id="why">Why Globalization?</h2>
30 <p>
31 Each language, and the countries that speak that language, have different
32 expectations when it comes to how numbers (including currency and percentages)
33 and dates should appear. Obviously, each language has different names for the
34 days of the week and the months of the year. But they also have different
35 expectations for the structure of dates, such as what order the day, month and
36 year are in. In number formatting, not only does the character used to
37 delineate number groupings and the decimal portion differ, but the placement of
38 those characters differ as well.
39 </p>
40 <p>
41 A user using an application should be able to read and write dates and numbers
42 in the format they are accustomed to. This library makes this possible,
43 providing an API to convert user-entered number and date strings - in their
44 own format - into actual numbers and dates, and conversely, to format numbers
45 and dates into that string format.
46 </p>
47
48 <a name="what"></a>
49 <h2 id="what">What is a Culture?</h2>
50 <p>
51 Globalize defines roughly 350 cultures. Part of the reason for this large
52 number, besides there being a lot of cultures in the world, is because for
53 some languages, expectations differ among the countries that speak it.
54 English, for example, is an official language in dozens of countries. Despite
55 the language being English, the expected date formatting still greatly differs
56 between them.
57 </p>
58 <p>
59 So, it does not seem useful to define cultures by their language alone. Nor
60 is it useful to define a culture by its country alone, as many countries have
61 several official languages, spoken by sizable populations. Therefore, cultures
62 are defined as a combination of the language and the country speaking it. Each
63 culture is given a unique code that is a combination of an ISO 639 two-letter
64 lowercase culture code for the language, and a two-letter uppercase code for
65 the country or region. For example, "en-US" is the culture code for English in
66 the United States.
67 </p>
68 <p>
69 Yet, it is perhaps unreasonable to expect application developers to cater to
70 every possible language/country combination perfectly. It is important then to
71 define so-called "neutral" cultures based on each language. These cultures
72 define the most likely accepted set of rules by anyone speaking that language,
73 whatever the country. Neutral cultures are defined only by their language code.
74 For example, "es" is the neutral culture for Spanish.
75 </p>
76
77 <a name="addCultureInfo"></a>
78 <h2 id="addCultureInfo">Globalize.addCultureInfo( cultureName, extendCultureName, info )</h2>
79 <p>
80 This method allows you to create a new culture based on an existing culture or
81 add to existing culture info. If the optional argument <pre>extendCultureName</pre>
82 is not supplied, it will extend the existing culture if it exists or create a new
83 culture based on the default culture if it doesn't exist. If cultureName is not
84 supplied, it will add the supplied info to the current culture. See .culture().
85 </p>
86
87
88 <a name="cultures"></a>
89 <h2 id="cultures">Globalize.cultures</h2>
90 <p>
91 A mapping of culture codes to culture objects. For example,
92 Globalize.cultures.fr is an object representing the complete culture
93 definition for the neutral French culture. Note that the main globalize.js file
94 alone only includes a neutral English culture. To get additional cultures, you
95 must include one or more of the culture scripts that come with it. You
96 can see in the section <a href="#defining">Defining Culture Information</a>
97 below which fields are defined in each culture.
98 </p>
99
100 <a name="culture"></a>
101 <h2 id="culture">Globalize.culture( selector )</h2>
102 <p>
103 An application that supports globalization and/or localization will need to
104 have a way to determine the user's preference. Attempting to automatically
105 determine the appropriate culture is useful, but it is good practice to always
106 offer the user a choice, by whatever means.
107 </p>
108 <p>
109 Whatever your mechanism, it is likely that you will have to correlate the
110 user's preferences with the list of cultures supported in the app. This
111 method allows you to select the best match given the culture scripts that you
112 have included and to set the Globalize culture to the culture which the user
113 prefers.
114 </p>
115 <p>
116 If you pass an array of names instead of a single name string, the first
117 culture for which there is a match (that culture's script has been referenced)
118 will be used. If none match, the search restarts using the corresponding
119 neutral cultures. For example, if the application has included only the neutral
120 "fr" culture, any of these would select it:
121 <pre>
122 Globalize.culture( "fr" );
123 console.log( Globalize.culture().name ) // "fr"
124
125 Globalize.culture( "fr-FR" );
126 console.log( Globalize.culture().name ) // "fr-FR"
127
128 Globalize.culture([ "es-MX", "fr-FR" ]);
129 console.log( Globalize.culture().name ) // "es-MX"
130 </pre>
131
132 In any case, if no match is found, the neutral English culture "en" is selected
133 by default.
134
135 If you don't pass a selector, .culture() will return the current Globalize
136 culture.
137 </p>
138 <p>
139 Each culture string may also follow the pattern defined in
140 <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4"
141 >RFC2616 sec 14.4</a>. That is, a culture name may include a "quality" value
142 that indicates an estimate of the user's preference for the language.
143
144 <pre>
145 Globalize.culture( "fr;q=0.4, es;q=0.5, he" );
146 </pre>
147 In this example, the neutral Hebrew culture "he" is given top priority (an
148 unspecified quality is equal to 1). If that language is not an exact match for
149 any of the cultures available in Globalize.cultures, then "es" is the next
150 highest priority with 0.5, etc. If none of these match, just like with the array
151 syntax, the search starts over and the same rules are applied to the
152 corresponding neutral language culture for each. If still none match, the
153 neutral English culture "en" is used.
154 </p>
155
156 <a name="find"></a>
157 <h2 id="find">Globalize.findClosestCulture( selector )</h2>
158 <p>
159 Just like .culture( selector ), but it just returns the matching culture, if
160 any, without setting it to the current Globalize culture, returned by
161 .culture().
162 </p>
163
164 <a name="format"></a>
165 <h2 id="format">Globalize.format( value, format, culture )</h2>
166 <p>
167 Formats a date or number according to the given format string and the given
168 culture (or the current culture if not specified). See the sections
169 <a href="#numbers">Number Formatting</a> and
170 <a href="#dates">Date Formatting</a> below for details on the available
171 formats.
172 <pre>
173 // assuming a culture with number grouping of 3 digits,
174 // using "," separator and "." decimal symbol.
175 Globalize.format( 1234.567, "n" ); // "1,234.57"
176 Globalize.format( 1234.567, "n1" ); // "1,234.6"
177 Globalize.format( 1234.567, "n0" ); // "1,235"
178
179 // assuming a culture with "/" as the date separator symbol
180 Globalize.format( new Date(1955,10,5), "yyyy/MM/dd" ); // "1955/11/05"
181 Globalize.format( new Date(1955,10,5), "dddd MMMM d, yyyy" ); // "Saturday November 5, 1955"
182 </pre>
183 </p>
184
185 <a name="localize"></a>
186 <h2 id="localize">Globalize.localize( key, culture )</h2>
187 <p>
188 Gets or sets a localized value. This method allows you to extend the
189 information available to a particular culture, and to easily retrieve it
190 without worrying about finding the most appropriate culture. For example, to
191 define the word "translate" in French:
192 <pre>
193 Globalize.addCultureInfo( "fr", {
194         messages: {
195                 "translate": "traduire"
196         }
197 });
198 console.log( Globalize.localize( "translate", "fr" ) ); // "traduire"
199 </pre>
200 Note that localize() will find the closest match available per the same
201 semantics as the Globalize.findClosestCulture() method. If there is no
202 match, the translation given is for the neutral English culture "en" by
203 default.
204 </p>
205
206
207 <a name="parseInt"></a>
208 <h2 id="parseInt">Globalize.parseInt( value, radix, culture )</h2>
209 <p>
210 Parses a string representing a whole number in the given radix (10 by default),
211 taking into account any formatting rules followed by the given culture (or the
212 current culture, if not specified).
213 <pre>
214 // assuming a culture where "," is the group separator
215 // and "." is the decimal separator
216 Globalize.parseInt( "1,234.56" ); // 1234
217 // assuming a culture where "." is the group separator
218 // and "," is the decimal separator
219 Globalize.parseInt( "1.234,56" ); // 1234
220 </pre>
221 </p>
222
223 <a name="parseFloat"></a>
224 <h2 id="parseFloat">Globalize.parseFloat( value, radix, culture )</h2>
225 <p>
226 Parses a string representing a floating point number in the given radix (10 by
227 default), taking into account any formatting rules followed by the given
228 culture (or the current culture, if not specified).
229 <pre>
230 // assuming a culture where "," is the group separator
231 // and "." is the decimal separator
232 Globalize.parseFloat( "1,234.56" ); // 1234.56
233 // assuming a culture where "." is the group separator
234 // and "," is the decimal separator
235 Globalize.parseFloat( "1.234,56" ); // 1234.56
236 </pre>
237 </p>
238
239 <a name="parseDate"></a>
240 <h2 id="parseDate">Globalize.parseDate( value, formats, culture )</h2>
241 <p>
242 Parses a string representing a date into a JavaScript Date object, taking into
243 account the given possible formats (or the given culture's set of default
244 formats if not given). As before, the current culture is used if one is not
245 specified.
246 <pre>
247 Globalize.culture( "en" );
248 Globalize.parseDate( "1/2/2003" ); // Thu Jan 02 2003
249 Globalize.culture( "fr" );
250 Globalize.parseDate( "1/2/2003" ); // Sat Feb 01 2003
251 </pre>
252 </p>
253
254 <a name="extend"></a>
255 <h2 id="extend">Utilizing and Extending Cultures</h2>
256 <p>
257 The culture information included with each culture is mostly necessary for the
258 parsing and formatting methods, but not all of it. For example, the Native and
259 English names for each culture is given, as well as a boolean indicating
260 whether the language is right-to-left. This may be useful information for your
261 own purposes. You may also add to the culture information directly if so
262 desired.
263 </p>
264 <p>
265 As an example, in the U.S., the word "billion" means the number 1,000,000,000
266 (9 zeros). But in other countries, that number is "1000 million" or a
267 "milliard", and a billion is 1,000,000,000,000 (12 zeros). If you needed to
268 provide functionality to your app or custom plugin that needed to know how many
269 zeros are in a "billion", you could extend the culture information as follows:
270 <pre>
271 // define additional culture information for a possibly existing culture
272 Globalize.addCultureInfo( "fr", {
273         numberFormat: {
274                 billionZeroes: 12
275         }
276 });
277 </pre>
278 Using this mechanism, the "fr" culture will be created if it does not exist.
279 And if it does, the given values will be added to it.
280 </p>
281
282 <a name="defining"></a>
283 <h2 id="defining">Defining Culture Information</h2>
284 <p>
285 Each culture is defined in its own script with the naming scheme
286 globalize.culture.&lt;name&gt;.js. You may include any number of these scripts,
287 making them available in the Globalize.cultures mapping. Including one of
288 these scripts does NOT automatically make it the current culture selected in the
289 Globalize.culture property.
290 </p>
291 <p>
292 The neutral English culture is defined directly in globalize.js, and set
293 both to the properties "en" and "default" of the Globalize.cultures mapping.
294 Extensive comments describe the purpose of each of the fields defined.
295 </p>
296 <p>
297 Looking at the source code of the scripts for each culture, you will notice
298 that each script uses Globalize.addCultureInfo() to have the "default" neutral
299 English culture "en", as a common basis, and defines only the properties that
300 differ from neutral English.
301 </p>
302 <p>
303 The neutral English culture is listed here along with the comments:
304 <pre>
305 Globalize.cultures[ "default" ] = {
306         // A unique name for the culture in the form
307         // &lt;language code&gt;-&lt;country/region code&gt;
308         name: "English",
309         // the name of the culture in the English language
310         englishName: "English",
311         // the name of the culture in its own language
312         nativeName: "English",
313         // whether the culture uses right-to-left text
314         isRTL: false,
315         // "language" is used for so-called "specific" cultures.
316         // For example, the culture "es-CL" means Spanish in Chili.
317         // It represents the Spanish-speaking culture as it is in Chili,
318         // which might have different formatting rules or even translations
319         // than Spanish in Spain. A "neutral" culture is one that is not
320         // specific to a region. For example, the culture "es" is the generic
321         // Spanish culture, which may be a more generalized version of the language
322         // that may or may not be what a specific culture expects.
323         // For a specific culture like "es-CL", the "language" field refers to the
324         // neutral, generic culture information for the language it is using.
325         // This is not always a simple matter of the string before the dash.
326         // For example, the "zh-Hans" culture is neutral (Simplified Chinese).
327         // And the "zh-SG" culture is Simplified Chinese in Singapore, whose
328         // language field is "zh-CHS", not "zh".
329         // This field should be used to navigate from a specific culture to its
330         // more general, neutral culture. If a culture is already as general as it
331         // can get, the language may refer to itself.
332         language: "en",
333         // "numberFormat" defines general number formatting rules, like the digits
334         // in each grouping, the group separator, and how negative numbers are
335         // displayed.
336         numberFormat: {
337                 // [negativePattern]
338                 // Note, numberFormat.pattern has no "positivePattern" unlike percent
339                 // and currency, but is still defined as an array for consistency with
340                 // them.
341                 //        negativePattern: one of "(n)|-n|- n|n-|n -"
342                 pattern: [ "-n" ],
343                 // number of decimal places normally shown
344                 decimals: 2,
345                 // string that separates number groups, as in 1,000,000
346                 ",": ",",
347                 // string that separates a number from the fractional portion,
348                 // as in 1.99
349                 ".": ".",
350                 // array of numbers indicating the size of each number group.
351                 groupSizes: [ 3 ],
352                 // symbol used for positive numbers
353                 "+": "+",
354                 // symbol used for negative numbers
355                 "-": "-",
356                 percent: {
357                         // [negativePattern, positivePattern]
358                         //         negativePattern: one of "-n %|-n%|-%n|%-n|%n-|n-%|n%-|-% n|n %-|% n-|% -n|n- %"
359                         //         positivePattern: one of "n %|n%|%n|% n"
360                         pattern: [ "-n %", "n %" ],
361                         // number of decimal places normally shown
362                         decimals: 2,
363                         // array of numbers indicating the size of each number group.
364                         groupSizes: [ 3 ],
365                         // string that separates number groups, as in 1,000,000
366                         ",": ",",
367                         // string that separates a number from the fractional portion, as in 1.99
368                         ".": ".",
369                         // symbol used to represent a percentage
370                         symbol: "%"
371                 },
372                 currency: {
373                         // [negativePattern, positivePattern]
374                         //         negativePattern: one of "($n)|-$n|$-n|$n-|(n$)|-n$|n-$|n$-|-n $|-$ n|n $-|$ n-|$ -n|n- $|($ n)|(n $)"
375                         //         positivePattern: one of "$n|n$|$ n|n $"
376                         pattern: [ "($n)", "$n" ],
377                         // number of decimal places normally shown
378                         decimals: 2,
379                         // array of numbers indicating the size of each number group.
380                         groupSizes: [ 3 ],
381                         // string that separates number groups, as in 1,000,000
382                         ",": ",",
383                         // string that separates a number from the fractional portion, as in 1.99
384                         ".": ".",
385                         // symbol used to represent currency
386                         symbol: "$"
387                 }
388         },
389         // "calendars" property defines all the possible calendars used by this
390         // culture. There should be at least one defined with name "standard" which
391         // is the default calendar used by the culture.
392         // A calendar contains information about how dates are formatted,
393         // information about the calendar's eras, a standard set of the date
394         // formats, translations for day and month names, and if the calendar is
395         // not based on the Gregorian calendar, conversion functions to and from
396         // the Gregorian calendar.
397         calendars: {
398                 standard: {
399                         // name that identifies the type of calendar this is
400                         name: "Gregorian_USEnglish",
401                         // separator of parts of a date (e.g. "/" in 11/05/1955)
402                         "/": "/",
403                         // separator of parts of a time (e.g. ":" in 05:44 PM)
404                         ":": ":",
405                         // the first day of the week (0 = Sunday, 1 = Monday, etc)
406                         firstDay: 0,
407                         days: {
408                                 // full day names
409                                 names: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
410                                 // abbreviated day names
411                                 namesAbbr: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
412                                 // shortest day names
413                                 namesShort: [ "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" ]
414                         },
415                         months: [
416                                 // full month names (13 months for lunar calendars -- 13th month should be "" if not lunar)
417                                 names: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "" ],
418                                 // abbreviated month names
419                                 namesAbbr: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "" ]
420                         ],
421                         // AM and PM designators in one of these forms:
422                         // The usual view, and the upper and lower case versions
423                         //              [standard,lowercase,uppercase]
424                         // The culture does not use AM or PM (likely all standard date
425                         // formats use 24 hour time)
426                         //              null
427                         AM: [ "AM", "am", "AM" ],
428                         PM: [ "PM", "pm", "PM" ],
429                         eras: [
430                                 // eras in reverse chronological order.
431                                 // name: the name of the era in this culture (e.g. A.D., C.E.)
432                                 // start: when the era starts in ticks, null if it is the
433                                 //                earliest supported era.
434                                 // offset: offset in years from gregorian calendar
435                                 {"name":"A.D.","start":null,"offset":0}
436                         ],
437                         // when a two digit year is given, it will never be parsed as a
438                         // four digit year greater than this year (in the appropriate era
439                         // for the culture)
440                         // Set it as a full year (e.g. 2029) or use an offset format
441                         // starting from the current year: "+19" would correspond to 2029
442                         // if the current year is 2010.
443                         twoDigitYearMax: 2029,
444                         // set of predefined date and time patterns used by the culture.
445                         // These represent the format someone in this culture would expect
446                         // to see given the portions of the date that are shown.
447                         patterns: {
448                                 // short date pattern
449                                 d: "M/d/yyyy",
450                                 // long date pattern
451                                 D: "dddd, MMMM dd, yyyy",
452                                 // short time pattern
453                                 t: "h:mm tt",
454                                 // long time pattern
455                                 T: "h:mm:ss tt",
456                                 // long date, short time pattern
457                                 f: "dddd, MMMM dd, yyyy h:mm tt",
458                                 // long date, long time pattern
459                                 F: "dddd, MMMM dd, yyyy h:mm:ss tt",
460                                 // month/day pattern
461                                 M: "MMMM dd",
462                                 // month/year pattern
463                                 Y: "yyyy MMMM",
464                                 // S is a sortable format that does not vary by culture
465                                 S: "yyyy\u0027-\u0027MM\u0027-\u0027dd\u0027T\u0027HH\u0027:\u0027mm\u0027:\u0027ss"
466                         }
467                         // optional fields for each calendar:
468                         /*
469                         monthsGenitive:
470                                 Same as months but used when the day preceeds the month.
471                                 Omit if the culture has no genitive distinction in month names.
472                                 For an explanation of genitive months, see
473                                 http://blogs.msdn.com/michkap/archive/2004/12/25/332259.aspx
474                         convert:
475                                 Allows for the support of non-gregorian based calendars. This
476                                 "convert" object defines two functions to convert a date to and
477                                 from a gregorian calendar date:
478                                         fromGregorian( date )
479                                                 Given the date as a parameter, return an array with
480                                                 parts [ year, month, day ] corresponding to the
481                                                 non-gregorian based year, month, and day for the
482                                                 calendar.
483                                         toGregorian( year, month, day )
484                                                 Given the non-gregorian year, month, and day, return a
485                                                 new Date() object set to the corresponding date in the
486                                                 gregorian calendar.
487                         */
488                 }
489         },
490         // Map of messages used by .localize()
491         messages: {}
492 }
493 </pre>
494 </p>
495 <p>
496 Each culture can have several possible calendars. The calendar named "standard"
497 is the default calendar used by that culture. You may change the calendar in
498 use by setting the "calendar" field. Take a look at the calendars defined by
499 each culture by looking at the script or enumerating its calendars collection.
500 <pre>
501 // switch to a non-standard calendar
502 Globalize.culture().calendar = Globalize.culture().calendars.SomeOtherCalendar;
503 // back to the standard calendar
504 Globalize.culture().calendar = Globalize.culture().calendars.standard;
505 </pre>
506
507 </p>
508
509 <a name="numbers"></a>
510 <h2 id="numbers">Number Formatting</h2>
511 <p>
512 When formatting a number with format(), the main purpose is to convert the
513 number into a human readable string using the culture's standard grouping and
514 decimal rules. The rules between cultures can vary a lot. For example, in some
515 cultures, the grouping of numbers is done unevenly. In the "te-IN" culture
516 (Telugu in India), groups have 3 digits and then 2 digits. The number 1000000
517 (one million) is written as "10,00,000". Some cultures do not group numbers at
518 all.
519 </p>
520 <p>
521 There are four main types of number formatting:
522 <ul>
523 <li><strong>n</strong> for number</li>
524 <li><strong>d</strong> for decimal digits</li>
525 <li><strong>p</strong> for percentage</li>
526 <li><strong>c</strong> for currency</li>
527 </ul>
528 Even within the same culture, the formatting rules can vary between these four
529 types of numbers. For example, the expected number of decimal places may differ
530 from the number format to the currency format. Each format token may also be
531 followed by a number. The number determines how many decimal places to display
532 for all the format types except decimal, for which it means the minimum number
533 of digits to display, zero padding it if necessary. Also note that the way
534 negative numbers are represented in each culture can vary, such as what the
535 negative sign is, and whether the negative sign appears before or after the
536 number. This is especially apparent with currency formatting, where many
537 cultures use parentheses instead of a negative sign.
538 <pre>
539 // just for example - will vary by culture
540 Globalize.format( 123.45, "n" ); // 123.45
541 Globalize.format( 123.45, "n0" ); // 123
542 Globalize.format( 123.45, "n1" ); // 123.5
543
544 Globalize.format( 123.45, "d" ); // 123
545 Globalize.format( 12, "d3" ); // 012
546
547 Globalize.format( 123.45, "c" ); // $123.45
548 Globalize.format( 123.45, "c0" ); // $123
549 Globalize.format( 123.45, "c1" ); // $123.5
550 Globalize.format( -123.45, "c" ); // ($123.45)
551
552 Globalize.format( 0.12345, "p" ); // 12.35 %
553 Globalize.format( 0.12345, "p0" ); // 12 %
554 Globalize.format( 0.12345, "p4" ); // 12.3450 %
555 </pre>
556 Parsing with parseInt and parseFloat also accepts any of these formats.
557 </p>
558
559 <a name="dates"></a>
560 <h2 id="dates">Date Formatting</h2>
561 <p>
562 Date formatting varies wildly by culture, not just in the spelling of month and
563 day names, and the date separator, but by the expected order of the various
564 date components, whether to use a 12 or 24 hour clock, and how months and days
565 are abbreviated. Many cultures even include "genitive" month names, which are
566 different from the typical names and are used only in certain cases.
567 </p>
568 <p>
569 Also, each culture has a set of "standard" or "typical" formats. For example,
570 in "en-US", when displaying a date in its fullest form, it looks like
571 "Saturday, November 05, 1955". Note the non-abbreviated day and month name, the
572 zero padded date, and four digit year. So, Globalize expects a certain set
573 of "standard" formatting strings for dates in the "patterns" property of the
574 "standard" calendar of each culture, that describe specific formats for the
575 culture. The third column shows example values in the neutral English culture
576 "en-US"; see the second table for the meaning tokens used in date formats.
577 <table>
578 <tr>
579   <th>Format</th>
580   <th>Meaning</th>
581   <th>"en-US"</th>
582 </tr>
583 <tr>
584    <td>f</td>
585    <td>Long Date, Short Time</td>
586    <td>dddd, MMMM dd, yyyy h:mm tt</td>
587 </tr>
588 <tr>
589    <td>F</td>
590    <td>Long Date, Long Time</td>
591    <td>dddd, MMMM dd, yyyy h:mm:ss tt</td>
592 </tr>
593 <tr>
594    <td>t</td>
595    <td>Short Time</td>
596    <td>h:mm tt</td>
597 </tr>
598 <tr>
599    <td>T</td>
600    <td>Long Time</td>
601    <td>h:mm:ss tt</td>
602 </tr>
603 <tr>
604    <td>d</td>
605    <td>Short Date</td>
606    <td>M/d/yyyy</td>
607 </tr>
608 <tr>
609    <td>D</td>
610    <td>Long Date</td>
611    <td>dddd, MMMM dd, yyyy</td>
612 </tr>
613 <tr>
614    <td>Y</td>
615    <td>Month/Year</td>
616    <td>MMMM, yyyy</td>
617 </tr>
618 <tr>
619    <td>M</td>
620    <td>Month/Day</td>
621    <td>yyyy MMMM</td>
622 </tr>
623 </table>
624 </p>
625 <p>
626 In addition to these standard formats, there is the "S" format. This is a
627 sortable format that is identical in every culture:
628 "<strong>yyyy'-'MM'-'dd'T'HH':'mm':'ss</strong>".
629 </p>
630 <p>
631 When more specific control is needed over the formatting, you may use any
632 format you wish by specifying the following custom tokens:
633 <table>
634 <tr>
635    <th>Token</th>
636    <th>Meaning</th>
637    <th>Example</th>
638 </tr>
639 <tr>
640    <td>d</td>
641    <td>Day of month (no leading zero)</td>
642    <td>5</td>
643 </tr>
644 <tr>
645    <td>dd</td>
646    <td>Day of month (leading zero)</td>
647    <td>05</td>
648 </tr>
649 <tr>
650    <td>ddd</td>
651    <td>Day name (abbreviated)</td>
652    <td>Sat</td>
653 </tr>
654 <tr>
655    <td>dddd</td>
656    <td>Day name (full)</td>
657    <td>Saturday</td>
658 </tr>
659 <tr>
660    <td>M</td>
661    <td>Month of year (no leading zero)</td>
662    <td>9</td>
663 </tr>
664 <tr>
665    <td>MM</td>
666    <td>Month of year (leading zero)</td>
667    <td>09</td>
668 </tr>
669 <tr>
670    <td>MMM</td>
671    <td>Month name (abbreviated)</td>
672    <td>Sept</td>
673 </tr>
674 <tr>
675    <td>MMMM</td>
676    <td>Month name (full)</td>
677    <td>September</td>
678 </tr>
679 <tr>
680    <td>yy</td>
681    <td>Year (two digits)</td>
682    <td>55</td>
683 </tr>
684 <tr>
685    <td>yyyy</td>
686    <td>Year (four digits)</td>
687    <td>1955</td>
688 </tr>
689 <tr>
690    <td>'literal'</td>
691    <td>Literal Text</td>
692    <td>'of the clock'</td>
693 </tr>
694 <tr>
695    <td>\'</td>
696    <td>Single Quote</td>
697    <td>'o'\''clock'</td><!-- o'clock -->
698 </tr>
699 <tr>
700    <td>m</td>
701    <td>Minutes (no leading zero)</td>
702    <td>9</td>
703 </tr>
704 <tr>
705    <td>mm</td>
706    <td>Minutes (leading zero)</td>
707    <td>09</td>
708 </tr>
709 <tr>
710    <td>h</td>
711    <td>Hours (12 hour time, no leading zero)</td>
712    <td>6</td>
713 </tr>
714 <tr>
715    <td>hh</td>
716    <td>Hours (12 hour time, leading zero)</td>
717    <td>06</td>
718 </tr>
719 <tr>
720    <td>H</td>
721    <td>Hours (24 hour time, no leading zero)</td>
722    <td>5 (5am) 15 (3pm)</td>
723 </tr>
724 <tr>
725    <td>HH</td>
726    <td>Hours (24 hour time, leading zero)</td>
727    <td>05 (5am) 15 (3pm)</td>
728 </tr>
729 <tr>
730    <td>s</td>
731    <td>Seconds (no leading zero)</td>
732    <td>9</td>
733 </tr>
734 <tr>
735    <td>ss</td>
736    <td>Seconds (leading zero)</td>
737    <td>09</td>
738 </tr>
739 <tr>
740    <td>f</td>
741    <td>Deciseconds</td>
742    <td>1</td>
743 </tr>
744 <tr>
745    <td>ff</td>
746    <td>Centiseconds</td>
747    <td>11</td>
748 </tr>
749 <tr>
750    <td>fff</td>
751    <td>Milliseconds</td>
752    <td>111</td>
753 </tr>
754 <tr>
755    <td>t</td>
756    <td>AM/PM indicator (first letter)</td>
757    <td>A or P</td>
758 </tr>
759 <tr>
760    <td>tt</td>
761    <td>AM/PM indicator (full)</td>
762    <td>AM or PM</td>
763 </tr>
764 <tr>
765    <td>z</td>
766    <td>Timezone offset (hours only, no leading zero)</td>
767    <td>-8</td>
768 </tr>
769 <tr>
770    <td>zz</td>
771    <td>Timezone offset (hours only, leading zero)</td>
772    <td>-08</td>
773 </tr>
774 <tr>
775    <td>zzz</td>
776    <td>Timezone offset (full hours/minutes)</td>
777    <td>-08:00</td>
778 </tr>
779 <tr>
780    <td>g or gg</td>
781    <td>Era name</td>
782    <td>A.D.</td>
783 </tr>
784 </table>
785 </p>
786
787 <a name="generating">
788 <h1 id="generating">Generating Culture Files</h1>
789
790 The Globalize culture files are generated JavaScript containing metadata and
791 functions based on culture info in the Microsoft .Net Framework 4.
792
793 <h2>Requirements</h2>
794
795 <ul>
796         <li>Windows</li>
797         <li>Microsoft .Net Framework 4 (Full, not just Client Profile) <a href="http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=0a391abd-25c1-4fc0-919f-b21f31ab88b7">download dotNetFx40_Full_x86_x64.exe</a></li>
798 </ul>
799
800 <h2>Building the generator</h2>
801
802 1. Open a Windows Command Prompt ( Start -> Run... -> cmd )
803 1. Change directory to root of Globalize project (where README.md file is located)
804 1. >"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild" generator\generator.csproj
805
806 <h2>Running the generator</h2>
807
808 1. Open a Windows Command Prompt
809 1. Change directory to root of Globalize project (where README.md file is located)
810 1. >"generator\bin\Debug\generator.exe"