Posts with category ‘Development’

Thu19Aug

Tools and services every web programmer should know

Written in Development

I will write about the tools and services I consider a must-have for every web programmer. They’ll be ordered by the most important to the less one:

  1. Firebug. Let’s be honest: without Firebug we are nothing. It’s the Firefox extension to view the AJAX calls and responses, to edit the entire HTML page to see the changes directly, etc.
  2. Subversion: A Software Source Control is a must. You need it, even if you think you don’t need it, you really need it. I recommend Assembla for non open source projects and Google Code and SourceForge to open source.
  3. PhpMyAdmin: To connect the MySQL databases and get a fast lookup between the tables is a really needed tool. If we depend the MySQL console we’ll be dead very probably.
  4. FileZilla: The FTP client everybody use to upload his files to the server.
  5. Statcounter: I know Google Analytics is very beautiful and very good, but if you want your stats instantaneously, you need it.
  6. Mantis Bug Tracker: You need a system where store every bug you find in your application and Mantis Bug Tracker is the easiest way to do it. It’s made with PHP+MySQL, so you don’t need an exotic hosting to get it running.
  7. IconFinder. An incredible icon finder where you can find whatever you want. Be careful with the license of them, because you can have problems.
  8. ColorMania: It’s a simple color picker. There are thousands of them, but I use it. You need a program where capture the color of everything on your screen, where convert between RGB and Hex, etc.
  9. Tada-list: I think a to-do list is always very recommendable. It’s useful to set goals or tasks.
Thu08Jul

10 Steps to build a fairly ambitious website

Written in Development
  1. Be clear with the idea. First of all, you need to have an idea and this idea must be very clear. Speak with your partners until is clear.
  2. Build the high level classes for the application. The connection with databases must be built before write any other line of code.
  3. Implement the user registration and the login later. That step can be obvious if your website doesn’t require login, but else you’ll need to have it as early as possible.
  4. Write the main code of your application. Forget about details and about design unless you have dedicated layout designers or something like that.
  5. Give the website an acceptable appearance. Start thinking about how the web will look.
  6. Think about what things might need the application if it grows more than expected. Scalability and code’s expansion possibilities. Also, get in mind the possible features your users will ask for you.
  7. Give some persons the application to hear opinions, and to test the usability of the website.
  8. Write the code to generate RSS feeds and to build the Sitemap.
  9. Start linking the web from other sites you own. Add the URL to Google. Start thinking about SEO seriously.
  10. Put a link to the site everywhere you can. Comment in blogs, register in forums and post links, answer questions on Yahoo! Answers and put a link, etc. etc.

If you follow all the steps you have the possibility to start a website with ambitious, but, remember, the most important thing here is your knowledge: more knowledge in web programming and more possibilities of success.

Sat08May

GNU gettext with PHP

Written in Development

When we started the development of trackingo a question came to our minds “what would be the best way to localize the entire application?”. The best choice must be one that was able to separate the text outside the source code, making easier to bring more languages to the application.

The easiest setup is probably to have tens or hundreds of PHP constants or an array with all the phrases and choose which array or which source code with constants apply depending on the language of the user. That system is very easy to understand, but is evident that for more than two languages is unsustainable: the source code gets bigger and bigger and there is no way back. The scalability of the system is simply zero.

In terms of performance is also very very poor: all phrases will be stored in the local memory, are they used or not.

Once we had discarded that option, we chose the official GNU translation system, GNU-gettext.

POEdit gettext editor

Translation system:

  • The files with translations are the .PO file, editable with Notepad or with the specialized POEdit and the .MO file, is the compiled version of the .PO source file. The programming language you are going to use with that only will read the .MO file, so you need to compile it after any change made in the original .PO.
  • Each folder have a .PO and a .MO file and each folder corresponds to a language. The main language of the application not have to have a folder for it.

The advantages we find with that system are:

  • Complete separation between PHP code and translations. If we want, we can pass the .PO file to a professional translator and get back with perfect translations; Otherwise we would have needed a person with almost basic programming knowledge.
  • Performance, gettext is more optimized than any trick we could manage to do with PHP. The access to translation won’t be a bottleneck.
  • Standard. GNU gettext is the standard for translations using open programming languages such as PHP.
  • Clean code. Calling a translation is as simple as call a function called __(), pass it a string and if is in the .PO, the phrase will be translated.

Using gettext for PHP:

To use gettext with PHP you must download the free library php-gettext and call it from your source code:

require_once(GETTEXT_FOLDER."php-gettext-1.0.9/gettext.inc");
$locale = $this->language;
$encoding = ‘UTF-8′;

T_setlocale(LC_MESSAGES, $locale);
$domain = ‘trackingo’;
T_bindtextdomain($domain, LOCALE_DIR);
T_bind_textdomain_codesett($domain, $encoding);
if ($locale!="en") {
        textdomainin($domain);
}
 

You set a default encoding (UTF-8), the language and call the functions T_setlocale, T_bindtextdomain, T_bin_textdomain_codesset and textdomainnin. Be carefull that $domain is no your website domain, but the .MO filename. The main language for your application don’t have to be called.

To call a translation, simple call the function __(“string”) with the phrase to translate. You can use sprintf() or printf() if you need a custom message, for example:

printf(__("Things %s are tracking"),ucfirst($username));
 

Possible modification of the source code:

An interesting thing that I think this system lacks is a function that direct output the value of the translation, so I edited the source code of gettext.inc to include a function for do that:

/*echo gettext*/
function _e($msgid) {
        echo _gettext($msgid);
}
 

Simply echo the translation but is lighter and in some cases can be very useful.

In summary:

I see gettext as the best choice to localize your web. If you are thinking about translating your web, use gettext.