Search results

Globalization

Globalization is the combination of internalization and localization. You can adapt the component to various languages by parsing and formatting the date or number Internationalization and also add culture specific customization and translation to the text localization.

By default, Calendar date format, week and month names are specific to American English culture. It utilizes the Essential JavaScript 2 Internationalization package to parse and format the date object based on the culture by uses the official UNICODE CLDR JSON data and also it provides the loadCldr method to load the culture specific CLDR JSON data.

To go with the different culture other than English, follow the below steps.

  • Install the CLDR-Data package by using the below command (it installs the CLDR JSON data). To know more about CLDR-Data refer the CLDR-Data link.
npm install cldr-data --save

Once the package installed, you can find the culture specific JSON data under the location \node_modules\cldr-data.

  • Now import the installed CLDR JSON data into the app.ts file. To import JSON data we need to install the JSON plugin loader. Here we have used the SystemJS JSON plugin loader.
npm install systemjs-plugin-json --save-dev
  • Once installed, configure the system.config.js configuration settings as like below to map the systemjs-plugin-json loader.
/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/',
      "syncfusion:": "node_modules/@syncfusion/", // syncfusion alias

    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      'app': 'app',

      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

      // syncfusion bundles
      "@syncfusion/ej2-base": "syncfusion:ej2-base/dist/ej2-base.umd.min.js",
      "@syncfusion/ej2-data": "syncfusion:ej2-data/dist/ej2-data.umd.min.js",
      "@syncfusion/ej2-calendars": "syncfusion:ej2-calendars/dist/ej2-calendars.umd.min.js",
      "@syncfusion/ej2-angular-base": "syncfusion:ej2-angular-base/dist/ej2-angular-base.umd.min.js",
      "@syncfusion/ej2-angular-calendars": "syncfusion:ej2-angular-calendars/dist/ej2-angular-calendars.umd.min.js",
      "@syncfusion/ej2-inputs": "syncfusion:ej2-inputs/dist/ej2-inputs.umd.min.js",
      "@syncfusion/ej2-buttons": "syncfusion:ej2-buttons/dist/ej2-buttons.umd.min.js",
      "@syncfusion/ej2-splitbuttons": "syncfusion:ej2-splitbuttons/dist/ej2-splitbuttons.umd.min.js",
      "@syncfusion/ej2-lists": "syncfusion:ej2-lists/dist/ej2-lists.umd.min.js",
      "@syncfusion/ej2-popups": "syncfusion:ej2-popups/dist/ej2-popups.umd.min.js",
      "cldr-data": 'npm:cldr-data',
      "plugin-json": "npm:systemjs-plugin-json/json.js",

      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
    },
      meta: {
        '*.json': { loader: 'plugin-json' }
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        defaultExtension: 'js',
        meta: {
          './*.js': {
            loader: 'systemjs-angular-loader.js'
          }
        }
      },
      "cldr-data": { main: 'index.js', defaultExtension: 'js' },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);
  • Now use the loadCldr method to load the culture specific CLDR JSON data from the installed location to app.ts file as like the below code example.
//import the loadCldr from ej2-base
import { loadCldr} from '@syncfusion/ej2-base';

declare var require: any;

loadCldr(
    require('cldr-data/supplemental/numberingSystems.json'),
    require('cldr-data/main/de/ca-gregorian.json'),
    require('cldr-data/main/de/numbers.json'));
    require('cldr-data/main/de/timeZoneNames.json'));

The Localization library allows you to localize default text content of the Calendar. The Calendar component has static text for today feature that can be changed to other cultures (Arabic, Deutsch, French, etc.) by defining the locale value and translation object.

Locale keywords Text
today Name of the button to choose Today date.
  • Before changing to a culture other than English, ensure that locale text for the concerned culture is loaded through load method of L10n class.
//Load the L10n, loadCldr from ej2-base
import { loadCldr, L10n } from "@syncfusion/ej2-base";

//load the locale object to set the localized placeholder value
L10n.load({
  de: {
    calendar: {
              today:"heute"
 }
  }
});
  • Set the culture by using the locale property. The below code example, initialize the Calendar component in German culture.
import { Component } from '@angular/core';
import { Calendar } from '@syncfusion/ej2-calendars';
//import the loadCldr from ej2-base
import { loadCldr, L10n } from '@syncfusion/ej2-base';

declare var require: any;

loadCldr(
    require('cldr-data/supplemental/numberingSystems.json'),
    require('cldr-data/main/de/ca-gregorian.json'),
    require('cldr-data/main/de/numbers.json'));
    require('cldr-data/main/de/timeZoneNames.json'));
@Component({
    selector: 'app-container',
    template: `
    <!-- Sets the value, locale -->
    <ejs-calendar [value]='dateValue' locale='de'></ejs-calendar>`
})

export class AppComponent {
    public dateValue: Object = new Date();
     ngOnInit(): void {
    /*loads the localization text*/
    L10n.load({
      'de': {
        'calendar': {
           today:"heute"
        }
      }
    });
  }
    constructor() {
    }
}

The following example demonstrates the Calendar in German culture.

Source
Preview
app.component.ts
app.module.ts
main.ts
import { Component } from '@angular/core';
import { loadCldr, L10n } from '@syncfusion/ej2-base';
import * as numberingSystems from './numberingSystems.json';
import * as gregorian from './ca-gregorian.json';
import * as numbers from './numbers.json';
import * as timeZoneNames from './timeZoneNames.json';

loadCldr(numberingSystems, gregorian, numbers, timeZoneNames);

@Component({
    selector: 'app-container',
    template: `
    <!-- Sets the value, locale -->
    <ejs-calendar [value]='dateValue' locale='de'></ejs-calendar>`
})

export class AppComponent {
   public dateValue: Object = new Date();
    ngOnInit(): void {
    /*loads the localization text*/
    L10n.load({
      'de': {
        'calendar': {
           today:"heute"
        }
      }
    });
  }
    constructor() {
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
//Syncfusion ej2-angular-calendars module
import { CalendarModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';


/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        CalendarModule //declaration of ej2-angular-calendars module into NgModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Right-To-Left

The Calendar supports right-to-left functionality for languages like Arabic, Hebrew to displays the text in the right-to-left direction. Use enableRtl property to set the RTL direction.

The following example demonstrates the Calendar in Arabic culture with enableRtl property.

Source
Preview
app.component.ts
app.module.ts
main.ts
import { Component } from '@angular/core';
import { loadCldr, L10n} from '@syncfusion/ej2-base';
import * as numberingSystems from './numberingSystems.json';
import * as gregorian from './ca-gregorian.json';
import * as numbers from './numbers.json';
import * as timeZoneNames from './timeZoneNames.json';

loadCldr(numberingSystems, gregorian, numbers, timeZoneNames);

@Component({
    selector: 'app-container',
    template: `
         <!-- Sets the value, locale,enableRtl -->
        <ejs-calendar [value]='dateValue' locale='ar' enableRtl='true'></ejs-calendar>
        `
})

export class AppComponent {
   public dateValue: Object = new Date();
    ngOnInit(): void {
       L10n.load({
        'ar': {
          'calendar': { today: "اليوم"}
        }
      });
    }
    constructor() {
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
//Syncfusion ej2-angular-calendars module
import { CalendarModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';


/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        CalendarModule //declaration of ej2-angular-calendars module into NgModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);