Skip to content

Commit

Permalink
TASK: Adapt ViewHelper to support changes in Flow
Browse files Browse the repository at this point in the history
  • Loading branch information
dfeyer committed Jan 10, 2018
1 parent 86f365a commit ddf0b3f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions Neos.Neos/Classes/ViewHelpers/Backend/TranslateViewHelper.php
Expand Up @@ -87,28 +87,35 @@ class TranslateViewHelper extends FluidTranslateViewHelper
* @param string $source Name of file with translations
* @param string $package Target package key. If not set, the current package key will be used
* @param mixed $quantity A number to find plural form for (float or int), NULL to not use plural forms
* @param string $languageIdentifier An identifier of a language to use (NULL for using the default language)
* @param string $locale An identifier of a language to use (NULL for using the default language)
* @return string Translated label or source label / ID key
* @throws ViewHelper\Exception
*/
public function render($id = null, $value = null, array $arguments = array(), $source = 'Main', $package = null, $quantity = null, $languageIdentifier = null)
public function render()
{
$id = $this->arguments['id'];
$value = $this->arguments['value'];
$locale = $this->arguments['locale'];

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);
$this->arguments['id'] = $id;
$this->arguments['package'] = $package;
$this->arguments['source'] = str_replace('.', '/', $source);
}

if ($languageIdentifier === null) {
$languageIdentifier = $this->userService->getInterfaceLanguage();
if ($locale === null) {
$this->arguments['locale'] = $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);
$translation = parent::render();
// 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');
if ($translation === $id && $locale !== 'en') {
$this->arguments['locale'] = 'en';
$translation = parent::render();
}
return $translation;
} catch (Exception $exception) {
Expand Down

0 comments on commit ddf0b3f

Please sign in to comment.