Skip to content

Commit edfa0b5

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
2 parents 05bbe66 + c27fb5d commit edfa0b5

File tree

7 files changed

+52
-2
lines changed

7 files changed

+52
-2
lines changed

system/Language/Language.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\Language;
1313

1414
use Config\Services;
15+
use InvalidArgumentException;
1516
use MessageFormatter;
1617

1718
/**
@@ -191,7 +192,14 @@ protected function formatMessage($message, array $args = [])
191192
return $message;
192193
}
193194

194-
return MessageFormatter::formatMessage($this->locale, $message, $args);
195+
$formatted = MessageFormatter::formatMessage($this->locale, $message, $args);
196+
if ($formatted === false) {
197+
throw new InvalidArgumentException(
198+
lang('Language.invalidMessageFormat', [$message, implode(',', $args)])
199+
);
200+
}
201+
202+
return $formatted;
195203
}
196204

197205
/**

system/Language/en/Language.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
// "Language" language settings
13+
return [
14+
'invalidMessageFormat' => 'Invalid message format: "{0}", args: "{1}"',
15+
];

tests/system/Language/LanguageTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use CodeIgniter\Test\CIUnitTestCase;
1515
use CodeIgniter\Test\Mock\MockLanguage;
1616
use Config\Services;
17+
use InvalidArgumentException;
1718
use MessageFormatter;
1819
use Tests\Support\Language\SecondMockLanguage;
1920

@@ -126,6 +127,30 @@ public function testGetLineArrayFormatsMessages(): void
126127
$this->assertSame(['45 related books.'], $this->lang->getLine('books.bookList', [91 / 2]));
127128
}
128129

130+
/**
131+
* @see https://github.com/codeigniter4/shield/issues/851
132+
*/
133+
public function testGetLineInvalidFormatMessage(): void
134+
{
135+
// No intl extension? then we can't test this - go away....
136+
if (! class_exists(MessageFormatter::class)) {
137+
$this->markTestSkipped('No intl support.');
138+
}
139+
140+
$this->expectException(InvalidArgumentException::class);
141+
$this->expectExceptionMessage(
142+
'Invalid message format: "تم الكشف عن كلمة المرور {0} بسبب اختراق البيانات وشوهدت {1 ، عدد} مرة في {2} في كلمات المرور المخترقة.", args: "password,hits,wording"'
143+
);
144+
145+
$this->lang->setLocale('ar');
146+
147+
$this->lang->setData('Auth', [
148+
'errorPasswordPwned' => 'تم الكشف عن كلمة المرور {0} بسبب اختراق البيانات وشوهدت {1 ، عدد} مرة في {2} في كلمات المرور المخترقة.',
149+
]);
150+
151+
$this->lang->getLine('Auth.errorPasswordPwned', ['password', 'hits', 'wording']);
152+
}
153+
129154
/**
130155
* @see https://github.com/codeigniter4/CodeIgniter4/issues/891
131156
*/

user_guide_src/source/changelogs/v4.4.2.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ BREAKING
1515
Message Changes
1616
***************
1717

18+
- Added ``Language.invalidMessageFormat`` error message.
19+
1820
Changes
1921
*******
2022

-7.54 KB
Loading
-4.92 KB
Loading

user_guide_src/source/tutorial/create_news_items.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Create a News Item
172172
******************
173173

174174
Now point your browser to your local development environment where you
175-
installed CodeIgniter and add **/news/create** to the URL.
175+
installed CodeIgniter and add **/news/new** to the URL.
176176
Add some news and check out the different pages you made.
177177

178178
.. image:: ../images/tutorial3.png

0 commit comments

Comments
 (0)