Wordpress translation/internationalization/localization for your theme
- I'm using qtranslatex for handling the language switching https://wordpress.org/plugins/qtranslate-x/installation/
__() 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')
This will translate
Contact based on the textdomain
Example of loading a text domain:
load_theme_textdomain( 'mytextdomain', get_template_directory() . '/languages' );
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:
Catalog > Properties...Fill in Project Name and version.
Sources paths, click the + under
Pathsand select your theme folder.
Sources keywords, click the 2nd button from the left.
Add the keywords
_e. (check out http://wordpress.stackexchange.com/a/149230/60444)
1.3 Finally, click
Extract from sourcesand this will generate the
1.4 Do your translations within
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
.mofile in the languages folder inside your theme, eg:
3. Switch language with qtranslatex
- Using Chinese as example, try switching to it manually by adding
/zhto the URL, assuming you have setup qtranslatex.
If you've done everything correctly, you should see your text changes.