laravel-translation icon indicating copy to clipboard operation
laravel-translation copied to clipboard

When I try to open any language to edit translations

Open soufiansaidi opened this issue 4 years ago • 5 comments

I did change to php 7.3 this problem appears each time i try to enter single language page to edit translation

// JoeDixon\Translation\Drivers\Translation::JoeDixon\Translation\Drivers{closure}(): Argument #2 ($key) must be passed by reference, value given

soufiansaidi avatar Jan 21 '21 20:01 soufiansaidi

This happens with PHP 8.0. (It did not happen with PHP7.4) This issue is caused with the following method getSourceLanguageTranslationsWith() in vendor/joedixon/laravel-translation/src/Drivers/Translation.php.

public function getSourceLanguageTranslationsWith($language)
{
        $sourceTranslations = $this->allTranslationsFor($this->sourceLanguage);
        $languageTranslations = $this->allTranslationsFor($language);

        return $sourceTranslations->map(function ($groups, $type) use ($language, $languageTranslations) {
            return $groups->map(function ($translations, $group) use ($type, $language, $languageTranslations) {
                $translations = $translations->toArray();
                array_walk($translations, function (&$value, &$key) use ($type, $group, $language, $languageTranslations) {
                    $value = [
                        $this->sourceLanguage => $value,
                        $language => $languageTranslations->get($type, collect())->get($group, collect())->get($key),
                    ];
                });

                return $translations;
            });
        });
}

Problem Area: function (&$value, &$key)

array_walk($translations, function (&$value, &$key) use ($type, $group, $language, $languageTranslations) {
       ......
});

How to Fix: Drop & from &$key. That will make it work.

public function getSourceLanguageTranslationsWith($language)
{
        $sourceTranslations = $this->allTranslationsFor($this->sourceLanguage);
        $languageTranslations = $this->allTranslationsFor($language);

        return $sourceTranslations->map(function ($groups, $type) use ($language, $languageTranslations) {
            return $groups->map(function ($translations, $group) use ($type, $language, $languageTranslations) {
                $translations = $translations->toArray();
                array_walk($translations, function (&$value, $key) use ($type, $group, $language, $languageTranslations) {
                    $value = [
                        $this->sourceLanguage => $value,
                        $language => $languageTranslations->get($type, collect())->get($group, collect())->get($key),
                    ];
                });

                return $translations;
            });
        });
}

ghost avatar Jan 25 '21 18:01 ghost

@howard-mintus thanks so much

pishguy avatar Feb 12 '21 19:02 pishguy

@joedixon is there a problem by don't using a reference variable here? I have the same problem

eduPHP avatar Jun 24 '21 20:06 eduPHP

Hi @joedixon it would be very helpful if this can be merged. Im having the same issue

Tharavink avatar Aug 25 '21 09:08 Tharavink

Had the same issue with in Laravel 9. The solution by @howard-mintus-zz worked. @joedixon please update it

Atif-Bashir-1998 avatar Aug 08 '22 05:08 Atif-Bashir-1998

@joedixon can you pls. merge this fix?

SalesFeed avatar Sep 20 '22 10:09 SalesFeed

Hi @SalesFeed, this is fixed in v2.

joedixon avatar Sep 20 '22 20:09 joedixon