viernes, 29 de enero de 2010

Changing the Wordpress Language

The Wordpress backend deals with 'Posts' and 'Pages'. For some clients this is too vague, and tweaks are needed.

As an example a site i've been working on recently needed the word 'Post' to be replaced with 'Product'. To do this, we need to create our own custom language file. Unfortunately creating a language file is a pretty complex process as compared to how simple other Wordpress processes can be. It is also not as well documented as other facets of Wordpress. So watch closely!

To begin with you will need a copy of the official WordPress POT file.

Next get yourself a translation tool. We opted for poEdit, which was quick and easy to download and install.

You are ready to start translating!
Open Poedit and use the File/open dialog to open your Wordpress POT file (ensure you change 'files of type' from GNU Gettext catalogs (*.po) to 'all files (*.*) )

Firstly, most importantly, and not well documented:

Go to Catalog/Settings
In the 'Project Info' tab:
change the language team to something new (e.g. Haycroft Media)
change the 'Plural Forms' value to nplurals=2; plural=(n != 1)
(if you are translating to a different language check this: list of Gettext plural forms for the correct setting
Click Ok

Now go to File/preferences and click on the 'Editor' tab.
Ensure that the 'Automatically compile .mo file on save' box is ticked
Click OK

Now File/save as to save
For this example I am saving the file as custom_lang
after saving you should see: custom_lang.mo and custom_lang.po saved in the location you chose.

Now at last we can begin!

Click Edit/find and enter the term you wish to translate (in my case it was 'Post')
tweak the search settings according to what you need and search

The first result I get for my 'Post' example is "Error: you are replying to a comment on a draft post."
Copy and paste this into the translation box and then amend the word post so you get:
Error: you are replying to a comment on a draft product.
Repeat this process until you have finished.

Save again

Now open your wp-config file and amend:
define ('WPLANG', '');
so that it reads:
define ('WPLANG', 'custom_lang');
(or whatever you saved your language file as)

Now create a directory called 'languages' in your wp-content directory
Upload the custom_lang.mo (or wahtever you saved it as) file to the languages folder you just created

Your backend should now display your amended language!

No hay comentarios:

Publicar un comentario