programming

Howto copy the msgid to the msgstr in a .po file using polib

Today I got a request to take a .po file, and copy each msgid (the translation string identifier) to the msgstr (the translated text), since the msgids were already english strings. Here's how I did this using polib and Python:

po_in = polib.pofile(input_file)
for entry in po_in:
    entry.msgstr = entry.msgid
po_in.save(output_file)

Very straightforward! Kudos to the people who developed this library.

A mistake with RegExes in JavaScript

In the past months I've made a subtle JavaScript programming error repeatedly. In an effort to not make this mistake again, I'll discus this error here.

Very often I write statements such as the following:

if (myString.search(/lorem/)) {
}

(Of course, the actual regex used differs).

According to the documentation, the search method expects a RegEx object. A RegEx object is conveniently created on the fly using the // shorthand.

Read the rest of this entry »