Re: Strings again

"Mark Hahn" <[email protected]>
Newsgroups gmane.comp.lang.prothon.user
Message-ID <[email protected]>
Roger Binns wrote:

> I just want to make it clear that a scheme such as _() or equivalents
> only does a tiny part of the job.  In particular you have to also deal
> with the issue that order of formatting changes.  As a simple example
> you may say this in english:
>
>   "%d of %d items imported" % (current, total)
>
> Whereas in another language it would be written the other way round:
>
>   "jkjh dfgd %d gfdg %d" % (total, current)
>
> The latter is common in Japanese.
>
> The above can't be simply resolved by looking up the format string.
> (Yes, you could supply dicts and other stuff but people don't and
> before you know it, your standard library is full of stuff that
> can't be internationalised/localised).

Are you familiar with Prothon's replacement for % ?  Check out:
http://prothon.org/wiki?pagename=String.fmt%28%29

It can easily handle the problem you pose here since it offers positional
numbering:

O>> current = 10; total = 50
O>> "We have shipped {0} of the {1} total".fmt(current,total)
We have shipped 10 of the 50 total
O>> "Of the {1} total, {0} have been shipped".fmt(current,total)
Of the 50 total, 10 have been shipped
O>>

> What I was suggesting was that the code looks as close as possible
> to this:
>
>    print MAGIC, current, total
>
> And behind the scenes the lookup happens (with defaults or whatever).
> But that also allows you to suddenly do a lot better.  For example
> shouldn't I trivially be able to make it output in XML or HTML
> or whatever format is common next year without having to write
> seperate code for each output format?  MAGIC would just "do the
> right thing" including doing the right output format, as well
> as deal with the localisation issues.  The reason for making it
> compulsory would be to ensure that all code does the outputting
> "correctly".

Our new String.fmt() uses the str_ function to process the spec.  It could
output in xml or html.

> Here is the true test.  Take a sample "Hello World" program
> and also have it output todays date, and how many days of the
> month have passed as a percentage.
>
> How much extra effort (just on the coding side) is it to also
> output in German?  Japanese? Hebrew? Arabic?  HTML?  XML?
> teletype?
>
> For the next generation of languages I believe the answer
> is going to be "none".

I think the combination of our String.fmt() and the proposed _"xxx" format
strings could do the job, once the other elements of Prothon (html, xml,
date functions, etc.) are complete.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.