Skip to content

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Aug 15, 2021

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #42480
License MIT
Doc PR symfony/symfony-docs#...

@carsonbot
Copy link

Hey!

I think @fancyweb has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@mboeck001
Copy link

Hi! There seems to be another problem with this fix, if there are manual or default fallbacks. I changed the routine at my place to this to fix it - the logic is to first take all computed fallbacks, and afterwards all fix coded fallbacks ...

` protected function computeFallbackLocales($locale)
{
if (null === $this->parentLocales) {
$this->parentLocales = json_decode(file_get_contents(DIR.'/Resources/data/parents.json'), true);
}

    $locales = [];
    // m.boeck: Fallback bug
    $localesManual = [];
    foreach ($this->fallbackLocales as $fallback) {
        if ($fallback === $locale) {
            continue;
        }

        // m.boeck: Fallback bug
        $localesManual[] = $fallback;
    }

    while ($locale) {
        $parent = $this->parentLocales[$locale] ?? null;

        if ($parent) {
            $locale = 'root' !== $parent ? $parent : null;
        } elseif (\function_exists('locale_parse')) {
            $localeSubTags = locale_parse($locale);
            $locale = null;
            if (1 < \count($localeSubTags)) {
                array_pop($localeSubTags);
                $locale = locale_compose($localeSubTags) ?: null;
            }
        } elseif ($i = strrpos($locale, '_') ?: strrpos($locale, '-')) {
            $locale = substr($locale, 0, $i);
        } else {
            $locale = null;
        }

        if (null !== $locale) {
            // m.boeck: wrong order in fallback - bug in symfony
            $locales[] = $locale;
        }
    }

    // m.boeck: fallback bug
    return array_unique(array_merge($locales, $localesManual));
}`

For testing there should be a testcase for manual set fallbacks ...

@ro0NL
Copy link
Contributor Author

ro0NL commented Aug 16, 2021

status: needs work

@ro0NL
Copy link
Contributor Author

ro0NL commented Aug 16, 2021

LGTM. Remaing failure seems random.

Status: needs review

@fabpot
Copy link
Member

fabpot commented Aug 26, 2021

Thank you @ro0NL.

@fabpot fabpot merged commit 409aff7 into symfony:4.4 Aug 26, 2021
@ro0NL ro0NL deleted the 42480 branch August 26, 2021 08:26
This was referenced Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants