Constructing WP themes or plugins that take into account future gender translations (2)

Few days ago I began a serie of articles about how to design a WordPress Theme that facilitates that in the future it is possible to make a translation that takes into account the gender. In the first article I suggested a little technique to mark the Post Type (and for extension Taxonomy) objects including a new property that keeps the gender of the object and that depends on the translation today I’m going to extend this technique also for the labels of the Post type inside the Admin interface.

Doing this, the translator has got the possibility to exchange this initial string for ‘female’, ‘neutral’, or ‘whatever’ in his/her local language. Principaly, this solution is oriented to the Front End –the WordPress theme– but, what does it happen in the Back End? Depending on the gender of the Post Type that you are working on, in a lot of languages, the interface ought change all its strings. As we saw, for example wine, cats and recipes has two (or three) different genders depending on the local language.

Of course, as a developer, you can decide to use a different array of labels for each one of the Post Types that your plugin or theme uses but I think that perhaps I could have a better solution using, precisely, the gender element that I already introduced in the last article.

In this proposal, firstly we have to declare three arrays of post type labels: one for male string, one for female strings and a third one for neutral strings. Secondly, we have to create a little function that returns one of these three arrays depending on the gender. Afterwards, for registering a new post types, we’ll use this function for constructing the labels. See the code.

This strategy gives the translator the possibility to modify completely the sentences used for male, female and neutral genders whether for the singular as for the plural form of the words. Now, in our themes or plugins, we’ll use this function to declare three post types.

The translator will have just to translate once the three arrays of labels (male, female and neutral) and these translations will serve for all post type. From this point, for each Post Type, the translator will have just to translate the gender of the word in his/her local language and, of course, the name of the post type in singular and plural… Just three words.

With only one translation of the labels it can be changed and adapted all the WordPress admin interface for take into account the gender for all strings for all different post types in any language… It looks well, I guess.

I hope this second article will be useful for you. In the next articles we will see strategies for individual post, users, and terms.

Expertise Levels

Programming Languages

What about the author?

Joan Miquel Viadé

Barcelona, 1966, I begin in the world of computer hand in hand with IBM in 1988 where I work for a year and a half. Later I am studying computer engineering and I graduate in 1994. Since then I participate in various computer projects until in 2010 I begin to specialize in projects based on the WordPress technology. See full bio.