• Hi,

    I’m one of the translation editors for Swedish and today, when I checked some pending translations for your plugin, I noted that your code is written in a way that in some cases makes it hard to translate.

    There may be more examples, but the place that caught my eye was in https://plugins.trac.www.ads-software.com/browser/classified-maker/tags/1.0.14/includes/functions.php around row 860.

                            return number_format_i18n($year) .' '.__('year ago',classified_maker_textdomain);
    	                        }
    	                               
    	                elseif($month > 0 && $day<=12 ){
    	                        return number_format_i18n($month) .' '.__('month ago',classified_maker_textdomain);
    	                        }
    	                       
    	                elseif($day > 0 && $day<=30){
    	                        return number_format_i18n($day).' '.__('day ago',classified_maker_textdomain);
    	                        }
    	                       
    	                elseif($hour > 0 && $hour<=24){
    	                        return number_format_i18n($hour).' '.__('hour ago',classified_maker_textdomain);
    	                        }               
    	                       
    	                elseif($minute > 0 && $minute<60){
    	                        return number_format_i18n($minute).' '.__('minute ago',classified_maker_textdomain);
    	                        }       
    	                               
    	                else{
    	                        return $diff.' second ago';
    	                        }
    

    Things to have in mind:
    Not all languages have the number in the beginning of a phrase like “xx years ago”. In Swedish, for instance, we’d ideally translate this into “f?r xx ?r sedan”, i.e. we need to put a particle in the beginning.
    You can handle this by using sprintf() and give us a string like “published %s years ago” to translate.

    But there’s one thing more. Please use _n() when you count something in a string. This makes it possible to form correct translations even when some words will have different forms depending on the number. It’s not enough to just split between 1 and more in your code, since some languages have more complicated structures. Russian and Polish, for instance, use singular for 1, 21, 31, “dual” for 2, 3, 4, 22, 23, 24 and “plural” for 5-20, 25-30, etc. If you just combine sprintf() and _n() in the right way, then this will all work just as it should. (As long as you handle this string in PHP only. Javascript isn’t fully there, yet.)

    To see examples where this is done in a good way, you can look at function wp_get_update_data() in https://core.trac.www.ads-software.com/browser/branches/5.0/src/wp-includes/update.php
    There you’ll also see how you can insert comments to translators, that will be shown during translation. It helps a lot when you know how your translation is going to be used.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Make your code easier to translate’ is closed to new replies.