As Kevin pointed out, the gadget spec only supports one locale per
gadget instance. getLocale()/setLocale()'s usefulness is therefore
questionable.
Datetime/number format patterns are an implementation detail. I don't
think you need to expose them. If you do, please document their
differences from Java/ICU/CLDR's pattern spec.
parseDateTime, strictParseDateTime, and standardParseDateTime are not
well defined. Please consider merging them into one function. You may
add an optional parameter if the parsing mode ("standard" vs.
"strict") is truly important -- which I feel very doubtful.
Time zone, currency etc. are also important components of an i18n
library. Why are they left out?
On Sun, Jun 15, 2008 at 7:07 AM, Shaopeng <jia.sh...@gmail.com> wrote:
>
setLocale/getLocale exist for the purpose of multi-locale support.
They are optional. If multi-locale support is not part of the goal,
this should be removed.
getResource / registerResource are for internal implementation.
registerResource make a resource avaiable and getResource retrieve
the resource. In the original design, single locale support will be
the dominant usage, but resource for multiple locales can be made
available if necessary. Thus we have this 2 funcions. They are very
simple and shouldn't add much overhead.
Please do.
>
> getResource / registerResource are for internal implementation.
> registerResource make a resource avaiable and getResource retrieve
> the resource. In the original design, single locale support will be
> the dominant usage, but resource for multiple locales can be made
> available if necessary. Thus we have this 2 funcions. They are very
> simple and shouldn't add much overhead.
Internal implementation details should not be exposed to the public interface.
I'm confused: You don't want "to push work back to server", yet you
suggest the use of GAE to host time zone data. What's the rationale
behind the decision?
Gadgets API has support for getLang() and getCountry() since the very beginning.
http://code.google.com/apis/opensocial/docs/0.8/reference/gadgets/#gadgets.Prefs
To further clarify, here "multi-locale support" means multiple locales
in single session. The assumption is that for general JS application,
they will stay in one locale for one session. Switching locale
involves a server reload, and thus starts a new session. But for some
applications, they may need to have access to resource from several
locales in one session. For example, an application may choose to
display date in both Japanaese and English on the same page. Such
usage is very rare. It is perfectly fine for Gadgets not to support
such usage. setLocale exists for such usages.
Message bundle can be used to make date/time and number format related
resources available to client, but it might not be the most efficient
way. Resources for date/time formatting are mostly string arrays. If
gadges allows code to be conditionally "linked" based on locale
choice, it might work better to let locale related resource file (js
file) be used directly.
Anyway, those 2 functions are never intended
to be public API. It is purely implementation detail and shouldn't
appear in "specification". Shaopeng's proposal is a design doc
including "specification" and some implementation choices.
Suggestions:
- Remove standardFormatDateTime; accept predefined patterns as the
first parameter of formatDateTime;
- Merge standardParseDateTime and parseDateTime;
- Merge standardFormatNumber and formatNumber;
- Remove all get*Formatter, get*Parser functions. I find them
unnecessary and confusing (e.g. Should developers call parseDateTime
to parse date or get a parser first?)
- Please elaborate on how errors are handled. For example, what
happens when you call
gadgets.i18n.standardParseNumber(gadgets.i18n.CURRENCY_PATTERN, "0,20
€"); if the locale is en-US?
See my comments inlined.
Thanks!
Predefined patterns are often good for average users(of our API, that
>
> Suggestions:
> - Remove standardFormatDateTime; accept predefined patterns as the
> first parameter of formatDateTime;
> - Merge standardParseDateTime and parseDateTime;
> - Merge standardFormatNumber and formatNumber;
is, gadgets developers), but they only cover very limited cases. We
need to give users flexibility to construct patterns when they want to
deal with cases that are not covered by the predefined pattern. For
example, formatting/parsing the date "Jun. 27" is not possible with
predefined date patterns (Year field will always be part of the date
in predefined patterns); this is also true for number formatting.
What I could do is to merge the functions as you suggested, but accept
both predefined patterns and user-constructed patterns as the first
parameter. In this case average users could use the simple API as you
suggested, but power users could construct patterns if they need to.
What do you think?
> - Remove all get*Formatter, get*Parser functions. I find them
> unnecessary and confusing (e.g. Should developers call parseDateTime
> to parse date or get a parser first?)
I am sorry if the documentation is not clear enough, let me try to
clarify here: For one time formatting(which is the majority of the
cases), users just need to use formatDateTime (which creates a
formatter internally to carry out the formatting). For the few cases
where users need to format many dates, repeatedly calling
formatDateTime is very inefficient.
What they could do is to create a
formatter by calling getDateTimeFormatter, then use the formatter to
format date/time by invoking its format() function. The same logic
applies to the parser.
0 will be returned for error cases - I have put this into the API
> - Please elaborate on how errors are handled. For example, what
> happens when you call
> gadgets.i18n.standardParseNumber(gadgets.i18n.CURRENCY_PATTERN, "0,20
> €"); if the locale is en-US?
proposal.
That's what I suggested :)
>
>> - Remove all get*Formatter, get*Parser functions. I find them
>> unnecessary and confusing (e.g. Should developers call parseDateTime
>> to parse date or get a parser first?)
>
> I am sorry if the documentation is not clear enough, let me try to
> clarify here: For one time formatting(which is the majority of the
> cases), users just need to use formatDateTime (which creates a
> formatter internally to carry out the formatting). For the few cases
> where users need to format many dates, repeatedly calling
> formatDateTime is very inefficient. What they could do is to create a
> formatter by calling getDateTimeFormatter, then use the formatter to
> format date/time by invoking its format() function. The same logic
> applies to the parser.
If formatDateTime is inefficient, try to improve it, probably by
caching a repeatedly called parser internally.
Thanks for the great suggestions Kevin and Zhen! I have made changesparameter. You could find the details in the original doc:
to the code to cache formater and parser internally, and now our
interface is much simpler without much compromise on performance. I
have also eliminated those standardFormat*/standardParse* functions by
accepting both string patterns and pre-defined patterns as first
For the error case we discussed, I added a section (section 5) in thePlease let me know if you have any further concerns. After you are ok
doc to explain this in detail.
with the proposal, I will submit the code as a patch to Shindig, so
that gadget developers could benefit from our libraries.
Come 0.9, if it gets at least 5 +1 votes and no -1's, it'll become an
official part of the specification, and -then- you can submit a patch
for shindig.
Shindig's goal is to support / implement the open social
specification, so putting it in shindig before it's part of the spec
would be putting the proverbial cart in front of the horse.
Keep in mind that next to shindig there are other Open Social
implementation(s) too, and if we don't all follow the same spec we'd
make life for gadget developers a lot more difficult .. so everything
like this always starts in the spec first, and then we worry about
implementing it :)
-- Chris
Seeing that we're still hard at work trying to get 0.8 out there i
think 0.9 will probably take a little bit of time, i think it might
take somewhere between 1 to 4 months (was it every half a year?
quarter? Others on the list can probably give you a better overview of
the timeline then i me)
-- Chris
+1