[wp-hackers] _n javascript variant?

TV productions info at tv-productions.org
Wed Jul 16 15:32:23 UTC 2014

Hi there,

I have a custom post type with a custom edit post screen. On that 
screen, I've build an editor in javascript for this post type.
The point is, I've a label with the text "1 photo" or "2 photos". This 
label is initial set on the server side and the number of photos changes 
on the client side with javascript.

So on the server side I have this code:

printf(_n('%d photo', '%d photos', count($photos), 'textdomain'), 

And later on I change it with javascript. I currently use 
wp_localize_script with:

array ('photo' => __('photo', 'textdomain'),
'photos' => __('photos', 'textdomain')

And in javascript the next condition to choose one of the two:

if ($photos.length == 1) {
$label.text('1 ' + myL10n.photo);
} else {
$label.text($photos.lenght + ' ' + myL10n.photos);

This would output things like "0 photos", "1 photo" and "2 photos".
The point is that some languages don't have the same plural forms for 0 
and 2 OR that they have more than 1 plural form.

So does anyone know a workaround to get a correct translation, also in 
languages with more than 1 plural form?

I hope you have some suggestions guys!

Best Regards,

TV productions :: Web development and stuff

More information about the wp-hackers mailing list