Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F12661880
PhutilTranslation.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
PhutilTranslation.php
View Options
<?php
abstract
class
PhutilTranslation
extends
Phobject
{
/**
* Get the locale code which this class translates text for, like
* "en_GB".
*
* This should correspond to a valid subclass of @{class:PhutilLocale}.
*
* @return string Locale code for this translation.
*/
abstract
public
function
getLocaleCode
();
/**
* Return a map of all translations.
*
* @return map<string, wild> Map of raw strings to translations.
*/
abstract
protected
function
getTranslations
();
/**
* Return a filtered map of all strings in this translation.
*
* Filters out empty/placeholder translations.
*
* @return map<string, wild> Map of raw strings to translations.
*/
final
public
function
getFilteredTranslations
()
{
$translations
=
$this
->
getTranslations
();
foreach
(
$translations
as
$key
=>
$translation
)
{
if
(
$translation
===
null
)
{
unset
(
$translations
[
$key
]);
}
}
return
$translations
;
}
/**
* Load all available translation objects.
*
* @return list<PhutilTranslation> List of available translation sources.
*/
public
static
function
loadAllTranslations
()
{
return
id
(
new
PhutilClassMapQuery
())
->
setAncestorClass
(
__CLASS__
)
->
execute
();
}
/**
* Load the complete translation map for a locale.
*
* This will compile primary and fallback translations into a single
* translation map.
*
* @param string Locale code, like "en_US".
* @return map<string, wild> Map of all avialable translations.
*/
public
static
function
getTranslationMapForLocale
(
$locale_code
)
{
$locale
=
PhutilLocale
::
loadLocale
(
$locale_code
);
$translations
=
self
::
loadAllTranslations
();
$results
=
array
();
foreach
(
$translations
as
$translation
)
{
if
(
$translation
->
getLocaleCode
()
==
$locale_code
)
{
$results
+=
$translation
->
getFilteredTranslations
();
}
}
$fallback_code
=
$locale
->
getFallbackLocaleCode
();
if
(
$fallback_code
!==
null
)
{
$results
+=
self
::
getTranslationMapForLocale
(
$fallback_code
);
}
return
$results
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 28, 15:48 (10 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1078706
Default Alt Text
PhutilTranslation.php (2 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment