eZLocale Class Reference
[Locale system]
Provides unified access to locale information and conversions.
More...
List of all members.
Detailed Description
Provides unified access to locale information and conversions.
The eZLocale class handles locale information and can format time, date, numbers and currency for correct display for a given locale. The locale conversion uses plain numerical values for dates, times, numbers and currency, if you want more elaborate conversions consider using the eZCurrency classes.
The first time a locale object is created (ie. eZLocale::instance() ) you must be sure to set a language using setLanguage before using any textual conversions.
Example:
include_once( 'lib/ezlocale/classes/ezlocale.php' );
$locale =& eZLocale::instance();
$locale->initPHP();
print( $locale->formatTime() . '<br>' );
print( $locale->formatDate() . '<br>' );
foreach ( $locale->weekDays() as $day )
{
print( $locale->shortDayName( $day ) . '<br>' );
}
Countries are specified by the ISO 3166 Country Code http://www.iso.ch/iso/en/prods-services/iso3166ma/index.html User-assigned code elements http://www.iso.ch/iso/en/prods-services/iso3166ma/04background-on-iso-3166/reserved-and-user-assigned-codes.html#userassigned
Language is specified by the ISO 639 Language Code http://www.w3.org/WAI/ER/IG/ert/iso639.htm
Currency/funds are specified by the ISO 4217 http://www.bsi-global.com/Technical+Information/Publications/_Publications/tig90.xalter
Discussion on Norwegian locales https://lister.ping.uio.no/pipermail/lister.ping.uio.no/i18n-nn/2002-April.txt http://www.sprakrad.no/oss.htm
The date and time formats are quite similar to the builting PHP date function, the main differences are those which returns textual representations of months and days. More info on the date function here: http://www.php.net/manual/en/function.date.php
The following characters are not recognized in the format string:
B - Swatch Internet time r - RFC 822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200" (added in PHP 4.0.4) S - English ordinal suffix for the day of the month, 2 characters; i.e. "st", "nd", "rd" or "th"
The following characters are recognized in the format string:
a - "am" or "pm" A - "AM" or "PM" d - day of the month, 2 digits with leading zeros; i.e. "01" to "31" D - day of the week, textual, 3 letters; e.g. "Fri" F - month, textual, long; e.g. "January" g - hour, 12-hour format without leading zeros; i.e. "1" to "12" G - hour, 24-hour format without leading zeros; i.e. "0" to "23" h - hour, 12-hour format; i.e. "01" to "12" H - hour, 24-hour format; i.e. "00" to "23" i - minutes; i.e. "00" to "59" I (capital i) - "1" if Daylight Savings Time, "0" otherwise. j - day of the month without leading zeros; i.e. "1" to "31" l (lowercase 'L') - day of the week, textual, long; e.g. "Friday" L - boolean for whether it is a leap year; i.e. "0" or "1" m - month; i.e. "01" to "12" M - month, textual, 3 letters; e.g. "Jan" n - month without leading zeros; i.e. "1" to "12" O - Difference to Greenwich time in hours; e.g. "+0200" s - seconds; i.e. "00" to "59" t - number of days in the given month; i.e. "28" to "31" T - Timezone setting of this machine; e.g. "EST" or "MDT" U - seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday) W - ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) Y - year, 4 digits; e.g. "1999" y - year, 2 digits; e.g. "99" z - day of the year; i.e. "0" to "365" Z - timezone offset in seconds (i.e. "-43200" to "43200"). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.
- See also:
-
eZLanguage
Definition at line ezlocale.php.
Constructor & Destructor Documentation
eZLocale::eZLocale |
( |
$ |
localeString |
) |
|
|
Member Function Documentation
|
Returns the charset for this locale. - Note:
-
It returns an empty string if no charset was set from the locale file.
Definition at line ezlocale.php.
Referenced by localeInformation(). |
eZLocale::countryCode |
( |
|
) |
|
|
eZLocale::countryComment |
( |
|
) |
|
|
|
Returns the comment for the country, if any.
Definition at line ezlocale.php. |
& eZLocale::countryFile |
( |
$ |
withVariation = false |
) |
|
|
eZLocale::countryList |
( |
|
) |
[static] |
|
|
- Returns:
-
a list of countries which was found in the system, the countries are in identifier form, for instance: NO, GB, US
Definition at line ezlocale.php.
References localeRegexp(). |
eZLocale::countryName |
( |
|
) |
|
|
|
Returns the name of the country in British English.
Definition at line ezlocale.php.
References Country. |
eZLocale::countryVariation |
( |
|
) |
|
|
eZLocale::currencyName |
( |
|
) |
|
|
|
Returns the name of the currency.
Definition at line ezlocale.php. |
eZLocale::currencyShortName |
( |
|
) |
|
|
|
Returns the short name of the currency.
Definition at line ezlocale.php. |
eZLocale::currencySymbol |
( |
|
) |
|
|
|
Returns the currency symbol for this locale.
Definition at line ezlocale.php. |
eZLocale::currentLocaleCode |
( |
|
) |
[static] |
|
|
Returns the current locale code for this language which is the language and the country with a dash (-) between them, for instance nor-NO or eng-GB. - See also:
-
localeCode, instance
Definition at line ezlocale.php.
References instance(). |
& eZLocale::formatCurrency |
( |
$ |
number, |
|
|
$ |
as_html = true |
|
) |
|
|
|
Formats the currency $number according to locale information and returns it. If $as_html is true all spaces are converted to before being returned.
Definition at line ezlocale.php. |
& eZLocale::formatDate |
( |
$ |
date = false |
) |
|
|
|
Formats the date $date according to locale information and returns it. If $date is not specified the current date is used.
Definition at line ezlocale.php.
References formatDateType(). |
& eZLocale::formatDateTime |
( |
$ |
date = false |
) |
|
|
|
Formats the date and time $date according to locale information and returns it. If $date is not specified the current date is used.
Definition at line ezlocale.php.
References formatDateTimeType(). |
& eZLocale::formatDateTimeType |
( |
$ |
fmt, |
|
|
$ |
datetime = false |
|
) |
|
|
& eZLocale::formatDateType |
( |
$ |
fmt, |
|
|
$ |
date = false |
|
) |
|
|
& eZLocale::formatNumber |
( |
$ |
number |
) |
|
|
|
Formats the number $number according to locale information and returns it.
Definition at line ezlocale.php. |
& eZLocale::formatShortDate |
( |
$ |
date = false |
) |
|
|
|
Formats the date $date according to locale information for short dates and returns it. If $date is not specified the current date is used.
Definition at line ezlocale.php.
References formatDateType(). |
& eZLocale::formatShortDateTime |
( |
$ |
date = false |
) |
|
|
|
Formats the date and time $date according to locale information for short dates and returns it. If $date is not specified the current date is used.
Definition at line ezlocale.php.
References formatDateTimeType(). |
& eZLocale::formatShortTime |
( |
$ |
time = false |
) |
|
|
|
Formats the time $time according to locale information for short times and returns it. If $time is not specified the current time is used.
Definition at line ezlocale.php.
References formatTimeType(). |
& eZLocale::formatTime |
( |
$ |
time = false |
) |
|
|
|
Formats the time $time according to locale information and returns it. If $time is not specified the current time is used.
Definition at line ezlocale.php.
References formatTimeType(). |
& eZLocale::formatTimeType |
( |
$ |
fmt, |
|
|
$ |
time = false |
|
) |
|
|
eZLocale::httpLocaleCode |
( |
|
) |
|
|
|
- Returns:
-
the locale code which can be set in either HTTP headers or the HTML file. The locale code is first check for in the RegionalSettings/HTTPLocale setting in site.ini, if that is empty it will use the value from localeCode().
- See also:
-
localeCode
Definition at line ezlocale.php.
References localeCode(). |
eZLocale::initPHP |
( |
$ |
charset = false |
) |
|
|
|
Sets locale information in PHP. This means that some of the string/sort functions in PHP will work with non-latin1 characters. Make sure setLanguage is called before this.
Definition at line ezlocale.php.
References charset(). |
& eZLocale::instance |
( |
$ |
localeString = false |
) |
|
|
|
Returns an unique instance of the locale class for a given locale string. If $localeString is not specified the default local string in site.ini is used. Use this instead of newing eZLocale to benefit from speed and unified access.
Definition at line ezlocale.php.
References eZINI::instance().
Referenced by eZContentObject::translationList(). |
eZLocale::internationalLanguageName |
( |
|
) |
|
|
eZLocale::isDebugEnabled |
( |
|
) |
[static] |
|
|
- Returns:
-
true if debugging of internals is enabled, this will display which files are loaded and when cache files are created. Set the option with setIsDebugEnabled().
Definition at line ezlocale.php.
Referenced by localeFile(). |
eZLocale::isMondayFirst |
( |
|
) |
|
|
|
- Returns:
-
true if the locale is valid, ie the locale file could be loaded.
Definition at line ezlocale.php. |
eZLocale::languageCode |
( |
|
) |
|
|
|
Returns the language code for this language, for instance nor for norwegian or eng for english.
Definition at line ezlocale.php.
References LanguageCode.
Referenced by localeFile(). |
eZLocale::languageComment |
( |
|
) |
|
|
|
Returns the comment for the language, if any.
Definition at line ezlocale.php. |
& eZLocale::languageFile |
( |
$ |
withVariation = false |
) |
|
|
eZLocale::languageList |
( |
|
) |
[static] |
|
|
- Returns:
-
a list of languages which was found in the system, the languages are in identifier form, for instance: nor, eng
Definition at line ezlocale.php.
References localeRegexp(). |
eZLocale::languageName |
( |
|
) |
|
|
|
Returns the locale code for this language which is the language and the country with a dash (-) between them, for instance nor-NO or eng-GB.
Definition at line ezlocale.php.
Referenced by httpLocaleCode(). |
& eZLocale::localeFile |
( |
$ |
withVariation = false |
) |
|
|
eZLocale::localeFullCode |
( |
|
) |
|
|
eZLocale::localeInformation |
( |
$ |
localeString |
) |
|
|
|
Decodes a locale string into language, country and charset and returns an array with the information. Country and charset is optional, country is specified with a - or _ followed by the country code (NO, GB), charset is specified with a . followed by the charset name. Examples of locale strings are: nor-NO, en_GB.utf8, nn_NO
Definition at line ezlocale.php.
References countryVariation().
Referenced by eZLocale(). |
eZLocale::localeList |
( |
$ |
asObject = false |
) |
[static] |
|
eZLocale::localeRegexp |
( |
|
) |
|
|
|
- Returns:
-
a regexp which can be used for locale matching. The following groups are defiend
- 1 - The language identifier
- 2 - The separator and the country (3)
- 3 - The country identifier
- 4 - The separator and the charset (5)
- 5 - The charset
- 6 - The separator and the variation (7)
- 7 - The variation
Definition at line ezlocale.php.
Referenced by localeList(). |
& eZLocale::longDayName |
( |
$ |
num |
) |
|
|
|
Returns the long name of the day number $num. The different numbers for the days are: Sunday = 0 Monday = 1 Tuesday = 2 Wednesday = 3 Thursday = 4 Friday = 5 Saturday = 6 This functions is usually used together with weekDays(). - See also:
-
shortDayName()
Definition at line ezlocale.php.
References DayNames.
Referenced by formatDateType(). |
& eZLocale::longMonthName |
( |
$ |
num |
) |
|
|
|
Returns the long name of the month number $num. The different numbers for the months are: Januray = 1 February = 2 March = 3 April = 4 May = 5 June = 6 July = 7 August = 8 September = 9 October = 10 November = 11 December = 12 This functions is usually used together with months(). - See also:
-
shortMonthName()
Definition at line ezlocale.php.
Referenced by formatDateType(). |
& eZLocale::meridiemName |
( |
$ |
time = false, |
|
|
$ |
upcase = false |
|
) |
|
|
|
Returns the name for the meridiem ie am (ante meridiem) or pm (post meridiem). If $time is not supplied or false the current time is used. If $upcase is false the name is in lowercase otherwise uppercase. The time is defined to be am if the hour is less than 12 and pm otherwise. Normally the hours 00 and 12 does not have am/pm attached and are instead called Midnight and Noon, but for simplicity the am/pm is always attached (if the locale allows it).
Definition at line ezlocale.php.
References PM.
Referenced by formatTimeType(). |
|
Returns the months of the year as an array. This only supplied for completeness. - See also:
-
weekDays()
Definition at line ezlocale.php. |
eZLocale::setIsDebugEnabled |
( |
$ |
debug |
) |
[static] |
|
|
Sets whether internal debugging is enabled or not.
Definition at line ezlocale.php. |
& eZLocale::shortDayName |
( |
$ |
num |
) |
|
|
|
Returns the short name of the day number $num. The different numbers for the days are: Sunday = 0 Monday = 1 Tuesday = 2 Wednesday = 3 Thursday = 4 Friday = 5 Saturday = 6 This functions is usually used together with weekDays(). - See also:
-
longDayName()
Definition at line ezlocale.php.
References DayNames. |
& eZLocale::shortMonthName |
( |
$ |
num |
) |
|
|
|
Returns the short name of the month number $num. The different numbers for the months are: Januray = 1 February = 2 March = 3 April = 4 May = 5 June = 6 July = 7 August = 8 September = 9 October = 10 November = 11 December = 12 This functions is usually used together with months(). - See also:
-
longMonthName()
Definition at line ezlocale.php.
Referenced by formatDateType(). |
eZLocale::weekDayNames |
( |
$ |
short = false |
) |
|
|
|
Returns the same array as in weekDays() but with all days translated to text.
Definition at line ezlocale.php. |
|
Returns an array with the days of the week according to locale information. Each entry in the array can be supplied to the longDayName() functions. - See also:
-
weekDayNames()
Definition at line ezlocale.php. |
The documentation for this class was generated from the following file:
|