Tuesday, July 30, 2013

PHP and JavaScript internationalization

These days I’ve been working on a PHP/JavaScript project which needed to be translated from English into other languages. I made a search and the results were pretty disappointing. All the solutions I’ve came across were either too complicated, too heavy or too messy. I wanted something more hygienic, that could be easily integrated into any project, so I ended up writing my own.

Basically, all you have to do is add a subdirectory called “i18n” (or any other name you want) and copy the “i18n.php” file there, then create a file to each language you need. One of those language files will be your default – probably the English one –, where the strings will also serve as the mapping keys. The other language files will simply have all the lines, one by one, translated.

Once the “i18n.php” file is included into your PHP script, you’ll have to set up the translation by calling i18n_set_map(), choosing the source (the default) language file, and the target language. And it’s done. Every string passed to the I() function will be translated, both in PHP and JavaScript.

There is a comprehensive example on the GitHub repository, where I published everything under the MIT license, in the hope that it can be useful to someone else. The repository is at github.com/rodrigocfd/php-js-i18n.

Saturday, July 20, 2013

Sibelius 7 sucks

As a musician with classical training, I love sheet music. They are not only beautiful pieces of graphic art, but also great repositories of musical knowledge, which are always ready to have music pulled out of them. And music writing is universal: sheet music written in China is the same written in Canada.

Obviously, when it comes to computers, I always was interested in sheet music editors. My first editor was Encore, a very simple one. But soon I moved to a more powerful editor: Sibelius 2. And since then, I’ve been a faithful Sibelius user. Well, up to version 6.

Sibelius Software was acquired by Avid, know for its sluggish Pro Tools. Unfortunately, Sibelius 7 suffered a huge shift in development direction, jumping on the ribbon bandwagon – the single worst thing ever invented in computer user interface history – and bringing up a very confusing and keyboard-unfriendly screen. Now, all the actions and option dialogs – previously organized into regular menus, easy to reach with keyboard shortcuts only – are spread among the ribbon tabs, with distracting and childish icons, wasting precious screen space and requiring you to execute many, many additional mouse clicks while searching for something among that mess. Oh, and there’s still a File ribbon tab, with even more additional tabs at left and options distributed like mucus dropped from a strong sneeze!

But Sibelius 7 didn’t change only the interface, they also brought improvements, right? Wrong. There is only one improvement, relative to text flowing inside textboxes. Everything else is insignificant for music writing. I felt really ashamed by watching the what's new videos from Sibelius Software, with nothing new to show besides that horrible user interface. Don’t they have some critical sense, at least?

So it seems that I’m stuck with Sibelius 6, which is a bit slow, but it’s usable. Well, until some other company comes out with something better. And without a ribbon.

Friday, June 7, 2013

Command line password prompt in PHP

These days I’ve been writing a quick command line script in PHP, and at some point I needed the user to type username and password to authenticate in some remote account. The standard way to prompt for a password in Linux is to hide the characters as the person goes typing, and I wanted that feeling on the script.

I assembled some code from here and here and I wrote a small function which prompts for username and password and returns an stdClass, which I share here:
function PromptUsrPwd()
{
	fwrite(STDOUT, 'Enter user name: ');
	$usr = trim(fgets(STDIN));
	$command = "/usr/bin/env bash -c 'echo OK'";
	if(rtrim(shell_exec($command)) !== 'OK') {
		die("Can't invoke bash.\n");
		return null;
	}
	$command = "/usr/bin/env bash -c 'read -s -p \"".
		addslashes("Password for $usr:").
		"\" mypassword && echo \$mypassword'";
	$pwd = rtrim(shell_exec($command));
	echo "\n";
	return (object)array('usr' => $usr, 'pwd' => $pwd);
}
This is an usage example. Run it on command line to see it in action:
$credentials = PromptUsrPwd();
echo 'Your name is '.$credentials->usr."\n";
echo 'Your password is '.$credentials->pwd."\n";

Monday, May 6, 2013

Brazilian progressive music

Well-made progressive music is just amazing. There’s not much to write about this one – lyrics (see here and here), arrangements, actual playing, mixing – there are no flaws I can spot. I’ll just leave this here and appreciate:



Unfortunately the other songs of the band are not good as this one – not even close, actually. But this very one song is so exceptionally good that the guys can die in peace.

Sunday, April 21, 2013

jQuery facepunches old IE versions

The jQuery team announced that they dropped support for Internet Explorer 6, 7 and 8 on the v2.0.0 of the library. That’s one huge and important move. First, because jQuery is widely used worldwide, and even endorsed by some big companies like Microsoft and Google. Second, because these versions of Internet Explorer still have a considerable percentage of the market share as of today. The jQuery guys announced that v1.9.x will still support these old IE versions, but who knows for how long.

This made me think the primary reason that jQuery was conceived for: a thin layer of cross-browser compatibility. If the library is not so widely compatible anymore, isn’t it losing its main reason to exist? Or maybe it’s heading towards becoming a framework like many others, just providing some useful and funny tricks.

I’m not against this decision, but given the wide adoption of jQuery in the wild, maybe it’s too early to force the migration to the latest IE version. Although when I think of the real pain that is to develop to those terrible browsers, I just raise my hands and scream hallelujah, they finally did it!

Friday, March 15, 2013

The best SRT editor for subtitles

After a couple months of work, it has just been published on CNet’s Download.com my newest program: SRTEd, a visual and portable editor to SRT files for Windows.

Basically, I decided to write this program because I had to edit some subtitles a while ago, in SRT format, and the available editors were quite tedious and painful to use. I somewhat got this insight of a more visual editor, and some time later I began writing it. The most important thing to “get the feel” is the use of the keyboard arrow keys to sync the subs. Left/right arrows move them, and when holding Shift key, change the duration. This makes the sync incredibly easy to do, visual.



Technically, the program is pure C-like C++ (that’s how I define my own C++ style) and native Win32, so it’s really light and fast. To video playback, it uses DirectX infrastructure. Moreover, SRTEd uses my own Win32 object-oriented library, which I plan to release as open source some day.

Here’s a getting started video:



CNet download link: SRTEd - SRT Subtitles Editor.

Update: I just received an e-mail from Softpedia, they published SRTEd on their site too.

Wednesday, February 20, 2013

KRK VXT frequency charts

As looking for a pair of studio monitors, I wanted to have a comparison between the three KRK VXT series models: VXT4, VXT6 and VXT8 – cones being respectively 4, 6 and 8 inches. I got the individual charts from KRK website, and I just made a collage with the three. This is what I ended up with:



It’s easy to spot how the low end increases with the cone size. Many people recommend a subwoofer, but not everyone has an appropriated room to fit everything. Indeed, in my case, I can hardly fit anything larger than the VXT4 on my desk, so I’ll probably have to stick with the VXT4 or other monitor with similar size, like the Yamaha HS50M – although I found these too bright and lacking in lows, rather unpleasant.

And the quest for my new home studio monitors goes on.

Update: after a lot of research and some listenings, I ended up picking up the KRK VXT4, which not only sounds really good, but also fits my desk. I’ve got a new pair for a good price, and I’m pretty satisfied so far.