Problem

Calling the function locale_get_plural() with different language codes, will give you a notice and incorrect return values:

Reproduce:

locale_get_plural(3, 'nl');
locale_get_plural(3, 'fr');

Expected:
1
1

Actual:
1
Notice: Undefined index: nl in locale_get_plural() (regel 743 van modules\locale\locale.module).
-1

This because the check is on the static array, not its entries and isset should be used instead of (implicitly) converting to bool.

Proposed resolution

I will attach a patch in a comment.

Comments

fietserwin’s picture

Version: 7.x-dev » 8.x-dev
Status: Active » Needs review
Issue tags: +Needs tests, +Needs backport to D7
StatusFileSize
new1.11 KB

I guess that this bug needs a test as well. I'm not yet into the testing framework, but putting the above steps in a test method should probably suffice.

sun’s picture

Title: Notice: Undefined index: nl in locale_get_plural() (regel 743) » locale_get_plural() only works for a single language within a request
StatusFileSize
new558 bytes

What you want and meant is this.

sun’s picture

sun’s picture

Issue summary: View changes

added semicolons, changed 'en' into 'fr' as 'en' has its own problems