Broken Localization After Moving to @grapecity NPM

Posted by: metrik on 28 May 2019, 12:48 am EST

    • Post Options:
    • Link

    Posted 28 May 2019, 12:48 am EST

    Hello,

    it seems like the localization capabilities got broken after Wijmo was moved to @grapecity NPM section.

    It seems like wijmo.culture property is now exported as getter function (previously it was an ordinary object). As a result it is impossible to apply new culture file because inside all of them do the following:

    window.wijmo.culture={...........};
    

    Setting window.wijmo.culture to another object doesn’t work now. The object remains the same (default, i.e. English culture).

  • Posted 28 May 2019, 7:23 pm EST

    Hello,

    There seem to be no changes in the culture object after NPM upgrade. It is still an ordinary object and any value can be easily assigned to it. The difference is that other culture files are moved to ‘@grapecity/wijmo.cultures’ package in NPM. Please refer to the link below that shows how you can change the culture:

    https://www.grapecity.com/wijmo/docs/GettingStarted/Globalization

    You can also assign an object directly to the culture object. Please refer to the sample attached that demonstrates the same.Culture purejs.zip

  • Posted 28 May 2019, 7:24 pm EST

  • Posted 28 May 2019, 10:59 pm EST

    Hi Abhishek,

    your example works because it uses SystemJS (i.e. no module bundling is happening and wijmo.culture indeed is a plain object). However this is not true for CommonJS modules.

    I have modified your example to work with Webpack and it reproduces the problem (please find attached): culture purejs webpack.zip

    To run the example:

    
    npm install
    npm run build
    
    

    then open ./dist/index.html in browser (launch Chrome with --disable-web-security flag in order to prevent CORS issues).

    Open browser console and you will see an error that “culture is a getter”.

    Looking forward to your assistance!

    Regards,

  • Posted 29 May 2019, 11:46 pm EST

    Hi,

    We are able to replicate the issue at our end so we have forwarded the issue to the concerned team for further investigation. We will give you an update as soon as possible.

    Until this is fixed, you could use the Object.assign method to assign value to the culture object. Please refer to the following code snippet:

    Object.assign(window.wijmo.culture, getCulture());
    
  • Posted 6 June 2019, 9:04 pm EST

    Hi Sharad,

     it seems like the last version of Wijmo (5.20191.615) has got this problem fixed. At least I see that localization is working again.
    

    Although it is still not possible to set window.wijmo.culture directly, now the localization files themselves seem to be working differently. Previously culture files (e.g. wijmo.culture.cs.js) were explicitly setting culture in window:

    window.wijmo.culture = {.....// culture data here};
    

    Now they only put culture data into a variable and then call _updateCulture for this variable. This seems to prevent explicit change of window.wijmo.culture (which is exactly what we need). Could you check this with developers please? Can we consider the problem fixed forever?

    Thanks!

  • Posted 9 June 2019, 6:14 pm EST

    Hi,

    As you have mentioned issue is fixed in the latest release.

    Further, we have asked the dev team for confirmation. We will update you once get an update from the dev team.

    Regards

  • Posted 18 November 2019, 8:22 pm EST

    Hi,

    Here is the comment from the development team:

    [i]The assignment to the top-level module variable is prohibited by the ECMAScript module specification.

    The following code can be used to apply the culture (tested with Wijmo 5.20192.631):

    import * as core from '@grapecity/wijmo';
    ...
    core._updateCulture(getCulture());
    ```[/i]
    
    Regards,
    Manish Gupta
  • Posted 8 June 2020, 3:03 am EST

    Can u provide an example on how to change the wijmo locale dynamically on load? Thanks

  • Posted 8 June 2020, 3:37 pm EST

    Hi Meera,

    Please refer to the demo link below that demonstrates how to change culture dynamically:

    https://www.grapecity.com/wijmo/demos/Core/Globalization/Formatting/purejs

    In this demo, we have used node_modules to update the culture because we use SystemJS loader to load the scripts. But if you are using CDN links (for purejs applications) or webpack (angular, react, etc), then I would suggest you use the CDN link in place of node_modules link in the selectedIndexChanged event of the culture combobox:

    let url = `https://cdn.grapecity.com/wijmo/5.latest/controls/cultures/wijmo.culture.${sender.selectedItem.key}.js`;
    

    Regards,

    Ashwin

  • Posted 8 June 2020, 10:47 pm EST

    Thanks. Its that’s exactly i was looking for,

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels