Benchmarking PHP Localization – Is gettext fast enough?

April 10th, 2006

Last year, I wrote a post about using gettext to localize PHP web pages. Gettext makes it easy to maintain the translations and always provides a fallback locale. But is it fast?

I created a simple web page to compare the performance of various localization methods for PHP. It only contains 3 localized strings and does not use advanced features of gettext (e.g. plurals). I wrote a version using the gettext PHP extension (“gettext Ext.”), one using PHP-gettext (“gettext PHP”, a gettext implementation written in pure PHP) and a version that does not use gettext at all, instead it uses an array that contains all the translations (“String ID”).

Read the rest of this entry »

Improved Ruby syntax highlighting for Notepad2

September 3rd, 2005

Notepad2 ScreenshotIn my previous post about Notepad2 (Notepad2 with Syntax highlighting for Ruby, YAML, Bash and Conf), I posted a modified version of the Notepad2 editor which included syntax highlighting for Ruby and some other languages.

I have now extended Scintilla’s Ruby lexer and Notepad2 to support seperate syntax highlighting for symbols, instance variables, class variables and global variables. I also added the keywords “private”, “protected” and “public” to Notepad2′s keyword list.

Download the new, modified Notepad2. This version includes English and German binaries and the complete source code including Scintilla.

Update: I have made some more small modifications to the Ruby lexer which fix some bugs. A single ‘:’ character is now no longer highlighted as a symbol, and expressions such as “@test.x” are now highlighted correctly (@test as a local variable, . as an operator and x as an identifier). Download the fixed version from above.

Notepad2 with Syntax highlighting for Ruby, YAML, Bash and Conf

August 14th, 2005

The free, open source Notepad2 is my favorite text editor. I use Notepad2 to edit HTML, PHP, JavaScript etc. Unfortunately, Notepad2 does not have syntax highlighting for all file types supported by Scintilla. Wesner Moise offers a version of Notepad2 with Ruby support. I have created a modified version of Notepad2 that is based on Wesner Moise’s changes to Ruby and Makefile support and Scintilla 1.65 and added Syntax highlighting for YAML, Bash shell scripts and Apache configuration files. I have compiled an English and German version (I have extracted the German strings from the official German Notepad2 build using Resource Hacker). I also added the extensions .rhtml (for Ruby on Rails), .php4 and .php5 to the HTML lexer (if you have previously used Notepad2, you may have to add them manually under View -> Customize Schemes). It does however not highlight the included Ruby code in .rhtml files, because the Scintilla HTML Lexer does not yet support included Ruby in HTML. It should be possible to include that feature in LexHTML.cxx somehow, but that Lexer is quite complex. I don’t know if someone is working on that. If you find something, please let me know.

Download modified Notepad2 (includes English and German binaries + source code)

This version comes with syntax highlighting support for HTML, XML, CSS, JavaScript, VBScript, ASP, PHP, CSS, Perl, C, C++, C#, Java, Visual Basic, Pascal, Assembler, SQL, Python, NSIS, INI, REG, INF, BAT, DIFF, Ruby, YAML, Bash and Apache configuration files.

Update: I have replaced the download with a newer version which includes an improved Ruby lexer. See my post Improved Ruby syntax highlighting for Notepad2. If you need the old version, here it is.

A flexible caching system for .NET: MelCache

August 7th, 2005

MelCache is a caching system for .NET I wrote some time ago in C#. It is very easy to use and allows you to cache arbitrary data (byte[]) with a key (string) and an expiry date. You can also compress the cached data using GZip or BZip2 (uses the #ziplib library). Cached data can be retrieved later if it has not yet expired. The caching system creates binary files which are used to store the cached data (by default 5 MB) and an XML index file. New cache files are created if needed. This is done to reduce hard drive fragmentation when caching small files. Cached files can also be deleted from the cache at any time. It is especially useful to cache files your application downloads from the Internet. Note: MelCache has nothing to do with ASP.NET or ASP.NET’s caching capabilities (however, it should work with ASP.NET, too).

The MelCache DLL (Melaxis.MelCache.dll) is signed with a strong name and can be installed in the GAC. It requires ICSharpCode.SharpZipLib.dll (included in the ZIP file).

Download MelCache (Documentation included)

You can use MelCache in freeware and open source projects without restriction. Please contact me if you want to use it otherwise. If you find any bugs in MelCache or if you have an idea how it could be improved, please leave a comment.

