generating po mo translating files from scratch in a wordpress theme

Maybe I’m missing something here but I really can’t find any answer to my question around the web.

I am creating a new wordpress theme from scratch (literally from scratch) and would like to create languages folder with PO and MO file in it.

I would like to generate this translation MO file from scratch

I was looking for a good tutorial that will get me started and let me understand the whole procedure but all the good tutorials I found all talking about how to translate strings that are already exist.. meaning that a MO file exists already, the strings are already in it and I need to translate them.. that’s pretty easy but that’s not what I want.

I would like to generate something from scratch using my own custom strings..
+ I want to always be able to add more strings and compile it again to update the PO file.

can anyone send a good tutorial of how o do it from scratch?
am I missing something here?

Thanks a lot

3 s
3

You can use the tool POEdit to translate your theme from scratch or update/add new strings into the .po/.mo files. Here is the tool usage tutorial: Translating_With_Poedit

There is a plugin that can do the job for you: codestyling-localization

STEPS:

1. Load a text domain for the theme.

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

2. Find the messages that need to be translated and process them with the appropriate WordPress function.

_e(‘Hello user’,’mytheme’);
the_content( __(‘Read more’,’mytheme’) );

3. Create language files.
3.1 The POT file contains a list of all translatable messages in our theme.

3.2 The .po file is created when we translate a POT file to a particular locale.

3.3 The .mo is a binary file that is created automatically by translation software and is not human-readable.

4. Create the POT file with help of a tool called PoEdit

4.1 Open Poedit, and create a new catalog. Fill in the project’s information in the “Project info” tab.

4.2 Provide path to the theme and it will parse all the text those needs to be translated. You need to provide the keywords we used in the theme __( and _e so it can parse and create the POT for you.

4.3 Now add the translated text for each string inside POT file and a .po file is created by setting the language code and country code as the file name.

4.4 Generate .mo file out of it. (When saving a .po file, Poedit will automatically create an .mo file, which is a binary file and is not human-readable.)

4.5 Instruct WordPress to enable the localization and to load the language files.
Edit the wp-config.php file and edit this define('WPLANG', 'en_GB');

Leave a Comment