• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atinc / ngx-tethys / 2b0c2344-6c9c-4127-9e80-38f3934d3178

16 Nov 2024 09:49AM UTC coverage: 90.353% (+0.005%) from 90.348%
2b0c2344-6c9c-4127-9e80-38f3934d3178

push

circleci

minlovehua
feat: i18n structure

5521 of 6758 branches covered (81.7%)

Branch coverage included in aggregate %.

13193 of 13954 relevant lines covered (94.55%)

996.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/src/i18n/i18n.service.ts
1
import { inject, Injectable } from '@angular/core';
2
import { THY_I18N_EN_US, THY_I18N_LOCALE_ID, THY_I18N_ZH_CN, ThyI18nLocale } from '.';
3
import zh_CN from './locales/zh-cn';
4
import en_US from './locales/en-us';
5

6
function normalizeLocale(localeId: string): string {
7
    return localeId?.toLowerCase().replace(/_/g, '-');
241✔
8
}
9

1✔
10
@Injectable({
11
    providedIn: 'root'
241✔
12
})
482✔
13
export class ThyI18nService {
482✔
14
    private locales: { [id: string]: ThyI18nLocale } = {
15
        'zh-cn': inject(THY_I18N_ZH_CN, { optional: true }) || zh_CN,
241✔
16
        'en-us': inject(THY_I18N_EN_US, { optional: true }) || en_US
17
    };
18

19
    private defaultLocaleId: string = normalizeLocale(inject(THY_I18N_LOCALE_ID, { optional: true })) || 'zh-cn';
241✔
20

21
    /**
22
     * 当前语言包
23
     */
24
    locale: ThyI18nLocale = this.locales[this.defaultLocaleId];
25

26
    /**
×
27
     * 设置语言
×
28
     * @param id 可以传入 zh-cn(或zh-CN)、 en-us(或en-US)
29
     */
30
    setLocale(id: string) {
1✔
31
        const localeId = normalizeLocale(id);
32
        this.locale = this.locales[localeId] || this.locales[this.defaultLocaleId];
33
    }
34
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc