Categories: "Full Stack Dev & Design"

Preparing Translatable Strings

I am currently considering using GNU gettext utilities to internationalize b2evolution.

I'm not done reading the docs, but right now I just felt like I needed to work this out:

The gettext manual has this totally valid understanding about preparing translatable string:

Hardcoded string concatenation is sometimes used to construct English strings:

strcpy (s, "Replace ");
strcat (s, object1);
strcat (s, " with ");
strcat (s, object2);
strcat (s, "?");

In order to present to the translator only entire sentences, and also because in some languages the translator might want to swap the order of object1 and object2, it is necessary to change this ...

This sounds very wise... but the "solution" leaves me baffled:

...change this to use a format string:

sprintf (s, "Replace %s with %s?", object1, object2);

Okay... how exactly am I supposed to swap the order of the objects? Swap %s with %s... ? yeah, right... :crazy:

(For those of you familiar with C but not with translation, rememenber that the translator can only act upon the string "Replace %s with %s?", not upon the sprintf statement.)

Update: Doh! Just learnt something kewl about printf syntax! :. Solution is easy:

sprintf (s, "Replace %1$s with %2$s?", object1, object2);

And there's no reason to specify those order numbers until you need to change the order... well, actually there is a reason: give a hint to the translator who "may not" be a printf syntax expert... :!:

mySQL & Oracle

(via Cédric) Jim Gray [Links gone]:

"Larry Ellison announced that Oracle is now running entirely on Linux. But he didn't say, "Incidentally we're going to run all of Oracle on MySQL on Linux." If you just connected the dots, that would be the next sentence in the paragraph. But he didn't say that, so I believe that Larry actually thinks Oracle will have a lot more value than MySQL has. I do not understand why he thinks the Linux problems are fixable and the MySQL problems are not."

Quote of the day - Concurrent development

The truth is that concurrent development is hard. Good SCM tools make it easier, but some people prefer to adopt processes which prevent complexity instead of using tools which help manage complexity.

-Eric W. Sink

Advanced PHP book?

So I've been developing on b2evolution for a couple of months now and people seem to be quite happy with it ;) (read the testimonials! ;) )

Nevertheless I still feel like I'd really need to learn PHP for real someday! :. I mean, it's easy to learn the basics from reading actual code (because it's very similar to C/C++) and occasionnaly referring to the online manual... but I'm pretty sure there are some advanced concepts out there I'm not even aware of... right now I'm thinking about the configuration options and the loading of modules...

I was about to buy a book online but I'm really afraid of getting something that will teach me "hello world" after a few hundred pages. What I need is a 15 page recap on datatypes and control structures and advanced stuff starting at page 20! :P

If anyone reading this knows the right book for this, please point me to it! Thanks a lot! ;D

Date Arithmetic With MySQL

MySQL offers pretty useful functions when you want to manipulate days:

  • You can add a time interval to a date value with ADDDATE() or DATE_ADD()
  • You can subtract a time interval from a date value witf DATE_SUB()
  • You can find the interval between two dates with  DATEDIFF()

It's often easier to compute this stuff directly in MySQL rather than in PHP.

For all date functions see the MySQL Manual.