Skip to content

Commit

Permalink
feat: Use Sharing locales instead apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Merkur39 committed Dec 6, 2024
1 parent 2f410e1 commit 55265c9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/cozy-sharing/src/OpenSharingLinkButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Icon from 'cozy-ui/transpiled/react/Icon'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

import { getIconWithlabel, openExternalLink } from './helpers/sharings'
import withLocales from './hoc/withLocales'

/**
* OpenSharingLinkButton component renders a Button
Expand All @@ -16,7 +17,7 @@ import { getIconWithlabel, openExternalLink } from './helpers/sharings'
* @param {boolean} [props.isSharingShortcutCreated=false] - Indicates if a sharing shortcut has been created. (default false)
* @param {Object} [props] - Additional props to be passed to the Button component.
*/
export const OpenSharingLinkButton = ({
const OpenSharingLinkButton = ({
link,
isSharingShortcutCreated = false,
...props
Expand Down Expand Up @@ -47,3 +48,5 @@ OpenSharingLinkButton.propTypes = {
link: PropTypes.string,
isSharingShortcutCreated: PropTypes.bool
}

export default withLocales(OpenSharingLinkButton)
5 changes: 4 additions & 1 deletion packages/cozy-sharing/src/OpenSharingLinkFabButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ExtendableFab } from 'cozy-ui/transpiled/react/Fab'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

import { getIconWithlabel, openExternalLink } from './helpers/sharings'
import withLocales from './hoc/withLocales'

const makeStyles = customStyle => {
const { position, right, bottom, ...rest } = customStyle
Expand All @@ -25,7 +26,7 @@ const makeStyles = customStyle => {
* @param {boolean} [props.isSharingShortcutCreated=false] - Indicates if a sharing shortcut has been created. (default false)
* @param {Object} [props] - Additional props to be passed to the ExtendableFab component.
*/
export const OpenSharingLinkFabButton = ({
const OpenSharingLinkFabButton = ({
link,
isSharingShortcutCreated = false,
...props
Expand Down Expand Up @@ -61,3 +62,5 @@ OpenSharingLinkFabButton.propTypes = {
link: PropTypes.string.isRequired,
isSharingShortcutCreated: PropTypes.bool
}

export default withLocales(OpenSharingLinkFabButton)
4 changes: 3 additions & 1 deletion packages/cozy-sharing/src/actions/openSharingLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'

import { getIconWithlabel, openExternalLink } from '../helpers/sharings'
import { getActionsI18n } from '../hoc/withLocales'

const makeComponent = (label, icon) => {
const Component = forwardRef((props, ref) => {
Expand All @@ -23,7 +24,8 @@ const makeComponent = (label, icon) => {
return Component
}

export const openSharingLink = ({ t, isSharingShortcutCreated, link }) => {
export const openSharingLink = ({ isSharingShortcutCreated, link }) => {
const { t } = getActionsI18n()
const { icon, label } = getIconWithlabel({
link,
isSharingShortcutCreated,
Expand Down
4 changes: 2 additions & 2 deletions packages/cozy-sharing/src/helpers/sharings.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const getIconWithlabel = ({ link, isSharingShortcutCreated, t }) => {
return { icon: ToTheCloudIcon, label: t('Share.create-cozy') }
}
if (!isSharingShortcutCreated) {
return { icon: CloudPlusOutlinedIcon, label: t('toolbar.add_to_mine') }
return { icon: CloudPlusOutlinedIcon, label: t('Share.banner.add_to_mine') }
}
return { icon: SyncIcon, label: t('toolbar.menu_sync_cozy') }
return { icon: SyncIcon, label: t('Share.banner.sync_to_mine') }
}
3 changes: 3 additions & 0 deletions packages/cozy-sharing/src/hoc/withLocales.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React from 'react'

import { I18n, translate } from 'cozy-ui/transpiled/react/providers/I18n'
import { getI18n } from 'cozy-ui/transpiled/react/providers/I18n/helpers'

const locales = {
en: require(`../../locales/en.json`),
fr: require(`../../locales/fr.json`)
}

export const getActionsI18n = () => getI18n(undefined, lang => locales[lang])

/**
* Adds cozy-sharing translations in the React context
*
Expand Down
4 changes: 2 additions & 2 deletions packages/cozy-sharing/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export { useSharingInfos } from './components/SharingBanner/hooks/useSharingInfo
export { ConfirmTrustedRecipientsDialog } from './ConfirmTrustedRecipientsDialog'
export { ShareButtonWithRecipients } from './ShareButtonWithRecipients'
export { DOCUMENT_TYPE } from './helpers/documentType'
export { OpenSharingLinkButton } from './OpenSharingLinkButton'
export { OpenSharingLinkFabButton } from './OpenSharingLinkFabButton'
export { default as OpenSharingLinkButton } from './OpenSharingLinkButton'
export { default as OpenSharingLinkFabButton } from './OpenSharingLinkFabButton'
export { openSharingLink } from './actions/openSharingLink'

0 comments on commit 55265c9

Please sign in to comment.