File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 2
2
// Or add a tooltip by data-number-in-tooltip attribute. JSON: {message: "count: %s", number: 123}
3
3
window . customElements . define ( 'gitea-locale-number' , class extends HTMLElement {
4
4
connectedCallback ( ) {
5
+ // ideally, the number locale formatting and plural processing should be done by backend with translation strings.
6
+ // if we have complete backend locale support (eg: Golang "x/text" package), we can drop this component.
5
7
const number = this . getAttribute ( 'data-number' ) ;
6
8
if ( number ) {
7
9
this . attachShadow ( { mode : 'open' } ) ;
8
10
this . shadowRoot . textContent = new Intl . NumberFormat ( ) . format ( Number ( number ) ) ;
9
11
}
10
- let numberInTooltip = this . getAttribute ( 'data-number-in-tooltip' ) ;
12
+ const numberInTooltip = this . getAttribute ( 'data-number-in-tooltip' ) ;
11
13
if ( numberInTooltip ) {
12
- numberInTooltip = JSON . parse ( numberInTooltip ) ;
13
- let msg = numberInTooltip . message ;
14
- msg = msg . replace ( / % [ d s ] / , new Intl . NumberFormat ( ) . format ( Number ( numberInTooltip . number ) ) ) ;
15
- this . setAttribute ( 'data-tooltip-content' , msg ) ;
14
+ // TODO: only 2 usages of this, we can replace it with Golang's "x/text/number" package in the future
15
+ const { message , number } = JSON . parse ( numberInTooltip ) ;
16
+ const tooltipContent = message . replace ( / % [ d s ] / , new Intl . NumberFormat ( ) . format ( Number ( number ) ) ) ;
17
+ this . setAttribute ( 'data-tooltip-content' , tooltipContent ) ;
16
18
}
17
19
}
18
20
} ) ;
You can’t perform that action at this time.
0 commit comments