MediaWiki fundraising/REL1_35
CurrencyNames.php
Go to the documentation of this file.
1<?php
2
11class CurrencyNames extends CldrNames {
12
13 private static $cache = [];
14
22 public static function getNames( $code ) {
23 // Load currency names localized for the requested language
24 $names = self::loadLanguage( $code );
25
26 // Load missing currency names from fallback languages
27 $fallbacks = Language::getFallbacksFor( $code );
28 foreach ( $fallbacks as $fallback ) {
29 // Overwrite the things in fallback with what we have already
30 $names = array_merge( self::loadLanguage( $fallback ), $names );
31 }
32
33 return $names;
34 }
35
42 private static function loadLanguage( $code ) {
43 if ( !isset( self::$cache[$code] ) ) {
44 /* Load override for wrong or missing entries in cldr */
45 $override = __DIR__ . '/../LocalNames/' . self::getOverrideFileName( $code );
46 if ( Language::isValidBuiltInCode( $code ) && file_exists( $override ) ) {
47 $currencyNames = false;
48 require $override;
49 // @phan-suppress-next-line PhanImpossibleCondition
50 if ( is_array( $currencyNames ) ) {
51 self::$cache[$code] = $currencyNames;
52 }
53 }
54
55 $filename = __DIR__ . '/../CldrNames/' . self::getFileName( $code );
56 if ( Language::isValidBuiltInCode( $code ) && file_exists( $filename ) ) {
57 $currencyNames = false;
58 require $filename;
59 // @phan-suppress-next-line PhanImpossibleCondition
60 if ( is_array( $currencyNames ) ) {
61 if ( isset( self::$cache[$code] ) ) {
62 // Add to existing list of localized currency names
63 self::$cache[$code] = self::$cache[$code] + $currencyNames;
64 } else {
65 // No list exists, so create it
66 self::$cache[$code] = $currencyNames;
67 }
68 }
69 } else {
70 wfDebug( __METHOD__ . ": Unable to load currency names for $filename\n" );
71 }
72 }
73
74 return self::$cache[$code] ?? [];
75 }
76}
$currencyNames
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
$fallback
A base class for querying translated names from CLDR data.
Definition CldrNames.php:11
static getOverrideFileName( $code)
Get the name for the file that contains the local override data for a given language.
Definition CldrNames.php:27
static getFileName( $code)
Get the name for the file that contains the CLDR data for a given language.
Definition CldrNames.php:18
A class for querying translated currency names from CLDR data.
static getNames( $code)
Get localized currency names for a particular language, using fallback languages for missing items.
static loadLanguage( $code)
Load currency names localized for a particular language.