Ideal D GUI Toolkit

Adam D. Ruppe destructionator at gmail.com
Wed May 22 18:23:38 PDT 2013


I've never actually done i18n so I might be full of crap, but I 
think a nice way to do it would be something along these lines:

1) (optionally) all printing functions actually take a different 
type than just plain string, forcing you to use the translation 
function

2) the function looks something like this:

PrintableString tr(string fmt, T...)(T t) {
     version(getstrings)
          pragma(msg, "string: " ~ fmt);
     return PrintableString(format(translation[lang][fmt], t));
}


So if you compile with -version=getstrings, the output from dmd 
can then be used to make your translation key file. It takes a 
format string so the translator can use positional arguments if 
they need to be reordered.

I've got half a mind to make those params commentable too so you 
can name them or something but not sure how to do that without 
being annoying. Maybe they can be alias arguments to the 
template, and then use stringof to get the variable name and 
annotations, but idk.


More information about the Digitalmars-d mailing list