本文整理匯總了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);
};
示例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});
示例3: osLocale
/// <reference path="./os-locale.d.ts" />
import osLocale, { sync } from 'os-locale';
osLocale((err: any, locale: string) => {
});
var locale: string = sync();
示例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);
};
示例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));
}