Drupal 6 entered beta stage
Wednesday, September 26th, 2007– just a note –
Will write about it next days.
Add this blog to Del.icio.us, Digg or Furl | Create Watchlist for this blog
– just a note –
Will write about it next days.
Sometimes when setting up a drupal site, the situation appears, that I need a “special translation” for a standard module. I.e. I need a blogging functionality - but I don’t want to call the system a “blog”.
That’s when I need a customized translation of the blogging module. This article is about how to customize drupal strings with the localization feature.
What you need first the the GNU gettext package (it’s contained in every linux distro). From this package you need the program “xgettext”. This program is able to extract the strings from the module code that can be translated (if the module is programed very well, this should be all strings in the code).
Now go the the module’s location (usualy /modules/blog) and type:
xgettext.exe --keyword=t -L PHP blog.module
The L tells xgettext, that this code is PHP code, the keyword tells xgettext, that function “t()” is used for gettext translations. The output of xgettext is by default a file called messages.po. This file contains all translateable strings of blog.module.
...
#: blog.module:137
msgid "Post new blog entry."
msgstr ""#: blog.module:140
msgid "You are not allowed to post a new blog entry."
msgstr ""#: blog.module:178
msgid "RSS - blogs"
msgstr ""#: blog.module:222 blog.module:257
msgid "Blogs"
msgstr ""#: blog.module:239
msgid "@username's blog"
msgstr ""#: blog.module:261
msgid "My blog"
msgstr ""#: blog.module:277 blog.module:286
msgid "Recent blog posts"
msgstr ""#: blog.module:285
msgid "more"
msgstr ""#: blog.module:285
msgid "Read the latest blog entries."
msgstr ""
...
Keep each string in messages.po that you want to translate, delete the one’s you don’t want to translate, rename the file to i.e. myBlogStrings.po. Now put your translation of each string into the “msgstr” field.
I.e.
#: blog.module:222 blog.module:257
msgid "Blogs"
msgstr "Articles"#: blog.module:239
msgid "@username's blog"
msgstr "@username's articles"#: blog.module:261
msgid "My blog"
msgstr "My articles"
Then save the file myBlogStrings.po.
Go to Administer / Site building / Modules and activate the “Locale” menu.
Go to Administer / Site configuration / Localization and choose “importing a translation”.
Use the file selector to choose your “myBlogStrings.po” file, choose to import to your current language (most times it’s english (en)). And check “Strings in the uploaded file replace existing ones, new ones are added”. Then import the strings with button “import”.
You’re done, your blog is now a article collection.
The character-set of your file must be correct (i.e. UTF-8). That means, you need an editor that’s capable of saving files in UTF-8 (I use PSPad) and don’t forget to change the CHARSET in line “Content-Type: text/plain; charset=CHARSET\n” of the xgettext program’s output.