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

adobe / spectrum-web-components / 16329709988

16 Jul 2025 08:32PM UTC coverage: 97.554%. First build
16329709988

Pull #5578

github

web-flow
Merge aa13eb3f9 into d6c69d058
Pull Request #5578: chore: update web test runner

5252 of 5562 branches covered (94.43%)

Branch coverage included in aggregate %.

8 of 10 new or added lines in 1 file covered. (80.0%)

33626 of 34291 relevant lines covered (98.06%)

631.38 hits per line

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

94.81
/tools/reactive-controllers/src/LanguageResolution.ts
1
/**
20✔
2
 * Copyright 2025 Adobe. All rights reserved.
20✔
3
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
20✔
4
 * you may not use this file except in compliance with the License. You may obtain a copy
20✔
5
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
20✔
6
 *
20✔
7
 * Unless required by applicable law or agreed to in writing, software distributed under
20✔
8
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
20✔
9
 * OF ANY KIND, either express or implied. See the License for the specific language
20✔
10
 * governing permissions and limitations under the License.
20✔
11
 */
20✔
12

20✔
13
import type { ReactiveController, ReactiveElement } from 'lit';
20✔
14
import { ProvideLang } from '@spectrum-web-components/theme';
20✔
15

20✔
16
export const languageResolverUpdatedSymbol = Symbol(
20✔
17
    'language resolver updated'
20✔
18
);
20✔
19

20✔
20
export class LanguageResolutionController implements ReactiveController {
20✔
21
    private host: ReactiveElement;
20✔
22
    language = document.documentElement.lang || navigator.language || 'en-US';
20!
23
    private unsubscribe?: () => void;
20✔
24

20✔
25
    constructor(host: ReactiveElement) {
20✔
26
        this.host = host;
416✔
27
        this.host.addController(this);
416✔
28
    }
416✔
29

20✔
30
    public hostConnected(): void {
20✔
31
        this.resolveLanguage();
416✔
32
    }
416✔
33

20✔
34
    public hostDisconnected(): void {
20✔
35
        this.unsubscribe?.();
416✔
36
    }
416✔
37

20✔
38
    private resolveLanguage(): void {
20✔
39
        try {
416✔
40
            // Fix for invalid locale tags like en-US@posix
416✔
41
            if (this.language.includes('@posix')) {
416✔
42
                this.language = this.language.replace('@posix', '');
416✔
43
            }
416✔
44
            Intl.DateTimeFormat.supportedLocalesOf([this.language]);
416✔
45
        } catch {
416!
NEW
46
            this.language = 'en-US';
×
NEW
47
        }
×
48
        const queryThemeEvent = new CustomEvent<ProvideLang>(
416✔
49
            'sp-language-context',
416✔
50
            {
416✔
51
                bubbles: true,
416✔
52
                composed: true,
416✔
53
                detail: {
416✔
54
                    callback: (lang: string, unsubscribe: () => void) => {
416✔
55
                        const previous = this.language;
136✔
56
                        this.language = lang;
136✔
57
                        this.unsubscribe = unsubscribe;
136✔
58
                        this.host.requestUpdate(
136✔
59
                            languageResolverUpdatedSymbol,
136✔
60
                            previous
136✔
61
                        );
136✔
62
                    },
136✔
63
                },
416✔
64
                cancelable: true,
416✔
65
            }
416✔
66
        );
416✔
67
        this.host.dispatchEvent(queryThemeEvent);
416✔
68
    }
416✔
69
}
20✔
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