I've got a few gettext() questions that are not covered anywhere in WordPress Codex but I think they are important.

  1. __('string') in THEME should be used for strings that are likely to be present also in main WordPress translation file. No textdomain necessary. Examples: one, two, submit, cancel, remove and other common words. Correct?
  2. __('string', 'textdomain') in THEME should be used for strings that are theme-specific. Examples: 'this option enables X feature'. Correct?
  3. I think it's better to make one textdomain for front-end of theme and another for back-end. Like __('string', 'textdomain') and __('string', 'textdomain-admin'). Not everyone wants to spend hours to translate 100 additional admin panel strings. Correct or it's bad practice?
  4. Each PLUGIN should have its own textdomain: __('string', 'plugin-name'). Correct?
  5. I think that setting CONTEXT for THEME string is very, very useful but nobody does this. Why? Like: _x('add item', 'add slide text', 'textdomain') and _x('add item', 'shopping cart', 'textdomain').
  6. How to translate comments, dates, currencies, hours, numbers?
    1. Example: one comment, two comments, but in some languages it may be: one comment, two comments, three commentsX, four commentsXY, five commentsXYZ, six commentsABXY (a lot more different plural forms with complex patterns).
    2. Example: nearly all themes use the_time(get_option('date_format')); - shouldn't it be echo date_i18n(get_option('date_format'), strtotime($post->post_date)); or echo date_i18n('F jS, Y'), strtotime($post->post_date));?
    3. Example: English uses 12,345.12, but some languages may use 12.345,12.

1 Answer 1


Interesting questions, I'll try my best, but I hope others can also give input.

re 1. Usually I use the theme's text domain also for strings that are likely to be present in the main WordPress translation file

re 2. correct

re 3. I think it is a good idea, but I don't know if it is bad practice or anything like that

re 4. correct

re 5. I also think it is very useful.

re 6.1. A few months ago Otto did a post on the correct way of internationalising strings. For anything related to numbers he gives the following:

$string = sprintf( __('You have %d tacos', 'plugin-domain'), $number );

re 6.2. correct

re 6.3. I had to look this up and found the answer on a thread in the WordPress forum:

if (0 < $numtags) $numcats= number_format_i18n($numtags);

Keep in mind that internationalization of themes and plugins is still not widely spread, WordPress is very much US (or English) oriented and only this year it seems that people are putting more attention to it. I wrote an article on WPCandy earlier this year about the very subject.

  • Thank you for taking time to read and answer :) 99% of website is easy to be translated but what do you think about this (6.1 on my list): "no comments", "1 comment", "2 comments" AND "brak komentaRZY", "1 komentaRZ", "2 komentaRZE", "5 komentaRZY" which is for: German, Polish, Russian. There can be multiple plural forms... _n() is just for single and plural. They forgot that there can be single, plural, other plural and yet another plural form.
    – Paul
    Aug 24, 2012 at 19:16
  • @Paul in German that is not the case actually, it's "1 Kommentar", "2-n Kommentare", so you can translate that with: $string = sprintf( _n('You have %d taco.', 'You have %d tacos.', $number, 'plugin-domain'), $number ); But I see what you mean. For Polish and other languages where the noun itself has different plural forms depending on the number, I guess I would add all the different options in my translation strings. Hopefully others can give input on this...
    – user2015
    Aug 25, 2012 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.