nice ass
nice ass

Reputation: 16719

Multi-purpose function for gettext translations

It's similar to what Drupal has.

My current function definition is like this:

string t(string $singular, [string $plural, int $number, mixed $arg1, ...])

The order of the arguments doesn't have to follow this pattern. Only string $singular needs to be the first for obvious reasons.

Some examples to demonstrate how it works:

Do you have any suggestions on how could I better implement such functionality and avoid clashes like these?

Upvotes: 1

Views: 112

Answers (2)

Denis Chmel
Denis Chmel

Reputation: 789

I would use standard _() and ngettext() instead, because then you could get all localizible strings gathered via xgettext shell command. You could even use your own function names like t() and nt() and still extract them with xgettext (see --keyword param in https://developer.mozilla.org/en/gettext) but you can't (and shouldn't) avoid two functions.

Upvotes: 3

raPHPid
raPHPid

Reputation: 567

What about if you would have only 2 arguments, first one is a string and 2nd one is in simple cases int, but in complex cases it would be associative array like

array('plural_int' => 5, 'plural_str' => '%d apples', 'singular_int' => 10) 

or

array('singular_int' => array(10,20,30))

Upvotes: 2

Related Questions