Skip to content

Commit 068d23e

Browse files
committed
feat(ContactsList): Move locales inside ContactsList attribute
to better target it in app in case of override
1 parent 9a940cc commit 068d23e

File tree

7 files changed

+44
-24
lines changed

7 files changed

+44
-24
lines changed

react/ContactsList/ContactCell.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Cell = ({ row, column, cell, actions }) => {
2929
<ListItemIcon>
3030
<IconButton
3131
ref={actionsRef}
32-
arial-label={t('menu')}
32+
arial-label={t('ContactsList.menu')}
3333
onClick={() => setShowActions(true)}
3434
>
3535
<Icon icon={DotsIcon} />

react/ContactsList/Contacts/ContactIdentity.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ const MyselfMarker = () => {
1414
useExtendI18n(locales)
1515
const { t } = useI18n()
1616

17-
return <span className={`${styles['contact-myself']}`}>({t('me')})</span>
17+
return (
18+
<span className={`${styles['contact-myself']}`}>
19+
({t('ContactsList.me')})
20+
</span>
21+
)
1822
}
1923

2024
const ContactIdentity = ({ contact }) => {

react/ContactsList/ContactsList.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import React from 'react'
44
import ContactRow from './ContactRow'
55
import { sortContacts, categorizeContacts, sortHeaders } from './helpers'
66
import withContactsListLocales from './locales/withContactsListLocales'
7+
import { locales } from './locales/withContactsListLocales'
78
import List from '../List'
89
import ListSubheader from '../ListSubheader'
910
import { Table } from '../deprecated/Table'
1011
import useBreakpoints from '../providers/Breakpoints'
11-
import { useI18n } from '../providers/I18n'
12+
import { useI18n, useExtendI18n } from '../providers/I18n'
1213

1314
const ContactsList = ({ contacts, onItemClick, ...rest }) => {
15+
useExtendI18n(locales)
1416
const { t } = useI18n()
1517
const sortedContacts = sortContacts(contacts)
1618
const categorizedContacts = categorizeContacts(sortedContacts, t)

react/ContactsList/helpers.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ export const sortContacts = contacts => contacts.sort(sortLastNameFirst)
3232
* @returns {string} header
3333
*/
3434
const makeHeader = (contact, t) => {
35-
if (contact.me) return t('me')
35+
if (contact.me) return t('ContactsList.me')
3636

3737
const name = buildLastNameFirst(contact)
38-
return name[0] || t('empty')
38+
return name[0] || t('ContactsList.empty')
3939
}
4040

4141
/**
@@ -45,8 +45,8 @@ const makeHeader = (contact, t) => {
4545
* @returns {string} header
4646
*/
4747
const makeHeaderForIndexedContacts = (contact, t) => {
48-
if (contact.me) return t('me')
49-
if (contact.cozyMetadata?.favorite) return t('favorite')
48+
if (contact.me) return t('ContactsList.me')
49+
if (contact.cozyMetadata?.favorite) return t('ContactsList.favorite')
5050

5151
const index = get(contact, 'indexes.byFamilyNameGivenNameEmailCozyUrl', '')
5252
const hasIndex = index !== null && index.length > 0
@@ -58,7 +58,7 @@ const makeHeaderForIndexedContacts = (contact, t) => {
5858
return firstLetterWithoutAccent
5959
}
6060

61-
return t('empty')
61+
return t('ContactsList.empty')
6262
}
6363

6464
/**
@@ -89,7 +89,8 @@ export const categorizeContacts = (contacts, t) =>
8989
export const sortHeaders = (categorized, t) => {
9090
const headers = Object.keys(categorized)
9191
const notEmptyAndMyselfHeaders = headers.filter(
92-
header => header !== t('empty') && header !== t('me')
92+
header =>
93+
header !== t('ContactsList.empty') && header !== t('ContactsList.me')
9394
)
9495
const notEmptyAndMyselfSorted = notEmptyAndMyselfHeaders.slice().sort()
9596

@@ -98,11 +99,11 @@ export const sortHeaders = (categorized, t) => {
9899
}
99100

100101
const headersSorted = []
101-
if (headers.includes(t('me'))) {
102-
headersSorted.push(t('me'))
102+
if (headers.includes(t('ContactsList.me'))) {
103+
headersSorted.push(t('ContactsList.me'))
103104
}
104-
if (headers.includes(t('empty'))) {
105-
headersSorted.push(t('empty'))
105+
if (headers.includes(t('ContactsList.empty'))) {
106+
headersSorted.push(t('ContactsList.empty'))
106107
}
107108

108109
return headersSorted.concat(notEmptyAndMyselfSorted)

react/ContactsList/helpers.spec.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('sortHeaders', () => {
103103

104104
const sortedHeaders = sortHeaders(contacts, t)
105105

106-
expect(sortedHeaders).toEqual(['me', 'empty', 'B', 'F', 'H'])
106+
expect(sortedHeaders).toEqual(['B', 'F', 'H', 'empty', 'me'])
107107
})
108108
})
109109

@@ -143,7 +143,16 @@ describe('makeGroupLabelsAndCounts', () => {
143143
const res = makeGroupLabelsAndCounts(contacts, t)
144144

145145
expect(res).toStrictEqual({
146-
groupLabels: ['A', 'C', 'B', 'X', 'Z', 'empty', 'me', 'E'],
146+
groupLabels: [
147+
'A',
148+
'C',
149+
'B',
150+
'X',
151+
'Z',
152+
'ContactsList.empty',
153+
'ContactsList.me',
154+
'E'
155+
],
147156
groupCounts: [3, 5, 2, 1, 1, 4, 1, 1]
148157
})
149158
})

react/ContactsList/locales/en.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
2-
"empty": "EMPTY",
3-
"me": "me",
4-
"favorite": "favorites",
5-
"menu": "Menu"
2+
"ContactsList": {
3+
"empty": "EMPTY",
4+
"me": "me",
5+
"favorite": "favorites",
6+
"menu": "Menu"
7+
}
68
}

react/ContactsList/locales/fr.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
2-
"empty": "VIDE",
3-
"me": "moi",
4-
"favorite": "favoris",
5-
"menu": "Menu"
6-
}
2+
"ContactsList": {
3+
"empty": "VIDE",
4+
"me": "moi",
5+
"favorite": "favoris",
6+
"menu": "Menu"
7+
}
8+
}

0 commit comments

Comments
 (0)