本文整理汇总了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;未经允许,请勿转载。 |
请发表评论