Title: Make your code easier to translate
Last modified: November 2, 2018

---

# Make your code easier to translate

 *  Moderator [tobifjellner (Tor-Bjorn “Tobi” Fjellner)](https://wordpress.org/support/users/tobifjellner/)
 * (@tobifjellner)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/make-your-code-easier-to-translate/)
 * 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.wordpress.org/browser/classified-maker/tags/1.0.14/includes/functions.php](https://plugins.trac.wordpress.org/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.wordpress.org/browser/branches/5.0/src/wp-includes/update.php](https://core.trac.wordpress.org/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)

 *  Moderator [tobifjellner (Tor-Bjorn “Tobi” Fjellner)](https://wordpress.org/support/users/tobifjellner/)
 * (@tobifjellner)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/make-your-code-easier-to-translate/#post-10841479)
 * Oh. One more thing:
    Please change all strings “classified_maker_textdomain” 
   to “classified-maker”. Your textdomain should equal your plugin slug.

Viewing 1 replies (of 1 total)

The topic ‘Make your code easier to translate’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/classified-maker_c2c1bd.svg)
 * [Classified Maker](https://wordpress.org/plugins/classified-maker/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/classified-maker/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/classified-maker/)
 * [Active Topics](https://wordpress.org/support/plugin/classified-maker/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/classified-maker/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/classified-maker/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [tobifjellner (Tor-Bjorn “Tobi” Fjellner)](https://wordpress.org/support/users/tobifjellner/)
 * Last activity: [7 years, 6 months ago](https://wordpress.org/support/topic/make-your-code-easier-to-translate/#post-10841479)
 * Status: not a support question