Monthly Archives: November 2008

My first WordPress plugin

Hey,

I am very proud to present you, my first plugin for WordPress platform – Autocompleter.

The plugin adding autocomplete functionality for the search input field of your blog. The values are the tags and categories existing in the blog and this way you will help your visitors to find easily the proper information in your blog.

My first implementation was with Prototype and Script.aculo.us, but because I like very much jQuery library and I found a wonderful plugin for autocomplete, I build it with jQuery.

You can check the demo in this blog – top right – search box πŸ™‚

Hope you will like it and you will vote for it πŸ™‚ Thanks

The official page is: wordpress.org/extend/plugins/autocompleter

Translating plural and singular forms in CakePHP

I don’t know how good you know the *.po translation file syntax, but for me it was a text file with “msgid” and “msgstr”, where msgid is the string, which could be found in a code of the app, wrapped with __() function and msgstr is the string which is the translation.

Following this convention in all of my projects I had not problems till now. But on this one I’ve noticed that the translation is not quite accurate especially when translating time. I am speaking about usage of timeAgoInWords() function from the TimeHelper.

I noticed that when there is a translation file for the specific language singular and plural words are not translated properly, I had results like “3 hour and 34 minute” instead of “3 hours and 34 minutes”.

I thought that I’ve found a bug, and I submitted a ticket in the trac, but I was wrong, because syntax of the PO files is a little bit extended than my understanding. πŸ™‚

99% of the cases the standard approach could fit just fine, but when it’s used __n() function which is described as:

Returns correct plural form of message identified by $singular and $plural for count $count.

the translation file needed a specific syntax. Here is the example of it:

msgid "hour"
msgid_plural "hours"
msgstr[0] "hour"
msgstr[1] "hours"

As you can see instead of msgid<->msgstr pair, there is also msgid_plural and array of msgstr which holding the translations of singular and plural values. Note that in some languages plural could have 2 or more forms. In these cases the syntax will be (Czech):

msgid "%1 second"
msgid_plural "%1 seconds"
msgstr[0] "%1 sekunda"
msgstr[1] "%1 sekundy"
msgstr[2] "%1 sekund"

It’s good to set the plural forms definition in the project settings which are in the beggining of the file. This is very handy when you use PoEdit or similar translation tools, because if is your setting is correct, these tools will provide for each plural form separate tab.

The syntax of plural form definition is like:

"Plural-Forms: nplurals=1; plural=0;\n"

It hold 2 parameters the first one holding the number of plural forms in the specific language and the second one is an expression how to determine the plurals. If you don’t know how to set this correct for a specific language, check this good document of all available languages. πŸ™‚

More information about the PO syntax I founded in that article. I’ve noticed in that the article there are shortcuts, which are not useful for me so far, but you never knows, in the future they could be handy.

Regarding to that I am wondering is there a POT file for the core lib translations which could be a big helper to anyone who need to translate the whole framework.

Blast from the past

Hey guys,

last week I’ve worked on a project which I finished somewhere in spring of 2007 and I decided to share my experience with this post. I don’t know did you had such experience, but for me it was interesting, because working on old code is always challenge.

Basically, the project was really small one, which uses 80% of scaffolding, so really nothing complicated. Now the client wanted some extensions to the core functionality /like adding few more look-up tables and some basic reports/ and because I was the only one developer who worked on it, they ask me to do this and I agreed.

My first thought was to upgrade the core CakePHP lib to the last version, but after thinking I decided not to, because if something goes wrong /like some deprecated functions/, I need to do more work in debugging rather than focusing on the real tasks.

What I noticed while I coded?

The major one – Improvement of the console script. In the past it was in the /cake/scripts/. In the folder there were acl.php, bake.php and bake2.php, extract.php for label extraction and master bake which I never used. Now, the console script is more advanced and provide more functions. Still I am not big expert on it and I still using it for basic operations :).

Fully translated labels – it’s related to the previous one – when the code was generated with old bake script, some of the labels weren’t wrapped with __() function and especially for me it was biggest pain. Someone could tell me that there was ability to modify the templates, but I personally never did it.

The truth is that CakePHP in fact is improved a lot since then. Hopefully it will continue in this direction in the future as well.

Anyway, it was really interesting experience for me.

bInspiration.com – a small and funny application

binspiration.com Hey guys,

I am really proud to present my last project written in CakePHP – bInspiration.com.

What is all about?
bInspiration.com is a web 2.0 service which aims at helping people to get inspired. Visitors are challenged to write a sentence including 2 already given words. The application is funny way to get creative, because “filling the gaps” in a text could give unpredictable and interesting results and that’s why I thought it’s really inspiring. More you can learn from about section of the site.

How long does it take to create this
Well, I’ve decided to create this application somewhere about mid of June and in fact the time for development and design was really short, about week and a half, but due to some hardware and admin problems with my hosting, I’ve delayed the start up.

Later on, I decided to show it to some friends and the responses were not very optimistic. Most of the people didn’t get the idea of the site, so definitely there was something wrong. Apart from this I received some very good ideas for improvements and I decided to add them before going live.

The features

  • Ajax interface – the whole interface is ajaxed and it’s really easy to use it.
  • Multilingual – thanks to CakePHP i18n class, the application automatically detect the browser language preferences and translate whole site. According to this, all user’s created content will be filtered by the selected language, so users can read and write in their preferred /or at least available in the site/ language.
  • No administration – yes that’s true, and it’s feature. As a real Web2.0 application, visitors of the site are the real administrators. They can vote for each sentence in the database and from their decision the content will be promoted or completely removed from the database /two spam votes will remove the sentence from the database/.
  • Follow an author – there is possibility to browse through all authors in a specific language. It’s also possible to follow them by subscribing to their rss feed.
  • View the archive – it’s possible to browse through all sentences in the specific language.
  • Changing the given words on the fly – this was an idea from Daniel – to give possibility to switch the current fixed pair, if the visitor is not inspired by the current one.

Future plans
Well, the plans really depends from the activity of the users. πŸ™‚ But at least I have idea to make some statistical reports such as

  • Most active language
  • Most and worst sentence by language
  • Most active author
  • Most used words
  • Probably a contest πŸ™‚

and many other.

I would love to hear any comments about it.

Powered with Ubuntu 8.10

Today I’ve upgraded my desktop machine with the last version of Ubuntu 8.10 Intrepid and I am quite happy from the installation. Wow, it’s been two years and a half since I switched from Windows. It is like it was yesterday. πŸ™‚

First things which I personally notice are:

  • Shut Down is separated from Login and Switch user.
  • The weather forecast is integrated in the time “widget” into panel, where it’s possible to add more than one location – very convenient for mobile users.
  • Default terminal application /gnome-terminal/ supporting tabs. Which in fact is not new /I’ve checked my laptop where I am still using 8.04 and this feature exist as well/, but I just noticed this. Anyway, I am using terminator rather than gnome-terminal πŸ™‚
  • The installation script remove some of my favorite games, especially Kasteroids, anyway re installation was quite easy.

This is my first time when I just upgrade instead of total wipe out and clean install. Apart from this – so far so good, everything run smoothly and nicely. Ubuntu rocks!