Class WP_CLDR
Gives WordPress developers easy access to localized country, region, language, currency, and calendar info from the Unicode Common Locale Data Repository.
Examples:
The default locale is English:
$cldr = new WP_CLDR();
$territories_in_english = $cldr->get_territories();
You can override the default locale per-call by passing in a language slug in the second parameter:
$germany_in_arabic = $cldr->get_territory_name( 'DE' , 'ar_AR' );
Use a convenience parameter during instantiation to change the default locale:
$cldr = new WP_CLDR( 'fr' );
$germany_in_french = $cldr->get_territory_name( 'DE' );
$us_dollar_in_french = $cldr->get_currency_name( 'USD' );
$canadian_french_in_french = $cldr->get_language_name( 'fr-ca' );
$canadian_french_in_english = $cldr->get_language_name( 'fr-ca' , 'en' );
$german_in_german = $cldr->get_language_name( 'de_DE' , 'de-DE' );
$bengali_in_japanese = $cldr->get_language_name( 'bn_BD' , 'ja_JP' );
$us_dollar_symbol_in_simplified_chinese = $cldr->get_currency_symbol( 'USD', 'zh' );
$africa_in_french = $cldr->get_territory_name( '002' );
Switch locales after the object has been created:
$cldr->set_locale( 'en' );
$us_dollar_in_english = $cldr->get_currency_name( 'USD' );
Testing:
The class includes a suite of PHPUnit tests. To run them, call phpunit
from the plugin directory.
Link: http://cldr.unicode.org
Link: https://github.com/unicode-cldr/cldr-json
Autounit: wp-cldr
Located at
Methods summary
public
|
#
__construct( string $locale = 'en', boolean $use_cache = true )
Constructs a new instance of the class, including setting defaults for locale and caching. |
public
|
|
public static
string
|
|
public static
string
|
#
get_cldr_json_path( string $cldr_locale, string $bucket )
Gets the absolute path of a CLDR JSON file for a given WordPress locale and CLDR data item. |
public static
boolean
|
#
is_cldr_json_available( string $cldr_locale, string $bucket )
Checks to see if there is an installed CLDR JSON file for a given CLDR locale and data item. |
public static
array
|
|
public static
string
|
#
get_best_available_cldr_json_locale( string $locale, string $bucket )
Uses fallback logic to get the best available CLDR JSON locale for a given WordPress locale. |
public
|
#
flush_wp_cache_for_locale_bucket( string $locale, string $bucket )
Flushes the WordPress object cache for a single CLDR data item for a single locale. |
public
|
#
flush_all_wp_caches( )
Clears the WordPress object cache for all CLDR data items across all locales. |
public
string
|
#
get_territory_name( string $territory_code, string $locale = '' )
Gets a localized country or region name. |
public
string
|
#
get_currency_symbol( string $currency_code, string $locale = '' )
Gets a localized currency symbol. |
public
string
|
|
public
string
|
|
public
array
|
|
public
array
|
|
public
string
|
|
public
string
|
#
get_first_day_of_week( string $country_code )
Gets the day which typically starts a calendar week in a country. |
public
array
|
|
public
string
|
|
public
array
|
|
public
array
|
#
get_countries_for_currency( string $currency_code )
Gets the countries that use a particular currency. |
public
array
|
|
public
array
|
#
get_languages_spoken( string $country_code )
Gets the languages spoken in a country, in descending order of use. |
public
string
|
#
get_most_spoken_language( string $country_code )
Gets the most widely spoken language spoken in a country. |
public
array
|
#
get_territory_info( string $country_code )
Gets GDP, population, and language information for a country. |
public
array
|
#
get_time_zone_cities( string $locale = '' )
Gets the time zone city names -- aka exemplars -- for a locale. |
public
string
|
#
get_time_zone_city( string $time_zone_id, string $locale = '' )
Gets the time zone city name -- aka exemplar -- for a time zone ID. |
Constants summary
string |
CACHE_GROUP
The cache group name to use for the WordPress object cache. |
#
'wp-cldr'
|
string |
CLDR_VERSION
The CLDR version, which the class uses to determine path to JSON files. |
#
'29.0.0'
|