Skip to content

Commit

Permalink
Create a utility function getLocalisedname()
Browse files Browse the repository at this point in the history
To make the name more usable we had to extract the name formatting logic into it's own function.

#6830
  • Loading branch information
Siyasanga committed Oct 30, 2024
1 parent 3358421 commit 0550d99
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/client/src/utils/data-formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import { getDefaultLanguage } from '@client/i18n/utils'
import type { GQLComment } from '@client/utils/gateway-deprecated-do-not-use'
import { HumanName } from './gateway'
import { constantsMessages } from '@client/i18n/messages'
import { IntlShape } from 'react-intl'

interface INamesMap {
[key: string]: string
Expand Down Expand Up @@ -86,3 +88,17 @@ export const mergeArraysRemovingEmptyStrings = (
export function getPercentage(total: number, current: number) {
return current === 0 || total === 0 ? 0 : (current / total) * 100
}

export function getLocalisedName(
intl: IntlShape,
nameObject: HumanName
): string {
return intl
.formatMessage(constantsMessages.humanName, {
firstName: nameObject.firstNames,
middleName: nameObject.middleName,
lastName: nameObject.familyName
})
.replace(/\s+/g, ' ') // Remove extra spaces
.trim()
}

0 comments on commit 0550d99

Please sign in to comment.