mako-framework/framework

I18n::has returns undefined offset when testing a string without dot

Closed this issue · 3 comments

Type


  • Bug report
  • Feature request
  • RFC
  • Other

Description


The methods I18n::has and I18n::get return 'ErrorException: Undefined offset: 1' when a string without a . is given. For I18n::get this can be argued as intended use, however I18n::has is expected to return false.

For example, in a controller $this->i18n->has("foo bar"); triggers the ErrorException.

The cause of this error is calling parseKey in I18n::has without testing whether $key can be split. If $key cannot be split, then $string cannot exist, causing the ErrorException.

Versions & Platform


What Version
PHP Version 7.x.x
Mako Version 5.5.4
OS -
Database -

As addition, I18n::has also returns

(RuntimeException(code: 0): The [ /app/resources/i18n/nl_NL/strings/foo.php ] language file does not exist in the [ nl_NL ] language pack.

when using $this->i18n->has("foo. bar"). It is here too expected to return false.

Hi,

This has been fixed in 5.5.6.

The issue that I18n::has returns

(RuntimeException(code: 0): The [ /app/resources/i18n/nl_NL/strings/foo.php ] language file does not exist in the [ nl_NL ] language pack.

instead of false when using $this->i18n->has("foo.bar") is not fixed in the update. Is it possible for I18n::has to return false when the language file does not exist?