Support » Themes and Templates » Implement _e () function, how to?

  • Designing_Themes_for_Public_Release mentions adding the _e () funtion to “echo titles and headings”. I’ve searched around the codex and forums, and haven’t seen something that explains exactly how to do this. If I missed it, a gentle nudge in the righ direction would be welcome, and if it’s not there and you share with me how to, I’ll gladly add it to the codex.
    Thanks in advance.

Viewing 14 replies - 1 through 14 (of 14 total)
  • I’ve seemed to answer my question, though I’m not sure if this is a WP specific funtion, or a php function.
    The pemise, as I understand it, is when you put the of something in the _e function, and a localization file exists, it searches the file for a translation of the word within the function.
    So if I have this <h2>Links</h2> and switch it to this <h2><?php _e('Links'); ?></h2>, a localization file can have the translation of Links, and it will automatically translate the word.
    I’m still not sure where else this should be used, but will continue to experiment.

    That’s exactly how it works. _e('text') echos, __('text') returns.

    Yeah, that was the first page I looked at. It makes a brief mention of the _e() function, which Viper confirmed my understanding of. However, there is no where else really in that article that explains where good places are to include the function. Thus my question. Aside from the headings in the sidebar, where else should I use it?

    Best practice is to include it anywhere where you think someone might want the text to appear in a different language.

    For plugins, if you use _e()/__(), it’s also best to use a custom language file.

    But here’s the dilemma I’m at. Most of the content is obviously dynamic, so are there built in features to have, let’s say, page titles translated, or is there a way to cojoin the _e() function with the list_pages template tag?

    No need to use it on list_pages as it’s either already handled by WordPress or it’s content that the user has defined, such as Page titles.

    Any text that you literally type out should be in a language function. See the /default/ theme for an example.

    I’m not sure what version of the default theme you are looking at, but there are no instances of _e()…
    Check that, upon futher poking around, it’s classic that uses the function, not default. I’ll take further inspection of the theme, and report back the instances of use. Thanks for talking me through the process.

    The developers decided not to include anymore the “gettext version” of the default theme in the distro… howevere you can study it here:
    (click on trunk)

    Outstanding Moshu. Between studying the classic theme, and the link you provided, I can not only fix what I want for my first”public release”, I can also update my “blank theme”.

    Thank you both.

    But here lies a question. If it was decided not to be included in the distro, then why is there language in the codex suggesting that any theme distributed contain such code?

    Translators can get the default from the link above. Then using the “gettext technology” a translator can extract the properly marked strings into a POT file and work on translation (.PO file) and, finally, generate a .MO file to be used in the localized WP.
    For individual themes – not having a central repository – I guess it’s recommended to have the code ‘ab ovo’…
    But this could be only my theory 🙂

    Right O’. Needless to say, I want to have it in the “blank theme” and any thing I were to release. Cheers again for the link and more clarification.

    Yes, indeed default is lacking that respect (as in a number of others…) — quite a serious oversight if you ask me that the default theme is not internationalized.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Implement _e () function, how to?’ is closed to new replies.