Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Handle attribution when title is blank (#1387)

Dhruv Bhanushali26e721f05455
diff --git a/src/locales/en.json b/src/locales/en.json
index 53e50122e..77b38782b 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -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 ",
diff --git a/src/locales/po-files/openverse.pot b/src/locales/po-files/openverse.pot
index 9e2c87624..24cf5e9f5 100644
--- a/src/locales/po-files/openverse.pot
+++ b/src/locales/po-files/openverse.pot
@@ -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"
@@ -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 ### ###.
diff --git a/src/utils/attribution-html.ts b/src/utils/attribution-html.ts
index 1f6ca4ca3..544f8e4e9 100644
--- a/src/utils/attribution-html.ts
+++ b/src/utils/attribution-html.ts
@@ -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 */
@@ -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`, {
@@ -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 ',
diff --git a/test/unit/specs/utils/attribution-html.spec.ts b/test/unit/specs/utils/attribution-html.spec.ts
index 08c9e3eba..284d86c53 100644
--- a/test/unit/specs/utils/attribution-html.spec.ts
+++ b/test/unit/specs/utils/attribution-html.spec.ts
@@ -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, {