/ wordpress

Wordpress localization

Wordpress translation/internationalization/localization for your theme



1. Use _e(), __() in your theme

See ref link.

__('String') should become __('String', 'text_domain')
_e('String') should become _e('String', 'text_domain')
_n('String', 'Strings', $count) should become _n('String', 'Strings', $count, 'text_domain')


_e('Contact', 'mytextdomain');

This will translate Contact based on the textdomain mytextdomain.

Example of loading a text domain:

load_theme_textdomain( 'mytextdomain', get_template_directory() . '/languages' );

2. Create .po file

  • 1.1 With Poedit go to File > New... and select the language you're translating to, eg: Chinese. Save the file at any location first. eg: ~/Desktop/mypo.po

  • 1.2 Choose Catalog > Properties... Fill in Project Name and version.
    Under Sources paths, click the + under Paths and select your theme folder.
    Under Sources keywords, click the 2nd button from the left.

    Add the keywords __ and _e. (check out http://wordpress.stackexchange.com/a/149230/60444)

  • 1.3 Finally, click Extract from sources and this will generate the .po and .mo files.

  • 1.4 Do your translations within Poedit.

  • Wordpress only needs the .mo file, and you'll have to name them according to the format here: https://make.wordpress.org/polyglots/teams/
    Eg: Chinese will be zh_CN.mo.

  • Save the .mo file in the languages folder inside your theme, eg: /wp-content/themes/yourtheme/languages/zh_CN.mo

3. Switch language with qtranslatex

  • Using Chinese as example, try switching to it manually by adding /zh to the URL, assuming you have setup qtranslatex.

If you've done everything correctly, you should see your text changes.

Wordpress localization
Share this