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
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_PoeditThere is a plugin that can do the job for you: codestyling-localization
STEPS:
1. Load a text domain for the theme.
2. Find the messages that need to be translated and process them with the appropriate WordPress function.
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 thisdefine('WPLANG', 'en_GB');
wp i18n make-pot . languages/my-theme.pot
in your plugin/theme folder (wp-cli i18n)my-theme
as an example, wrap your strings using the__()
function:I’m using eazypo to generate MO files for wordpress themes and plugins.
Nice and free software.
check their website, they have a guide.