[wp-hackers] _n javascript variant?

J.D. Grimes jdg at codesymphony.co
Wed Jul 16 16:00:13 UTC 2014


I’d take a look at https://core.trac.wordpress.org/ticket/20491

-J.D.

On Jul 16, 2014, at 11:32 AM, TV productions <info at tv-productions.org> wrote:

> 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:
> 
> <?php
> printf(_n('%d photo', '%d photos', count($photos), 'textdomain'), count($photos));
> ?>
> 
> 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,
> Ties
> 
> -- 
> TV productions :: Web development and stuff
> http://tv-productions.org
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list