Monday, September 29, 2014

Change WordPress Language in Theme

If using _e("Hello","textdomain"); to translate theme you need to create an es_es.po file in text editor:

msgid ""
msgstr ""
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"Project-Id-Version: Theme Name\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: Mike <w@w.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: es_ES\n"
"X-Generator: Poedit 1.6.9\n"
"X-Poedit-SourceCharset: UTF-8\n"

#: ../header.php:58
msgid "Hello"
msgstr "Hola"

Compile it with POEeditor you will get file es_es.mo. Upload both files
/wp-content/themes/{yourTheme}/languages

in functions.php add

add_action('after_setup_theme', 'my_theme_setup');
function my_theme_setup(){
    load_theme_textdomain('textdomain', get_template_directory() . '/languages');
}

In WP backend change language to Spanish. And both your theme and WP backend will be in Spanish. You can use plugin to leave backend in English.

No comments:

Post a Comment