UNPKG

@duoduo-oba/ng-devui

Version:

DevUI components based on Angular

473 lines (461 loc) 14.3 kB
import { Injectable, ɵɵdefineInjectable, Pipe, NgModule } from '@angular/core'; import { Subject } from 'rxjs'; import { getLocaleId, formatDate } from '@angular/common'; /** * @fileoverview added by tsickle * Generated from: i18n.model.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function I18nInterface() { } if (false) { /** @type {?} */ I18nInterface.prototype.locale; /** @type {?} */ I18nInterface.prototype.common; /** @type {?} */ I18nInterface.prototype.datePicker; /** @type {?} */ I18nInterface.prototype.pagination; /** @type {?} */ I18nInterface.prototype.upload; /** @type {?} */ I18nInterface.prototype.modal; } /** * @fileoverview added by tsickle * Generated from: zh-cn.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var zhCN = { locale: 'zh-cn', common: { searchPlaceholder: '请输入关键字', noData: '没有数据', noRecordsFound: '找不到相关记录', btnConfirm: '确定', loading: '加载中...', checkAll: '全选', btnOk: '确定' }, datePicker: { today: '今天', clear: '清除', daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'], monthsOfYear: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], }, pagination: { totalItem: '所有条目', goTo: '跳至', pageSize: '每页条数' }, upload: { upload: '上传', chooseFile: '选择文件', chooseFiles: '选择多个文件', preload: '预加载', uploading: '上传中...', uploaded: '已上传', uploadFailed: '上传失败', delete: '删除', /** * @param {?} filename * @param {?} scope * @return {?} */ getNotAllowedFileTypeMsg(filename, scope) { return `您上传的文件"${filename}"不在允许范围"${scope}"内,请重新选择文件`; }, /** * @param {?} filename * @param {?} maximalSize * @return {?} */ getBeyondMaximalFileSizeMsg(filename, maximalSize) { return `您上传的文件"${filename}"大小超过最大限制${maximalSize}M,请重新选择文件`; }, /** * @param {?} sameNames * @return {?} */ getExistSameNameFilesMsg(sameNames) { return `您上传的 "${sameNames}" 存在重名文件 ,请重新选择文件`; } }, modal: { warning: '提醒', error: '错误', info: '提示' } }; /** * @fileoverview added by tsickle * Generated from: en-us.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var enUS = { locale: 'en-us', common: { searchPlaceholder: 'Enter a keyword.', noData: 'No data available.', noRecordsFound: 'No records found.', btnConfirm: 'Confirm', loading: 'Loading...', checkAll: 'All', btnOk: 'OK' }, datePicker: { today: 'Today', clear: 'Clear', daysOfWeek: ['Sun', 'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat'], monthsOfYear: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], }, pagination: { totalItem: 'Total Records', goTo: 'Go To', pageSize: 'Page Size' }, upload: { upload: 'Upload', chooseFile: '--select--', chooseFiles: '--select--', preload: 'Selected', uploading: 'Uploading...', uploaded: 'Upload successful', uploadFailed: 'Upload Failed', delete: 'Delete', /** * @param {?} filename * @param {?} scope * @return {?} */ getNotAllowedFileTypeMsg(filename, scope) { return `Files with unsupported types: ${filename}. Supported file types: ${scope}`; }, /** * @param {?} filename * @param {?} maximalSize * @return {?} */ getBeyondMaximalFileSizeMsg(filename, maximalSize) { return `Maximum file size (MB): ${maximalSize}. Files whose size exceeds the maximum value: ${filename}`; }, /** * @param {?} sameNames * @return {?} */ getExistSameNameFilesMsg(sameNames) { return `Duplicate files exist : "${sameNames}"`; } }, modal: { warning: 'Warning', error: 'Error', info: 'Information' } }; /** * @fileoverview added by tsickle * Generated from: i18n.service.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class I18nService { constructor() { this.i18nConfig = { 'zh-cn': zhCN, 'en-us': enUS }; this.i18nSubject = new Subject(); } /** * @param {?=} lang * @return {?} */ toggleLang(lang = 'zh-cn') { localStorage.setItem('lang', lang); this.i18nSubject.next(this.getI18nText()); } /** * @return {?} */ getI18nText() { /** @type {?} */ const lang = localStorage.getItem('lang') ? localStorage.getItem('lang').toLocaleLowerCase() : 'zh-cn'; if (this.i18nConfig.hasOwnProperty(lang)) { return this.i18nConfig[lang]; } else { return zhCN; } } /** * @return {?} */ langChange() { return this.i18nSubject.asObservable(); } } I18nService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ I18nService.ngInjectableDef = ɵɵdefineInjectable({ factory: function I18nService_Factory() { return new I18nService(); }, token: I18nService, providedIn: "root" }); if (false) { /** * @type {?} * @private */ I18nService.prototype.i18nConfig; /** * @type {?} * @private */ I18nService.prototype.i18nSubject; } /** * @fileoverview added by tsickle * Generated from: i18n.util.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class I18nUtil { /** * @return {?} */ static getCurrentLanguage() { /** @type {?} */ let lang = localStorage.getItem('lang'); if (I18nUtil.supportLanguages.indexOf(lang) < 0) { lang = I18nUtil.supportLanguages[0]; } return lang; } /** * @return {?} */ static getSupportLanguages() { return I18nUtil.supportLanguages; } } I18nUtil.supportLanguages = ['zh-cn', 'en-us', 'ru-ru']; if (false) { /** * @type {?} * @private */ I18nUtil.supportLanguages; } /** * @fileoverview added by tsickle * Generated from: i18n.format.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class I18nFormat { // 通过get方法来做业务没有指定locale的时候fallback /** * @private * @param {?} locale * @return {?} */ static getLocaleAndLang(locale) { /** @type {?} */ const currentLanguage = I18nUtil.getCurrentLanguage(); /** @type {?} */ let localeId; try { // 通过get方法来判断是否存在locale getLocaleId(locale); localeId = (locale || I18nFormat.DEFAULT_LOCALE).toLocaleLowerCase(); } catch (error) { localeId = I18nFormat.DEFAULT_LOCALE; } return { localeId, currentLanguage }; } // 短格式:y/MM/dd /** * @param {?} value * @param {?=} format * @param {?=} locale * @param {?=} timezone * @return {?} */ static formatDate(value, format, locale, timezone) { /** @type {?} */ const localeLang = I18nFormat.getLocaleAndLang(locale); /** @type {?} */ const formatStr = format ? format : I18nFormat.localFormat[localeLang.currentLanguage].short; return formatDate(value, formatStr, localeLang.localeId, timezone); } // 完整格式:y/MM/dd hh:mm:ss zzzz /** * @param {?} value * @param {?=} format * @param {?=} locale * @param {?=} timezone * @return {?} */ static formatDateTime(value, format, locale, timezone) { /** @type {?} */ const localeLang = I18nFormat.getLocaleAndLang(locale); /** @type {?} */ const formatStr = format ? format : I18nFormat.localFormat[localeLang.currentLanguage].full; return formatDate(value, formatStr, localeLang.localeId, timezone); } // 完整格式不加GMT:y/MM/dd hh:mm:ss /** * @param {?} value * @param {?=} format * @param {?=} locale * @param {?=} timezone * @return {?} */ static formatDateTimeWithoutGMT(value, format, locale, timezone) { /** @type {?} */ const localeLang = I18nFormat.getLocaleAndLang(locale); // 非用户传入的format,就替换掉完整的格式化字符中中GMT信息 /** @type {?} */ const formatStr = format ? format : (I18nFormat.localFormat[localeLang.currentLanguage].full).replace(' zzzz', ''); return formatDate(value, formatStr, localeLang.localeId, timezone); } } // 默认locale使用英文,因为angular默认只支持英文,其他的需要显示注册 I18nFormat.DEFAULT_LOCALE = 'en-us'; I18nFormat.DATETIME_FORMAT_EN = 'MMM dd, y HH:mm:ss zzzz'; I18nFormat.DATETIME_FORMAT_ZH = 'y/MM/dd HH:mm:ss zzzz'; I18nFormat.DATETIME_FORMAT_RU = 'dd.MM.y HH:mm:ss zzzz'; I18nFormat.DATE_FORMAT_EN = 'MMM dd, y'; I18nFormat.DATE_FORMAT_ZH = 'y/MM/dd'; I18nFormat.DATE_FORMAT_RU = 'dd.MM.y'; I18nFormat.localFormat = { 'zh-cn': { full: I18nFormat.DATETIME_FORMAT_ZH, short: I18nFormat.DATE_FORMAT_ZH }, 'en-us': { full: I18nFormat.DATETIME_FORMAT_EN, short: I18nFormat.DATE_FORMAT_EN }, 'ru-ru': { full: I18nFormat.DATETIME_FORMAT_RU, short: I18nFormat.DATE_FORMAT_RU } }; if (false) { /** * @type {?} * @private */ I18nFormat.DEFAULT_LOCALE; /** * @type {?} * @private */ I18nFormat.DATETIME_FORMAT_EN; /** * @type {?} * @private */ I18nFormat.DATETIME_FORMAT_ZH; /** * @type {?} * @private */ I18nFormat.DATETIME_FORMAT_RU; /** * @type {?} * @private */ I18nFormat.DATE_FORMAT_EN; /** * @type {?} * @private */ I18nFormat.DATE_FORMAT_ZH; /** * @type {?} * @private */ I18nFormat.DATE_FORMAT_RU; /** * @type {?} * @private */ I18nFormat.localFormat; } /** * @fileoverview added by tsickle * Generated from: i18n-date.pipe.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class I18nDatePipe { /** * 使用方式参考:{{dateObj | i18nDate:'full':false}} 参数可选 * @param {?} value 日期表达式,字符串、数字或者日期对象. * @param {?=} format 格式化表达式, 使用 'full','short'或者自定义格式化表达式. * @param {?=} withGMT 是否包含GMT信息,默认包含,只对完整日期有效 * @return {?} 返回格式化后的字符串. */ transform(value, format = 'full', withGMT = true) { if (format === 'full') { /** @type {?} */ let formatValue = I18nFormat.formatDateTime(value); if (!withGMT) { formatValue = I18nFormat.formatDateTimeWithoutGMT(value); } return formatValue; } else if (format === 'short') { return I18nFormat.formatDate(value); } else { // 默认使用用户传入的format格式化 return I18nFormat.formatDate(value, format); } } } I18nDatePipe.decorators = [ { type: Pipe, args: [{ name: 'i18nDate' },] } ]; /** * @fileoverview added by tsickle * Generated from: i18n.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class I18nModule { } I18nModule.decorators = [ { type: NgModule, args: [{ declarations: [ I18nDatePipe ], exports: [ I18nDatePipe ] },] } ]; /** * @fileoverview added by tsickle * Generated from: public-api.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * Generated from: ng-devui-i18n.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { I18nDatePipe, I18nFormat, I18nModule, I18nService, I18nUtil }; //# sourceMappingURL=ng-devui-i18n.js.map