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 6, 2020
1 parent 65f0a0e commit 72e03e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions system/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ public function getLine(string $line, array $args = [])
}
}

if ($output === null)
{
$row = current(explode('.', $parsedLine));
$key = substr($parsedLine, strlen($row) + 1);
$output = $this->language[$this->locale][$file][$row][$key] ?? null;
}

if ($output === null && strpos($this->locale, '-'))
{
[$locale] = explode('-', $this->locale, 2);
Expand Down
8 changes: 8 additions & 0 deletions tests/system/Language/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,12 @@ 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']));
}

}

0 comments on commit 72e03e7

Please sign in to comment.