Exceptional coding style

FG home at fgda.pl
Tue Jan 15 12:23:22 PST 2013


On 2013-01-15 17:00, H. S. Teoh wrote:
> reading the format string alone says nothing about what meaning is
> intended. What is found in a what? Also, it doesn't let you vary the
> word order correctly. Nor does it let you perform inflection correctly.
>
> For true ease of translation, you need:
>
> 1) Logical naming of format arguments, e.g.:
>
> 	"%{filename} is found in %{dirname}"


I agree that named arguments are best -- then you don't require extra comments.
As for argument positioning, it already can be specified, for example "%1$s".



> 2) Some way to indicate the function of each word so that inflection can
> be cone correctly, e.g.:
>
> 	"%{filename.nominative} is found in %{dirname.locative}"
>
> or something like that, in languages where words change form depending
> on function. There will, of course, need to be requisite mechanisms for
> interpreting these word function identifiers.


Filename and dirname don't look like good examples - they don't change.
Well, this is a problem much deeper than providing simple translation, so let's 
drop this for now.



> 3) Some way to indicate multiplicity:
>
> 	"1 file was found" vs. "2 files were found"
>


This is already taken care of in every gettext system I know.
The code would look something like this:

writefln(ngettext("%1$d file found in %2$s", "%1$d files found in %2$s", 2),
     2, "folder X");

where ngettext takes 3 arguments: eng_singular, eng_plural, count.



More information about the Digitalmars-d mailing list