dachcom-digital / pimcore-i18n

Pimcore - i18n Manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XLIFF/Word Export failed

C-R-W opened this issue · comments

It seems that the complex language switcher breaks the xliff and word export functionality.
If i remove the code everything works as expected.

Is this a bug or do I have a wrong configuration?

hey @leo-chris. Funny, we just had the same issue some days ago. Currently there is no easy fix and i have to checkout how to manage the backend request in such cases. For now, you could do the same we did:

Twig Extension

<?php

namespace AppBundle\Twig\Extension;

use I18nBundle\Adapter\Context\Language;
use I18nBundle\Manager\ContextManager;
use Twig\Extension\AbstractExtension;

class LanguageExtension extends AbstractExtension
{
    protected $contextManager;

    public function __construct(ContextManager $contextManager)
    {
        $this->contextManager = $contextManager;
    }

    public function getFunctions()
    {
        return [
            new \Twig_Function('generate_language_list', [$this, 'generateList'])
        ];
    }

    public function generateList()
    {
        $context = null;

        try {
            $context = $this->contextManager->getContext();
        } catch (\Exception $e) {
            return [];
        }

        if (!$context instanceof Language) {
            return [];
        }

        try {
            $languages = $context->getActiveLanguages();
        } catch (\Exception $e) {
            return [];
        }

        if (!is_array($languages)) {
            return [];
        }

        return $languages;
    }
}

Usage

{% set active_languages = generate_language_list() %}
{% if active_languages|length > 0 %}
    <select>
        {% for language in active_languages %}
            <option {{ language.active ? 'selected' }} value="{{ language.linkedHref }}">{{ language.title }}</option>
        {% endfor %}
    </select>
{% endif %}

Hope this helps.

Hi,

thank you for your quick response.
Sadly we call other functions in our template ({{ i18n_context('getCountryNameByIsoCode', [ i18n_context('getCurrentCountryIso'), i18n_context('getCurrentLocale') ]) }}) so this solution is not going to work for us.

I know its messy but for now i managed it by returning null in the getI18Context function if Admin::getCurrentUser returns a user.

This has been fixed in 2.4.1 and 3.1.0.