Search code examples
angularwebpacksyncfusion

Internationalization in Syncfusion Ej2 with WebPack


I'm trying to use the internationalization features of Syncfusion EJ2 in Angular-Cli with WebPack, which is problematic because all the documentation uses SystemJs.

In particular I'm trying to use this sample

import { L10n, loadCldr, setCulture, setCurrencyCode } from '@syncfusion/ej2-base';
import * as currencies from './currencies.json';
import * as cagregorian from './ca-gregorian.json';
import * as numbers from './numbers.json';
import * as timeZoneNames from './timeZoneNames.json';
import * as numberingSystems from './numberingSystems.json';
import { Component, OnInit } from '@angular/core';
import { data } from './datasource';

loadCldr(currencies, cagregorian, numbers, timeZoneNames, numberingSystems);

setCulture('de-DE');
setCurrencyCode('EUR');

I tried but could not make it to work, I'm stuck on this error:

 Cannot find module './numberingSystems.json'

Which changes should I make to the sample?


Solution

  • In order to import the json files in the typescript, we need to include the json type in the wildcard card module declaration( https://www.typescriptlang.org/docs/handbook/modules.html#wildcard-module-declarations ). Use the below declaration code in the typings.d.ts file to resolve the compilation issue.

    declare module "*.json" {
      const value: any;
      export default value;
    }
    

    Note: You can also use the cldr json files by installing the npm package cldr-data. This package contains all cultures json files.