Arbeiten mit I18n Platzhalter

die Platzhalter in dem Template werden mit i18n{} formatiert.

<b>i18n{i18n.spring.document.address}</b><br>
  eq{company::name}<br>
  eq{company::companyaddress1}<br>
  eq{company::companyzipcode} eq{company::companycity}<br>
  eq{company::i18n.companycountry.name}

mit der Klasse \Alvine\Application\I18n\TextFormatter wird der Text formatiert.

    $i18nPathList=[];
    $i18nPathList[] = '{CUSTOMISATIONPATH}resource/locale/{language}.properties';
    $i18nPathList[] = '{CUSTOMISATIONPATH}themes/enabled/spring/resource/locale/{language}.properties';

    $localeProperties = new \Alvine\Types\Properties();
    $language = \Alvine\Application\Assembly::getInstance()->getLocale()->getLanguage();
    foreach ($i18nPathList as $path) {
        $placeholder = new \Alvine\Types\Map();
        $placeholder->setValue('language', $language);
        $placeholder->append(\Alvine\Application\Assembly::getInstance()->getPlaceholderMap());
        $fileName = (new \Alvine\Text\MessageFormatter($placeholder))
             ->setMarker('{', '}')
             ->format($path);
        $file = new \Alvine\IO\File\File($fileName);
        $locale = new \Alvine\Types\Properties();
        $locale->load($file->getInputStream());

        $localeProperties->append($locale);
    }
    $i18nTextFormatter = new \Alvine\Application\I18n\TextFormatter(new \Alvine\I18n\PropertyText($localeProperties));
    $content=$i18nTextFormatter->format($content);

Wenn ein anderes Objekt die Daten für \Alvine\I18n\PropertyText geladen hat und es das \Alvine\Application\I18n\ResourceText Interface implementiert kann der I18n TextFormatter dieses Objekt für die Übersezung verwenden.


    $resourceTextImplementation = new class() extends \Alvine\Core\Alvine implements \Alvine\Application\I18n\ResourceText {

        protected ?\Alvine\I18n\PropertyText $resourceText = null;

        public function getText($text, $default = null, $pluralKey = null) {
            if ($default === null) $default = $text;
            if ($this->resourceText === null) return $default;
            $result = (new \Alvine\I18N\MessageArgumentFormatter($this->resourceText))->format($text, $pluralKey);
            if ($result === '') return $default;
            return $result;
        }
    }

    $i18nTextFormatter = new \Alvine\Application\I18n\TextFormatter(new \Alvine\I18n\PropertyText($localeProperties));
    $i18nTextFormatter->setResourceTextImplementation($resourceTextImplementation)