We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Dynamic Globalization

Thread ID:

Created:

Updated:

Platform:

Replies:

144932 May 29,2019 09:58 AM UTC May 30,2019 10:38 AM UTC Angular 1
loading
Tags: ejDatePicker
Louis Goh Boon Kuan
Asked On May 29, 2019 09:58 AM UTC


Hi,

The code below works.  I would like the user to be able to change the language of their choice.  The loadCldr from the example is static and how do I make that selective at runtime.  Thank you.


import { EmitType } from '@syncfusion/ej2-base';
import { L10n, loadCldr } from '@syncfusion/ej2-base';
import * as L10nJson from '../../assets/l10n.json';
import { SwitchComponent } from '@syncfusion/ej2-angular-buttons';
import { DataManager, ODataV4Adaptor } from '@syncfusion/ej2-data';
import { DatePickerComponent } from '@syncfusion/ej2-angular-calendars';


L10n.load(L10nJson.default)
loadCldr(
require('cldr-data/main/zh/numbers.json'),
require('cldr-data/main/zh/ca-gregorian.json'),
require('cldr-data/main/zh/numbers.json'),
require('cldr-data/supplemental/numberingSystems.json'),
require('cldr-data/main/zh/timeZoneNames.json')
);

Ashokkumar Balasubramanian [Syncfusion]
Replied On May 30, 2019 10:38 AM UTC

Hi Louis Goh Boon Kuan, 
 
Good day to you. 
 
You can use the Ajax and setCulture method to load the corresponding culture in dynamically. Please refer the below code block. 
 
public onChange(args: any): void { 
    if(this.loadedCultures.indexOf(args.value) === -1) { 
        this.loadedCultures.push(args.value); 
        this.loadCultureFiles(args.value); 
    } 
    setCulture(args.value); 
} 
 
//Function for loading locale files based on culture name 
loadLocaleFiles(name: string) { 
    // load local files 
    let localeajax: Ajax = new Ajax('./node_modules/@syncfusion/ej2-locale/src/' + name + '.json', 'GET', false); 
    localeajax.onSuccess = (value: string) => { 
        L10n.load(JSON.parse(value)); 
    } 
    localeajax.send(); 
} 
// Function for loading the culture files from cldr-data. 
loadCultureFiles(name: string) { 
 
    this.loadLocaleFiles(name); 
    // since default culture files are preloaded no need to load the files again. 
    if(name === 'en-US'){ 
        return; 
    } 
    let files: string[] = ['ca-gregorian.json', 'numbers.json', 'timeZoneNames.json', 'numberingSystems.json']; 
 
    let loadCulture = function (prop: any) { 
        let val: string, ajax: Ajax; 
        if (prop === files.length - 1) { 
            ajax = new Ajax('./node_modules/cldr-data/supplemental/' + files[prop], 'GET', false); 
        } else { 
            ajax = new Ajax('./node_modules/cldr-data/main/' + name + '/' + files[prop], 'GET', false); 
        } 
        ajax.onSuccess = function (value: any) { 
            val = value; 
            loadCldr(JSON.parse(val)); 
        }; 
        ajax.send(); 
 
    }; 
    for (let prop = 0; prop < files.length; prop++) { 
        loadCulture(prop); 
    } 
} 
 
For your reference, we have prepared the sample for this requirement, please find it below. 
 
 
Steps to run the sample: 
 
npm install 
npm start 
 
Please check the sample and get back to us, if you need any further assistance on this. 
 
Regards, 
Ashokkumar B. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon