WordPress.org

Ready to get started?Download WordPress

Forums

Implement _e () function, how to? (15 posts)

  1. Michael Bishop

    Posted 9 years ago #

    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.

  2. Michael Bishop

    Posted 9 years ago #

    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.

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

  4. Yngwin
    Member
    Posted 9 years ago #

  5. Michael Bishop

    Posted 9 years ago #

    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?

  6. 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.

  7. Michael Bishop

    Posted 9 years ago #

    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?

  8. 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.

  9. Michael Bishop

    Posted 9 years ago #

    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.

  10. moshu
    Member
    Posted 9 years ago #

    The developers decided not to include anymore the "gettext version" of the default theme in the distro... howevere you can study it here:
    http://svn.automattic.com/wordpress-i18n/theme/
    (click on trunk)

  11. Michael Bishop

    Posted 9 years ago #

    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.

  12. Michael Bishop

    Posted 9 years ago #

    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?

  13. moshu
    Member
    Posted 9 years ago #

    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 :)

  14. Michael Bishop

    Posted 9 years ago #

    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.

  15. Yngwin
    Member
    Posted 9 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic