本文整理汇总了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));
}