Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4101806
TimeUnits.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
TimeUnits.php
View Options
<?php
namespace
MediaWiki\Extension\CLDR
;
use
MediaWiki\MediaWikiServices
;
/**
* A class for querying translated time units from CLDR data.
*
* @author Niklas Laxström
* @author Ryan Kaldari
* @copyright Copyright © 2007-2013
* @license GPL-2.0-or-later
*/
class
TimeUnits
{
/** @var array */
private
static
$cache
=
[];
/**
* Get localized time units for a particular language, using fallback languages for missing
* items. The time units are returned as an associative array. The keys are of the form:
* <unit>-<tense>-<ordinality> (for example, 'hour-future-two'). The values include a placeholder
* for the number (for example, '{0} months ago').
*
* @param string $code The language to return the list in
* @return array an associative array of time unit codes and localized time units
*/
public
static
function
getUnits
(
$code
)
{
// Load time units localized for the requested language
$units
=
self
::
loadLanguage
(
$code
);
if
(
$units
)
{
return
$units
;
}
// Load missing time units from fallback languages
$fallbacks
=
MediaWikiServices
::
getInstance
()->
getLanguageFallback
()->
getAll
(
$code
);
foreach
(
$fallbacks
as
$fallback
)
{
if
(
$units
)
{
break
;
}
// Get time units from a fallback language
$units
=
self
::
loadLanguage
(
$fallback
);
}
return
$units
;
}
/**
* Load time units localized for a particular language. Helper function for getUnits.
*
* @param string $code The language to return the list in
* @return array an associative array of time unit codes and localized time units
*/
private
static
function
loadLanguage
(
$code
)
{
if
(
!
isset
(
self
::
$cache
[
$code
]
)
)
{
self
::
$cache
[
$code
]
=
[];
$langNameUtils
=
MediaWikiServices
::
getInstance
()->
getLanguageNameUtils
();
if
(
!
$langNameUtils
->
isValidBuiltInCode
(
$code
)
)
{
return
[];
}
/* Load override for wrong or missing entries in cldr */
$override
=
__DIR__
.
'/../LocalNames/'
.
$langNameUtils
->
getFileName
(
'LocalNames'
,
$code
);
if
(
file_exists
(
$override
)
)
{
$timeUnits
=
false
;
require
$override
;
// @phan-suppress-next-line PhanImpossibleCondition
if
(
is_array
(
$timeUnits
)
)
{
self
::
$cache
[
$code
]
=
$timeUnits
;
}
}
$filename
=
__DIR__
.
'/../CldrMain/'
.
$langNameUtils
->
getFileName
(
'CldrMain'
,
$code
);
if
(
file_exists
(
$filename
)
)
{
$timeUnits
=
false
;
require
$filename
;
// @phan-suppress-next-line PhanImpossibleCondition
if
(
is_array
(
$timeUnits
)
)
{
self
::
$cache
[
$code
]
+=
$timeUnits
;
}
}
else
{
wfDebug
(
__METHOD__
.
": Unable to load time units for $filename
\n
"
);
}
}
return
self
::
$cache
[
$code
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 17:07 (3 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c7/4a/11843b3cd0e3a80df6d5fc22aecf
Default Alt Text
TimeUnits.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment