Skip to content

Commit

Permalink
Fixes codeigniter4#2932 : Fix Translation key separated by dot
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed May 5, 2020
1 parent 65f0a0e commit 72e3e75
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions system/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ public function getLine(string $line, array $args = [])
}
}

if ($output === null)
{
unset($current);
foreach (explode('.', $parsedLine) as $row)
{
if (! isset($current))
{
$current = $this->language[$this->locale][$file] ?? null;
}

if (isset($current[$row][substr($parsedLine, strlen($row) + 1)]))
{
$output = $current[$row][substr($parsedLine, strlen($row) + 1)];
break;
}
}
}

if ($output === null && strpos($this->locale, '-'))
{
[$locale] = explode('-', $this->locale, 2);
Expand Down
3 changes: 3 additions & 0 deletions tests/_support/Language/en/Foo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
'bar' => 'Foo Bar Translated',
'bar.min_length1' => 'The {field} field is very short.',
'bar.min_length2' => 'Supplied value ({value}) for {field} must have at least {param} characters.',
'bar' => [
'min.length' => 'The {field} field is very short.',
],
];
9 changes: 9 additions & 0 deletions tests/system/Language/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,13 @@ public function testLanguageNestedArrayDefinition()
$this->assertEquals('e', $lang->getLine('Nested.a.b.c.d'));
}

public function testLanguageKeySeparatedByDot()
{
$lang = new SecondMockLanguage('en');
$lang->loadem('Foo', 'en');

$this->assertEquals('The fieldname field is very short.', $lang->getLine('Foo.bar.min_length1', ['field' => 'fieldname']));
$this->assertEquals('The fieldname field is very short.', $lang->getLine('Foo.bar.min.length', ['field' => 'fieldname']));
}

}

0 comments on commit 72e3e75

Please sign in to comment.