Skip to content

Commit

Permalink
feat(paper): Format date metadata qualification on cozy-client
Browse files Browse the repository at this point in the history
Was previously on cozy-ui. Now mutualized.
  • Loading branch information
zatteo committed Mar 12, 2024
1 parent 8466b66 commit a86335c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/cozy-client/src/models/document/locales/en.json
Expand Up @@ -148,6 +148,24 @@
"transport": "Transport",
"undefined": "Undefined",
"work_study": "Work & Study"
},
"qualification": {
"date": {
"title": {
"datetime": "Added on",
"AObtentionDate": "License A, delivered on",
"BObtentionDate": "License B, delivered on",
"CObtentionDate": "License C, delivered on",
"DObtentionDate": "License D, delivered on",
"issueDate": "Delivered on",
"expirationDate": "Expiration date",
"referencedDate": "Referenced date",
"shootingDate": "Shooting date",
"obtentionDate": "Date obtained",
"date": "Document date"
}
},
"noInfo": "No information"
}
},
"MagicFolders": {
Expand Down
18 changes: 18 additions & 0 deletions packages/cozy-client/src/models/document/locales/fr.json
Expand Up @@ -148,6 +148,24 @@
"transport": "Transport",
"undefined": "Indéfini",
"work_study": "Travail & Études"
},
"qualification": {
"date": {
"title": {
"datetime": "Ajouté le",
"AObtentionDate": "Permis A, délivré le",
"BObtentionDate": "Permis B, délivré le",
"CObtentionDate": "Permis C, délivré le",
"DObtentionDate": "Permis D, délivré le",
"issueDate": "Délivré le",
"expirationDate": "Date d'expiration",
"referencedDate": "Date de référence",
"shootingDate": "Date de prise de vue",
"obtentionDate": "Date d'obtention",
"date": "Date du document"
}
},
"noInfo": "Non renseigné(e)"
}
},
"MagicFolders": {
Expand Down
33 changes: 33 additions & 0 deletions packages/cozy-client/src/models/paper.js
@@ -1,5 +1,6 @@
import add from 'date-fns/add'
import sub from 'date-fns/sub'
import { getLocalizer } from './document/locales'

/**
* @typedef {import("../types").IOCozyFile} IOCozyFile
Expand Down Expand Up @@ -286,3 +287,35 @@ export const getMetadataQualificationType = metadataName => {

return null
}

/**
* @param {string} name - The name of a metadata of type date like 'expirationDate' or 'shootingDate'
* @param {Object} options - Options
* @param {string} options.lang - Lang requested for the translation like 'fr' or 'en'
* @returns {string} Translated name for the metadata
*/
export const getTranslatedNameForDateMetadata = (name, { lang }) => {
const t = getLocalizer(lang)

return t(`Scan.qualification.date.title.${name}`)
}

/**
* @param {string} value - The value of a metadata of type date
* @param {Object} options - Options
* @param {string} options.lang - Lang requested for the translation
* @param {function} options.f - Date formatting function
* @returns {string} Formatted and translated value for the metadata
*/
export const formatDateMetadataValue = (value, { lang, f }) => {
const t = getLocalizer(lang)

if (value) {
if (lang === 'en') {
return f(value, 'MM/DD/YYYY')
}
return f(value, 'DD/MM/YYYY')
} else {
return t('Scan.qualification.noInfo')
}
}

0 comments on commit a86335c

Please sign in to comment.