nciric

Globalization API matchers

Nov 17th, 2011
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Create LocaleList object with well formed list of locales, and save
  2. // languageMatcher for later.
  3. var locales = new LocaleList([...], languageMatcher);
  4.  
  5. // Create DateTimeFormat object.
  6. // Use localeMatcher function to match available locales to |locales|. It would
  7. // also be used for supportedLocalesOf method call.
  8. // Use dateMatcher function to match options to available pattern.
  9. var dtf = new DateTimeFormat(locales, options, dateMatcher);
  10.  
  11. // Both localeMatcher and dateMatcher are optional.
  12. // If they are not specified we use default implementation.
  13. // One of the languageMatcher functions can be 'bcp47' matcher.
  14. // Implementations can implement them as native or JS code.
  15. // Users of the library could implement their own.
  16.  
  17. /*
  18.  * Other way would be to define matchers in global scope:
  19.  */
  20.  
  21. Globalization.languageMatcher = function() {...};
  22. Globalization.dateTimeMatcher = function() {...};
  23.  
  24. // I don't think there are any issues with this approach. Already constructed objects would have already resolved the data.
  25. // New object would use new matchers (in case one changed the matchers during the lifetime of given context).
Advertisement
Add Comment
Please, Sign In to add comment