MultiWP 1.1

August 6th, 2005

I have just installed some WordPress plugins that try to create files in the blog directory. They use the get_home_path function, which returns the path of the WordPress installation. Therefore, the files are created in the wrong directory. To fix this problem, I have released an updated version of MultiWP. Unfortunately, this time, you have to modify one line in admin-functions.php to make it work. Detailed installation instructions are included. If you update from MultiWP 1.0, be sure to also update the multiwp.php plugin file. I have also improved the wordpress/wp-config.php file. I encourage you to update that file as well (be sure to adjust the base path in line 11 if needed (see included howto)), but it should work with the old one as well.

Download MultiWP 1.1

Localizing PHP web sites using gettext

August 6th, 2005

Developing multi language web sites using PHP is actually very easy. A common approach is having an include file for every supported language which contains an array that maps string ids to localized text (for example “WelcomeText” => “Welcome to our homepage.” would be included using something like <?= $strings["WelcomeText"] >). However there are several problems with this approach. First of all, when the application is updated and additional strings are added, there is no way to determine which new strings were added and if they are present in every language (unless you write a script for it). What happens if a newly added string is not yet translated into a specific language?

Using gettext with PHP

A widely used framework for internationalization is gettext. It can be used with a variety of programming languages, including PHP. There are basically two ways to use gettext in your PHP applications. You can use the native gettext PHP extension or you can use a library implemented in PHP that does not need any extension, such as php-gettext. I will use the native PHP extension, but once you have read the post you should be able to use the php-gettext-library, too (have a look at the included example).

Read the rest of this entry »

Learning Ruby on Rails

August 5th, 2005

Ruby on Rails is an open source framework for web applications written in Ruby. It has become very popular recently because it allows you to write web applications much faster than with most other frameworks. You have to write very little code to do the most common operations and its clean MVC architecture ensures that your application is clearly structured. Ruby on Rails comes with several generator scripts that automatically created the required files.

So far, I created all my dynamic web sites using PHP. Writing a simple application such as a guest book requires quite a lot of code in PHP to connect to the database, retrieve the entries, add new entries and so on. With Ruby on Rails that’s much easier. You simple create a table, run a generator script to create a model and a controller. A cool feature called scaffolding automatically creates an interface to list, add, edit and remove entries. This is very useful to add some entries to a new table before you have created the real interface. But even that is really simple.

For example, by adding a line like “@entries = Entry.find_all” to a controller action, Ruby on Rails fetches all rows of the entries table (that’s another cool feature: table names are lowercase and plural, model names uppercase and singular – Ruby on Rails can convert them automatically) and saves them in a variable called entries. In a template with the same name as the action, you can loop trough all entries using “<% @entries.each do |entry| %>” (Ruby code is embedded in <% %>-Blocks inside the HTML template) and then print them easily using “<%= entry.message %>” etc.

Ruby on Rails is really cool. In order to understand Rails, I decided to learn Ruby first. So far, I can recommend two links for learning Ruby. The first one is the Ruby user’s guide by matz, the creator of the language, which provides a rather short introduction to Ruby. The other one is Why’s (Poignant) Guide to Ruby, which is quite entertaining.
O’Reilly has a tutorial for Ruby on Rails: Rolling with Ruby on Rails (this includes installation instructions for Ruby, Ruby on Rails and MySQL) and Rolling with Ruby on Rails, Part 2. More tutorials and API references can be found on the Ruby on Rails Homepage.

Multiple blogs with a single WordPress installation: MultiWP

August 5th, 2005

As I wrote in my previous post, I’m going to start a few blogs based on WordPress. Unfortunately, WordPress does not support multiple blogs by default. Normally you need a separate WordPress installation for every blog. While this may not seem like a big problem at first, what do you do when an updated WordPress version is released? I didn’t want to update every single blog, so I wrote a little script called MultiWP. MultiWP allows you to have several blogs with just a single WordPress install. When you update WordPress, all blogs are immediately updated to the new version. MultiWP also does not modify any WordPress files, so you can just follow the standard update procedure. Sounds good? Download MultiWP. A detailled installation howto is included in both English and German.

Welcome to my web development blog!

August 5th, 2005

Welcome to my new weblog. This blog is about web development and web design and is the first of a number of WordPress based blogs I plan to launch soon.