SeaUrchinBot / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

Improved DateTimeSymbol Capabilities #601

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. base.js defines goog.LOCALE as a constant = 'en'
2. datetimesymbols.js uses goog.LOCALE to determine the symbols and formats
3. Becuase goog.LOCALE is a constant, we cannot change the value in order to 
get different DateTime Symbols for different locales.

Proposal
1. Add a static function to datetimesymbols.js that will re-compute the symbol 
and format set given a locale.
2. The static function will use the large if block at the bottom of the code to 
re-assign the symbol set based on the provided locale. (see attached)
3. Make a call to the static function and pass in goog.LOCALE to preserve 
current functionality.

What is the expected output? What do you see instead?
A new static method that can be called from writen scripts that have determined 
the locale of the client and need symbols and formats other than English

Please provide any additional information below.
This is more of a desired improvement rather than a bug.

Note: we cannot accept patches without the contributor license agreement
being signed. See http://code.google.com/p/closure-
library/wiki/Contributors for more info.

Original issue reported on code.google.com by p...@indeed.com on 24 Oct 2013 at 2:38

Attachments:

GoogleCodeExporter commented 9 years ago
Workaround: set DateTimeSymbols and DateTimePatterns

The formatters created capture the current global settings and can be used 
without interfering with each other of the global variables.

Example:
  date = new Date(2013, 10, 15);

  goog.i18n.DateTimePatterns = goog.i18n.DateTimePatterns_fr;
  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_fr;
  var fmtFr = new goog.i18n.DateTimeFormat(
      goog.i18n.DateTimeFormat.Format.FULL_DATE);

  goog.i18n.DateTimePatterns = goog.i18n.DateTimePatterns_de;
  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_de;
  var fmtDe = new goog.i18n.DateTimeFormat(
      goog.i18n.DateTimeFormat.Format.FULL_DATE);

  // The two formatters should return different results (French & German)
  assertEquals('vendredi 15 novembre 2013', fmtFr.format(date));
  assertEquals('Freitag, 15. November 2013', fmtDe.format(date));

Original comment by mn...@google.com on 3 Mar 2014 at 6:41

GoogleCodeExporter commented 9 years ago
If you don't need to switch at runtime, it is possible to set a different 
default: goog.LOCALE is set with goog.define, you can override the default 
value for goog.define values using CLOSURE_DEFINES, just set this prior to 
loading base.js

var CLOSURE_DEFINES = {
  'goog.LOCALE': 'fr'
};

Original comment by johnl...@google.com on 3 Mar 2014 at 6:56

GoogleCodeExporter commented 9 years ago
goog.LOCALE is defined with goog.define (base.js):

* Defines a named value. In uncompiled mode, the value is retrieved from
* CLOSURE_DEFINES or CLOSURE_UNCOMPILED_DEFINES if the object is defined and
* has the property specified, and otherwise used the defined defaultValue.
* When compiled the default can be overridden using the compiler
* options or the value set in the CLOSURE_DEFINES object.

So using CLOSURE_DEFINES or --define at compile time is the intended behavior, 
not a workaround.
Beging done at compile time it allows the compiler optimization to kick in and 
throw away all unused locale data, reducing size a lot.

From base.js:
* @define {string} LOCALE defines the locale being used for compilation. It is
* used to select locale specific data to be compiled in js binary. BUILD rule
* can specify this value by "--define goog.LOCALE=<locale_name>" as JSCompiler
* option.

So I would say that this is not a bug, works as intended.

Original comment by mihn...@gmail.com on 2 Mar 2015 at 5:54