How to use ilib - 10 common examples

To help you get started, we’ve selected a few ilib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enactjs / enact / packages / i18n / locale / locale.js View on Github external
const updateLocale = function (locale) {
	// blow away the cache to force it to reload the manifest files for the new app
	// eslint-disable-next-line no-undefined
	if (ilib._load) ilib._load.manifest = undefined;
	// remove the cache of the platform name to allow transition between snapshot and browser
	delete ilib._platform;
	// load any external ilib/resbundle data
	ilib.data = global.ilibData || ilib.data;
	ilib.data.cache = ilib.data.cache || {};
	ilib.data.cache['ResBundle-strings'] = global.resBundleData || {};
	// ilib handles falsy values and automatically uses local locale when encountered which
	// is expected and desired
	ilib.setLocale(locale);
	const newLocale = ilib.getLocale();
	// Recreate the case mappers to use the just-recently-set locale
	initCaseMappers();

	return newLocale;
};
github enactjs / enact / packages / moonstone / internal / $L / $L.js View on Github external
function createResBundle (options) {
	let opts = options;

	if (typeof ILIB_MOONSTONE_PATH !== 'undefined') {
		opts = {
			loadParams: {
				root: ILIB_MOONSTONE_PATH
			},
			...options
		};
	}

	if (!opts.onLoad) return;

	// Swap out app cache for moonstone's
	const appCache = ilib.data;
	ilib.data = global.moonstoneILibCache || cache;

	// eslint-disable-next-line no-new
	new ResBundle({
		...opts,
		onLoad: (bundle) => {
			ilib.data = appCache;
			opts.onLoad(bundle || null);
		}
	});
}
github enactjs / enact / packages / i18n / locale / locale.js View on Github external
const updateLocale = function (locale) {
	// blow away the cache to force it to reload the manifest files for the new app
	// eslint-disable-next-line no-undefined
	if (ilib._load) ilib._load.manifest = undefined;
	// remove the cache of the platform name to allow transition between snapshot and browser
	delete ilib._platform;
	// load any external ilib/resbundle data
	ilib.data = global.ilibData || ilib.data;
	ilib.data.cache = ilib.data.cache || {};
	ilib.data.cache['ResBundle-strings'] = global.resBundleData || {};
	// ilib handles falsy values and automatically uses local locale when encountered which
	// is expected and desired
	ilib.setLocale(locale);
	const newLocale = ilib.getLocale();
	// Recreate the case mappers to use the just-recently-set locale
	initCaseMappers();

	return newLocale;
};
github enactjs / enact / packages / i18n / locale / locale.js View on Github external
const updateLocale = function (locale) {
	// blow away the cache to force it to reload the manifest files for the new app
	// eslint-disable-next-line no-undefined
	if (ilib._load) ilib._load.manifest = undefined;
	// remove the cache of the platform name to allow transition between snapshot and browser
	delete ilib._platform;
	// load any external ilib/resbundle data
	ilib.data = global.ilibData || ilib.data;
	ilib.data.cache = ilib.data.cache || {};
	ilib.data.cache['ResBundle-strings'] = global.resBundleData || {};
	// ilib handles falsy values and automatically uses local locale when encountered which
	// is expected and desired
	ilib.setLocale(locale);
	const newLocale = ilib.getLocale();
	// Recreate the case mappers to use the just-recently-set locale
	initCaseMappers();

	return newLocale;
};
github enactjs / enact / packages / moonstone / internal / $L / $L.js View on Github external
let opts = options;

	if (typeof ILIB_MOONSTONE_PATH !== 'undefined') {
		opts = {
			loadParams: {
				root: ILIB_MOONSTONE_PATH
			},
			...options
		};
	}

	if (!opts.onLoad) return;

	// Swap out app cache for moonstone's
	const appCache = ilib.data;
	ilib.data = global.moonstoneILibCache || cache;

	// eslint-disable-next-line no-new
	new ResBundle({
		...opts,
		onLoad: (bundle) => {
			ilib.data = appCache;
			opts.onLoad(bundle || null);
		}
	});
}
github enactjs / enact / packages / moonstone / TimePicker / TimePickerController.js View on Github external
type: 'time',
				useNative: false,
				timezone: 'local',
				length: 'full',
				date: 'dmwy'
			};

			this.timeFormat = new DateFmt(format);

			const meridiemFormat = {
				template: 'a',
				useNative: false,
				timezone: 'local'
			};

			const merFormatter = new DateFmt(meridiemFormat);
			const meridiems = merFormatter.getMeridiemsRange(meridiemFormat);
			this.meridiemRanges = meridiems.map(calcMeridiemRange);
			this.meridiemLabels = meridiems.map(obj => obj.name);

			// Set picker format 12 vs 24 hour clock
			const li = new LocaleInfo();
			const clockPref = li.getClock();
			this.meridiemEnabled = clockPref === '12';

			const filter = this.meridiemEnabled ? includeMeridiem : excludeMeridiem;
			this.order = this.timeFormat.getTemplate().match(filter).map(s => s[0].toLowerCase());

			const timeFormat = {
				type: 'time',
				time: 'h',
				useNative: false,
github enactjs / enact / packages / moonstone / TimePicker / TimePickerController.js View on Github external
initI18n () {
		const locale = ilib.getLocale();

		if (this.locale !== locale && typeof window === 'object') {
			this.locale = locale;

			const format = {
				type: 'time',
				useNative: false,
				timezone: 'local',
				length: 'full',
				date: 'dmwy'
			};

			this.timeFormat = new DateFmt(format);

			const meridiemFormat = {
				template: 'a',
				useNative: false,
				timezone: 'local'
			};

			const merFormatter = new DateFmt(meridiemFormat);
			const meridiems = merFormatter.getMeridiemsRange(meridiemFormat);
			this.meridiemRanges = meridiems.map(calcMeridiemRange);
			this.meridiemLabels = meridiems.map(obj => obj.name);

			// Set picker format 12 vs 24 hour clock
			const li = new LocaleInfo();
			const clockPref = li.getClock();
			this.meridiemEnabled = clockPref === '12';
github enactjs / enact / packages / moonstone / TimePicker / TimePicker.js View on Github external
onChangeHour: function (ev, value) {
			const currentTime = DateFactory(value).getTimeExtended();
			const currentHour = value.hour;

			value.hour = ev.value;

			// In the case of navigating onto the skipped hour of DST, ilib will return the same
			// value so we skip that hour and update the value again.
			const newTime = DateFactory(value).getTimeExtended();
			if (newTime === currentTime) {
				value.hour = ev.value * 2 - currentHour;
			}

			return value;
		},
github enactjs / enact / packages / i18n / locale / locale.js View on Github external
function isRtlLocale (options = {}) {
	const {onLoad, sync} = options;

	if (!onLoad) return;

	// eslint-disable-next-line no-new
	new LocaleInfo(ilib.getLocale(), {
		...options,
		onLoad: (li) => {
			const scriptName = li.getScript();
			// eslint-disable-next-line no-new
			new ScriptInfo(scriptName, {
				sync,
				onLoad: (script) => {
					onLoad(script.getScriptDirection() === 'rtl');
				}
			});
		}
	});
}
github enactjs / enact / packages / i18n / I18nDecorator / getI18nClasses.js View on Github external
function getI18nClasses (options = {}) {
	const {sync, onLoad} = options;
	if (!onLoad) return;

	// eslint-disable-next-line no-new,no-undefined
	new LocaleInfo(undefined, {
		sync,
		onLoad: (li) => getClassesForLocale(li, {
			...options,
			onLoad
		})
	}); // for the current locale
}