Fixed JS plural function to be per app

Some apps might not define the same "nplural" value.
To avoid conflicts, the plural function is now generated per app.

Fixes #6427