File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 11import type { translate } from 'angular'
2- import React , { useMemo } from 'react'
2+ import React , { useEffect , useMemo , useState } from 'react'
33import { getAngularService } from '../ServiceProvider'
44
55type Props = {
6- id : string
6+ children : string
77 substitutions ?: unknown
88}
99
1010/**
1111 * Helper element that uses Angular's translate service to translate a string
1212 * @returns
1313 */
14- const NgTranslate = ( { id , substitutions } : Props ) => {
14+ const NgTranslate = ( { children , substitutions } : Props ) => {
1515 const $translate = useMemo ( ( ) => getAngularService < translate . ITranslateService > ( '$translate' ) , [ ] )
16+ const [ text , setText ] = useState ( children . trim ( ) )
1617
17- return < > { $translate . instant ( id , substitutions ) } </ >
18+ useEffect ( ( ) => {
19+ const update = ( ) => {
20+ const txKey = children . trim ( )
21+ setText ( $translate . instant ( txKey , substitutions ) )
22+ }
23+ if ( $translate . isReady ( ) ) {
24+ update ( )
25+ } else {
26+ $translate . onReady ( update )
27+ }
28+ } , [ children , substitutions ] )
29+
30+ return < > { text } </ >
1831}
1932
2033export default NgTranslate
You can’t perform that action at this time.
0 commit comments