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 22// Or add a tooltip by data-number-in-tooltip attribute. JSON: {message: "count: %s", number: 123}
33window . customElements . define ( 'gitea-locale-number' , class extends HTMLElement {
44 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.
57 const number = this . getAttribute ( 'data-number' ) ;
68 if ( number ) {
79 this . attachShadow ( { mode : 'open' } ) ;
810 this . shadowRoot . textContent = new Intl . NumberFormat ( ) . format ( Number ( number ) ) ;
911 }
10- let numberInTooltip = this . getAttribute ( 'data-number-in-tooltip' ) ;
12+ const numberInTooltip = this . getAttribute ( 'data-number-in-tooltip' ) ;
1113 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 ) ;
1618 }
1719 }
1820} ) ;
You can’t perform that action at this time.
0 commit comments