PolymerElements / app-localize-behavior

Polymer behaviour to help internationalize your application
48 stars 54 forks source link

Cannot set property 'IntlMessageFormat' of undefined #127

Closed jfdumont closed 6 years ago

jfdumont commented 6 years ago

Description

with polymer-3-starter-kit fresh install

npm install --save @polymer/app-localize-behavior@next
>npm WARN @babel/plugin-transform-classes@7.0.0-beta.35 requires a peer of @babel/core@7.0.0-beta.35 but none is installed 

added to my-view1.js

import {AppLocalizeBehavior} from '@polymer/app-localize-behavior/app-localize-behavior.js';
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
...
class MyApp extends mixinBehaviors([AppLocalizeBehavior], PolymerElement) {
...
<div>{{localize('hello', 'name', 'Batman')}}</div>
...
  constructor() {
    super();
    // set default language and localization strings
    this.language = 'en';
    this.resources = {
      'en': { 'hello': 'My name is {name}.' },
      'fr': { 'hello': 'Je m\'apelle {name}.' }
    };
  }

Actual outcome

chrome console when loading page : Uncaught TypeError: Cannot set property 'IntlMessageFormat' of undefined at parser.js:586 at parser.js:586

Translation works on Firefox

Browsers Affected

lequem commented 6 years ago

+1

sebagr commented 6 years ago

+1, can't upgrade my project from Polymer 2 to Polymer 3 until this is fixed :(

I suspect it has something to do with intl-messageformat.js:

(function() {
// ...
}).call(this);

After bundling, this seems to be undefined.

notwaldorf commented 6 years ago

cc @e111077

e111077 commented 6 years ago

Hello, this is because of a bunk version of released app-localize-behavior. The previous release worked just fine. You might want to pin your version to3.0.0-pre.17. I'll udpate this thread when we release the fixed version again

e111077 commented 6 years ago

Note: this version will also require you to include the yahoo/intl-messageformat polyfill manually

DrNiels commented 6 years ago

+1

xw901103 commented 6 years ago

this still occurs in 3.0.0-pre.19. temporary solution would be modify the end of intl-messageformat.min.js from .call(this) to .call(window)

e111077 commented 6 years ago

Hello, we have decoupled the polyfill from the element in @latest pre.21. (@next pre.20 is still broken)

This means that you will have to manually include the polyfill in a script tag of the page that is using this element for non FF browsers.

This will most-likely be the last prerelease before we manually comb through the elements and fix them up for 3.0.0