Skip to content

Conversation

@esnoeijs
Copy link
Contributor

@esnoeijs esnoeijs commented May 8, 2014

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.

erik.snoeijs and others added 3 commits May 8, 2014 11:11
@oscarotero
Copy link
Member

Thank you for your great work.
The main reason of using static methods is because the use of static functions like __(). But I'm agree with you that it's not the best. Maybe a function to define the translator instance used by these functions should be fine. For example:

$translator = new Gettext\Translator();
$translator->loadTranslations('locales/en.php');
__setTranslator($translator);

//Now you can use the rest of the gettext functions:
__e('hello world');

What do you think about this?

oscarotero added a commit that referenced this pull request May 9, 2014
@oscarotero oscarotero merged commit cadd161 into php-gettext:master May 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants