當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript os-locale.sync函數代碼示例

本文整理匯總了TypeScript中os-locale.sync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript sync函數的具體用法?TypeScript sync怎麽用?TypeScript sync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了sync函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

export const setOrDetectLocale = (locale: Maybe<string>) => {
  let how = LocalType.Specified;
  if (!locale) {
    how = LocalType.Detected;
    locale = osLocale.sync();
  }
  locale = locale.substr(0, 2);
  if (!isSupported(locale)) {
    console.warn(colors.yellow(`===== locale ${locale} ${how} but not supported, default: en =====`));
    return;
  }
  i18n.setLocale(locale);
};
開發者ID:iurimatias,項目名稱:embark-framework,代碼行數:13,代碼來源:i18n.ts

示例2: osLocale

/// <reference path="./os-locale.d.ts" />

import osLocale, { sync } from 'os-locale';

osLocale((err: any, locale: string) => {
});

osLocale({spawn: false}, (err: any, locale: string) => {
});

var locale1: string = sync();
var locale2: string = sync({spawn: false});
開發者ID:0815fox,項目名稱:DefinitelyTyped,代碼行數:12,代碼來源:os-locale-tests.ts

示例3: osLocale

/// <reference path="./os-locale.d.ts" />

import osLocale, { sync } from 'os-locale';

osLocale((err: any, locale: string) => {
});

var locale: string = sync();
開發者ID:ErykB2000,項目名稱:DefinitelyTyped,代碼行數:8,代碼來源:os-locale-tests.ts

示例4: require

import * as osLocale from 'os-locale';
import * as util from 'util';
let locale;
/* tslint:disable:no-var-requires */
try {
	locale = require(`../locales/${osLocale.sync()}.json`);
} catch (ex) {
	locale = require('../locales/en.json');
}
/* tslint:enable:no-var-requires */
export = (str: string, ...args) => {
	return util.format(locale[str] || str, ...args);
};
開發者ID:jedmao,項目名稱:eclint,代碼行數:13,代碼來源:i18n.ts

示例5: osLocale

export default function installI18N() {
	if (locale) {
		return;
	}
	locale = osLocale();
	locale = locale.toLowerCase().replace(/_/g, '-');
	if (locale === 'posix') {
		locale = 'en-us';
	}
	
	let langFile = localeFilePath(locale);
	if (!existsSync(require('path').resolve(__dirname, langFile))) {
		console.warn(`Warn: no language file for ${locale}, fallback to en.`);
		locale = 'en-us';
		langFile = localeFilePath(locale);
	}
	global.t = getTextFn(locale, require(langFile));
}
開發者ID:GongT,項目名稱:jenv,代碼行數:18,代碼來源:i18n.ts


注:本文中的os-locale.sync函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。