oscarotero/Gettext — pull request #17 by esnoeijs (2014-05-08 21:14:49+00:00)
Title: plural support

Hi,

I was looking for a gettext like implementation so I could get the familiarity of gettext without being stuck to the rigour of gettext and needing locale's and translation files on disk.

Your project more or less fit the bill for that with a couple of adjustments, one of which was support for the plural-forms. So I added some support for that. I ended up using create_function. The placement of which is not really ideal for performance reasons, But the static setup of everything more or less forced that.

I'm not really a big fan of the everything static approach, so I'll might actually end up rewriting a bunch to give it state, but since adding plural-forms is kind of a thing I figured I'd point out these changes in case you where interested.

Obviously with the use of create_function it also creates an exploit vector if the source file is untrusted. But for my current use I can always trust my input. For more generic stuff either a filter would need to be added, or perhaps better a full parser that reads the plural-forms line and translates it to php code. Thinking about it that might not be all that difficult to write, so I might do that next weekend or somewhere next week. Should be safer.

Also refactored the loading of translation array from always needing a file to loadTranslationsArray which just takes the array as an argument. This because I don't want to bother with files.

Anyway, just wanted to let you know.