Gettext details

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.

Related posts

Leave a Reply

1 comment

  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.