Monday, February 7, 2005

Making localization easier

"The total is $Dollars."
"The total is $" & Dollars & "."
"The total is " Dollars "." (Fantasy syntax where concatenation requires no operator)

In practice, you probably shouldn't use any kind of shorthand like these, because they're not really localizable. Straight concatenation is out because certain languages will need to have the words rearranged, and the $ syntax is out because you also might not want localizers to be able to include just any old variable in the string, and it doesn't allow you to use expressions unless you start getting really complicated. An interesting idea would be one in which you could make up your own tokens on the fly using dedicated string formatting syntax:

["The total is [Dollars]."; Dollars: Total.AsDollars]

Wouldn't that be a great expression? That would be pretty easy to localize. If the string Dollars were already declared, you could get rid of the ":Total.AsDollars" part. And, if my fantasy language made resources first-class citizens, you could do something like:

[Resources.TotalText; Dollars: Total.AsDollars]

OR, maybe the code could contain one version of the string (for example, English), and then localized strings could be substituted in as necessary. That might get a little too complicated...

[TotalText: "The total is [Dollars]."; Dollars: Total.AsDollars]

I think I'd like that after I got used to it. It's verbose, but something like it would make writing localizable code a lot easier, I think.

No comments: