Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 280
James Gordon Avatar asked Sep 15 '17 04:09

James Gordon


People also ask

What does Webpack do with JavaScript?

Webpack is a powerful module bundler which building a dependency graph, and emitting one or more bundles. With plugin and rules, Webpack can preprocess and minify different non-JavaScript files such as TypeScript, SASS, and LESS files. We can determine what Webpack does and how it does it with a JavaScript configuration file.

How to get started with essential JS 1 for angular with Webpack?

Getting started with Essential JS 1 for Angular with Webpack. To quick start with Syncfusion JavaScript Angular components run the below commands to clone the repository for Webpack starter and installing required dependency packages.

What is ej-angular2 cloned application?

The cloned application already configured with ej-angular2 library to seamlessly work with Angular and Essential JavaScript components. The below steps describe, how the library consumed in the Angular seed application.


1 Answers

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.

like image 119
Mydeen sn Avatar answered Oct 23 '22 12:10

Mydeen sn