From 4ff44d141c6430ea200da10a521dcf14aebfd454 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 11 Jul 2021 00:40:30 +0200 Subject: [PATCH] Translator: Fix values handling when array keys are set Fixes #820 (Password recovery not working) --- src/Helpers/Translation/Translator.php | 2 +- tests/Unit/Helpers/Translation/TranslatorTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Helpers/Translation/Translator.php b/src/Helpers/Translation/Translator.php index 8b11ecb4..d42e4bcf 100644 --- a/src/Helpers/Translation/Translator.php +++ b/src/Helpers/Translation/Translator.php @@ -106,7 +106,7 @@ class Translator return $key; } - return call_user_func_array('sprintf', array_merge([$key], $replace)); + return call_user_func_array('sprintf', array_merge([$key], array_values($replace))); } /** diff --git a/tests/Unit/Helpers/Translation/TranslatorTest.php b/tests/Unit/Helpers/Translation/TranslatorTest.php index 5e341cfd..8c646850 100644 --- a/tests/Unit/Helpers/Translation/TranslatorTest.php +++ b/tests/Unit/Helpers/Translation/TranslatorTest.php @@ -128,8 +128,8 @@ class TranslatorTest extends ServiceProviderTest // Fallback translation $this->assertEquals('Lorem test2???', $translator->translate('foo.batz', ['test2'])); - // Successful translation - $this->assertEquals('Lorem test3!', $translator->translatePlural('foo.barf', 'foo.bar2', 3, ['test3'])); + // Successful translation, keys in replaces should be ignored + $this->assertEquals('Lorem test3!', $translator->translatePlural('foo.barf', 'foo.bar2', 3, ['x' => 'test3'])); } /**