Open GoogleCodeExporter opened 8 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
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
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
Original issue reported on code.google.com by
p...@indeed.com
on 24 Oct 2013 at 2:38Attachments: