Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Handle attribution when title is blank (#1387)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb authored May 5, 2022
1 parent e11f1de commit 26e721f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@
"link": "here"
},
"credit": {
"text": "\"{title}\"{creator}{marked-licensed}{license}. {view-legal}",
"generic-title": "This work",
"actual-title": "\"{title}\"",
"text": "{title}{creator}{marked-licensed}{license}. {view-legal}",
"creator-text": " by {creator-name}",
"marked": " is marked with ",
"licensed": " is licensed under ",
Expand Down
13 changes: 11 additions & 2 deletions src/locales/po-files/openverse.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Openverse \n"
"Report-Msgid-Bugs-To: https://github.com/wordpress/openverse/issues \n"
"POT-Creation-Date: 2022-05-03T16:18:32+00:00\n"
"POT-Creation-Date: 2022-05-04T11:38:38+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -655,9 +655,18 @@ msgctxt "media-details.reuse.copy-license.copied"
msgid "Copied!"
msgstr ""

msgctxt "media-details.reuse.credit.generic-title"
msgid "This work"
msgstr ""

#. Do not translate words between ### ###.
msgctxt "media-details.reuse.credit.actual-title"
msgid "\"###title###\""
msgstr ""

#. Do not translate words between ### ###.
msgctxt "media-details.reuse.credit.text"
msgid "\"###title###\"###creator######marked-licensed######license###. ###view-legal###"
msgid "###title######creator######marked-licensed######license###. ###view-legal###"
msgstr ""

#. Do not translate words between ### ###.
Expand Down
9 changes: 6 additions & 3 deletions src/utils/attribution-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const getAttribution = (
/* Title */

let titleLink = mediaItem.title || ''
if (!isPlaintext && mediaItem.foreign_landing_url)
if (!isPlaintext && mediaItem.foreign_landing_url && titleLink)
titleLink = extLink(mediaItem.foreign_landing_url, titleLink)

/* Creator */
Expand Down Expand Up @@ -144,7 +144,9 @@ export const getAttribution = (
let attribution: string
if (i18n) {
let fillers: Record<string, string> = {
title: titleLink,
title: titleLink
? i18n.t(`${i18nBase}.actual-title`, { title: titleLink }).toString()
: i18n.t(`${i18nBase}.generic-title`).toString(),
creator: creatorLink
? i18n
.t(`${i18nBase}.creator-text`, {
Expand Down Expand Up @@ -172,7 +174,8 @@ export const getAttribution = (
}
attribution = i18n.t(`${i18nBase}.text`, fillers).toString()
} else {
const attributionParts = [`"${titleLink}"`]
const attributionParts = []
attributionParts.push(titleLink ? `"${titleLink}"` : 'This work')
if (creatorLink) attributionParts.push(' by ', creatorLink)
attributionParts.push(
isPd ? ' is marked with ' : ' is licensed under ',
Expand Down
10 changes: 10 additions & 0 deletions test/unit/specs/utils/attribution-html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ describe('getAttribution', () => {
}
)

it('uses generic title if not known', () => {
const mediaItemNoTitle = { ...mediaItem, title: '' }
const attrText = getAttribution(mediaItemNoTitle, i18n, {
isPlaintext: true,
})
const expectation =
'This work by Creator is marked with Public Domain Mark 1.0'
expect(attrText).toContain(expectation)
})

it('omits creator if not known', () => {
const mediaItemNoCreator = { ...mediaItem, creator: undefined }
const attrText = getAttribution(mediaItemNoCreator, i18n, {
Expand Down

0 comments on commit 26e721f

Please sign in to comment.