Globalization is the process of designing and developing an
application that works in multiple cultures. The culture defines specific information
for the number formats, week and month names, date and time formats and etc.
Kendo exposes culture(cultureName) method which allows to select the culture
script corresponding to the "culture name". kendo.culture() method uses the passed culture name
to select a culture from the culture scripts that you have included and then sets the current culture. If there is no
corresponding culture then the method will try to find culture which is equal to the country part of the culture name.
If no culture is found the default one is used.
Define current culture settings
Include culture scripts and select culture
<script src="jquery.js" ></script>
<script src="kendo.all.min.js"></script>
<script src="kendo.culture.en-GB.js"></script>
<script type="text/javascript">
//set current culture to the "en-GB" culture script.
kendo.culture("en-GB");
</script>
Select closest culture
<script src="jquery.js" ></script>
<script src="kendo.all.min.js"></script>
<script src="kendo.culture.fr.js"></script>
<script type="text/javascript">
//set current culture to the "fr" culture script.
kendo.culture("fr-FR");
</script>
Get current culture
var cultureInfo = kendo.culture();
<h3>Find culture object</h3>
Kendo also exposes findCulture(cultureName) method which returns a culture object which corresponds to
the passed culture name. If there is no such culture in the registered culture scripts, the method will try to find a culture object
which corresponds to the country part of the culture name. If no culture is found, the result will be null.Find a culture object
<script src="jquery.js" ></script>
<script src="kendo.all.min.js"></script>
<script src="kendo.culture.fr.js"></script>
<script type="text/javascript">
//finds the "fr-FR" culture object.
var culture = kendo.findCulture("fr-FR");
</script>
Format number or date object
Kendo exposes methods which can format number or date object using specific format string and the current specified culture:kendo.toString(object, format)
- returns a string representation of the current object using specific format.
Formats number and date objects
//format number using standard number format
kendo.toString(10.12, "n"); //10.12
kendo.toString(10.12, "n0"); //10
kendo.toString(10.12, "n5"); //10.12000
kendo.toString(10.12, "c"); //$10.12
kendo.toString(0.12, "p"); //12.00 %
//format number using custom number format
kendo.toString(19.12, "00##"); //0019
//format date
kendo.toString(new Date(2010, 9, 5), "yyyy/MM/dd" ); // "2010/10/05"
kendo.toString(new Date(2010, 9, 5), "dddd MMMM d, yyyy" ); // "Tuesday October 5, 2010"
kendo.toString(new Date(2010, 10, 10, 22, 12), "hh:mm tt" ); // "10:12 PM"
kendo.format - replaces each format item in a specified string with the text equivalent of a corresponding object's value.
String format
kendo.format("{0} - {1}", 12, 24); //12 - 24
kendo.format("{0:c} - {1:c}", 12, 24); //$12.00 - $24.00
Parsing a string
Kendo exposes methods which converts the specified string to date or number object:
-
kendo.parseInt(string, [culture])
- converts a string to a whole number using the specified culture (current culture by default).Parse string to integer
//assumes that current culture defines decimal separator as "."
kendo.parseInt("12.22"); //12
//assumes that current culture defines decimal separator as ",", group separator as "." and currency symbol as "€"
kendo.parseInt("1.212,22 €"); //1212
</li>
<li>
<code>kendo.parseFloat(string, [culture])</code> - converts a string to a number with floating point using the specified culture (current culture by default).
Parse string to float
//assumes that current culture defines decimal separator as "."
kendo.parseFloat("12.22"); //12.22
//assumes that current culture defines decimal separator as ",", group separator as "." and currency symbol as "€"
kendo.parseFloat("1.212,22 €"); //1212.22
</li>
<li>
<code>kendo.parseDate(string, [formats], [culture])</code> - converts a string to a JavaScript Date object, taking into account the given format/formats (or the given culture's set of default formats).
Current culture is used if one is not specified.
Parse string to float
//current culture is "en-US"
kendo.parseDate("12/22/2000"); //Fri Dec 22 2000
kendo.parseDate("2000/12/22", "yyyy/MM/dd"); //Fri Dec 22 2000
</li>
</ol>
Number formatting
The purpose of number formatting is to convert Number object to a human readable string using culture's specific settings. kendo.format
and kendo.toString
methods support standard and custom numeric formats:
Standard numeric formats
n for numberFormatting using "n" format
kendo.culture("en-US");
kendo.toString(1234.567, "n"); //1,234.57
kendo.culture("de-DE");
kendo.toString(1234.567, "n3"); //1.234,567
c for currencyFormatting using "c" format
kendo.culture("en-US");
kendo.toString(1234.567, "c"); //$1,234.57
kendo.culture("de-DE");
kendo.toString(1234.567, "c3"); //1.234,567 €
p for percentage (number is multiplied by 100)Formatting using "p" format
kendo.culture("en-US");
kendo.toString(0.222, "p"); //22.20 %
kendo.culture("de-DE");
kendo.toString(0.22, "p3"); //22.000 %
e for exponentialFormatting using "e" format
kendo.toString(0.122, "e"); //1.22e-1
kendo.toString(0.122, "e4"); //1.2200e-1
Custom numeric formats
You can create custom numeric format string using one or more custom numeric specifiers. Custom numeric format string is any tha is not a standard numeric format.
Format specifiers
-
"0" - zero placeholder
- Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string -
kendo.toString(1234.5678, "00000") -> 01235
-
"#" - digit placeholder
- Replaces the pound sign with the corresponding digit if one is present; otherwise, no digit appears in the result string -
kendo.toString(1234.5678, "#####") -> 1235
-
"." - Decimal placeholder
- Determines the location of the decimal separator in the result string -
kendo.tostring(0.45678, "0.00") -> 0.46
(en-us)
-
"," - group separator placeholder
- Insert localized group separator between each group -
kendo.tostring(12345678, "##,#") -> 12,345,678
(en-us)
-
"%" - percentage placeholder
- Multiplies a number by 100 and inserts a localized percentage symbol in the result string
-
"e" - exponential notation
kendo.toString(0.45678, "e0") -> 5e-1
-
";" - section separator
- Defines sections wih separate format strings for positive, negative, and zero numbers
-
"string"/'string' - Literal string delimiter
- Indicates that the enclosed characters should be copied to the result string
Date formatting
The purpose of date formatting is to convert Date object to a human readable string using culture's specific settings. kendo.format
and kendo.toString
methods support standard and custom date formats:
Standard date formats
Format specifiers
-
"d" - short date pattern
kendo.toString(new Date(2000, 10, 6), "d") -> 11/6/2000
-
"D" - long date pattern
kendo.toString(new Date(2000, 10, 6), "D") -> Monday, November 06, 2000
-
"F" - Full date/time pattern
kendo.toString(new Date(2000, 10, 6), "D") -> Monday, November 06, 2000 12:00:00 AM
-
"g" - General date/time pattern (short time)
kendo.toString(new Date(2000, 10, 6), "g") -> 11/6/2000 12:00 AM
-
"G" - General date/time pattern (long time)
kendo.toString(new Date(2000, 10, 6), "G") -> 11/6/2000 12:00:00 AM
-
"M/m" - Month/day pattern
kendo.toString(new Date(2000, 10, 6), "m") -> November 06
-
"u" - Universal sortable date/time pattern
kendo.toString(new Date(2000, 10, 6), "u") -> 2000-11-06 00:00:00Z
-
"Y/y" - Year/month pattern
kendo.toString(new Date(2000, 10, 6), "y") -> November, 2000
Custom date formats
Format specifiers
-
"d"
- The day of the month, from 1 through 31
-
"dd"
- The day of the month, from 01 through 31.
-
"ddd"
- iThe abbreviated name of the day of the week
-
"dddd"
- The full name of the day of the week
-
"f"
- The tenths of a second in a date and time value
-
"ff"
- The hundredths of a second in a date and time value
-
"fff"
- The milliseconds in a date and time value
-
"M"
- The month, from 1 through 12
-
"MM"
- The month, from 01 through 12
-
"MMM"
- The abbreviated name of the month
-
"MMMM"
- The full name of the month
-
"h"
- The hour, using a 12-hour clock from 1 to 12
-
"hh"
- The hour, using a 12-hour clock from 01 to 12
-
"H"
- The hour, using a 24-hour clock from 1 to 23
-
"HH"
- The hour, using a 24-hour clock from 01 to 23
-
"m"
- The minute, from 0 through 59
-
"mm"
- The minute, from 00 through 59
-
"s"
- The second, from 0 through 59
-
"ss"
- The second, from 00 through 59
-
"tt"
- The AM/PM designator
Widgets that depend on current culture are:
- Calendar
- DatePicker
- TimePicker
- NumericTextBox