WordPress has a ridiculous number of translation functions to make your life easier. Remember them.
The basics:
- __() – Translate a string
- _e() – Echo the translated string
- _x() – Tell the poor translater what they’re translating
- _ex() – Tell the poor translater what they’re translating and echo the translated string
Escape the output:
- esc_attr__() – Escape the translation for HTML attributes
- esc_attr_e() – Escape and echo the translation for HTML attributes
- esc_attr_x() – Escape the translation for HTML attributes and tell the translator what they’re translating
- esc_html__() – Escape the translation for HTML code
- esc_html_e() – Escape and echo the translation for HTML code
- esc_html_x() – Escape the translation for HTML code and tell the translator what they’re translation
Handle plurals
- _n()
- _nx() – Tell the poor translater what plurals they’re translating
- _n_noop() – WTF is a noop? Konstantin knows
- _nx_noop() – More noops, but you can tell the poor translator what they’re translating
- translate_nooped_plural() – Actually translate your noops.
Small correction for escape and echo, correct is
esc_attr_e()
alsoesc_html_x()
…Good catch!