public render ( string $id = null, string $value = null, array $arguments = [], string $source = 'Main', string $package = null, mixed $quantity = null, string $languageIdentifier = null ) : string | ||
$id | string | Id to use for finding translation (trans-unit id in XLIFF) |
$value | string | If $key is not specified or could not be resolved, this value is used. If this argument is not set, child nodes will be used to render the default |
$arguments | array | Numerically indexed array of values to be inserted into placeholders |
$source | string | Name of file with translations |
$package | string | Target package key. If not set, the current package key will be used |
$quantity | mixed | A number to find plural form for (float or int), NULL to not use plural forms |
$languageIdentifier | string | An identifier of a language to use (NULL for using the default language) |
return | string | Translated label or source label / ID key |
public function render($id = null, $value = null, array $arguments = array(), $source = 'Main', $package = null, $quantity = null, $languageIdentifier = null)
{
if (preg_match(TranslationHelper::I18N_LABEL_ID_PATTERN, $id) === 1) {
// In the longer run, this "extended ID" format should directly be resolved in the localization service
list($package, $source, $id) = explode(':', $id, 3);
$source = str_replace('.', '/', $source);
}
if ($languageIdentifier === null) {
$languageIdentifier = $this->userService->getInterfaceLanguage();
}
// Catch exception in case the translation file doesn't exist, should be fixed in Flow 3.1
try {
$translation = parent::render($id, $value, $arguments, $source, $package, $quantity, $languageIdentifier);
// Fallback to english label if label was not available in specific language
if ($translation === $id && $languageIdentifier !== 'en') {
$translation = parent::render($id, $value, $arguments, $source, $package, $quantity, 'en');
}
return $translation;
} catch (Exception $exception) {
return $value ?: $id;
}
}