From 4fb960003a5fac08d1c6bb5136c6fd575e373f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Pi=C4=85tkiewicz?= Date: Mon, 12 Feb 2024 11:14:52 +0100 Subject: [PATCH 1/8] Parameterize LinguistCard title MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piotr Piątkiewicz --- .changeset/lazy-terms-shake.md | 5 +++++ plugins/linguist/README.md | 6 ++++++ .../linguist/src/components/LinguistCard/LinguistCard.tsx | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/lazy-terms-shake.md diff --git a/.changeset/lazy-terms-shake.md b/.changeset/lazy-terms-shake.md new file mode 100644 index 0000000000..41f5292709 --- /dev/null +++ b/.changeset/lazy-terms-shake.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-linguist': minor +--- + +Allow to optionally pass component's title as LinguistCard parameter diff --git a/plugins/linguist/README.md b/plugins/linguist/README.md index 7ad70f1db6..72855c0894 100644 --- a/plugins/linguist/README.md +++ b/plugins/linguist/README.md @@ -79,6 +79,12 @@ To setup the Linguist Card frontend you'll need to do the following steps: ``` +3. (optionally) Set component's title - default is "Languages" + + ```tsx + + ``` + **Notes:** - The `if` prop is optional on the `EntitySwitch.Case`, you can remove it if you always want to see the tab even if the entity being viewed does not have the needed annotation diff --git a/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx b/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx index 6a07a958c2..3b63abd406 100644 --- a/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx +++ b/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx @@ -55,7 +55,7 @@ const useStyles = makeStyles(theme => ({ }, })); -export const LinguistCard = () => { +export const LinguistCard = ({ title = 'Languages' }) => { const classes = useStyles(); const theme = useTheme(); const { entity } = useEntity(); @@ -70,7 +70,7 @@ export const LinguistCard = () => { if (items && items.languageCount === 0 && items.totalBytes === 0) { return ( - + From 01fff3ff1c895ebad2d49224e7547e332bc9eea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Pi=C4=85tkiewicz?= Date: Mon, 12 Feb 2024 11:44:29 +0100 Subject: [PATCH 2/8] generated api reports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piotr Piątkiewicz --- plugins/linguist/api-report.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/linguist/api-report.md b/plugins/linguist/api-report.md index 71e2460088..ca1ce3cdd2 100644 --- a/plugins/linguist/api-report.md +++ b/plugins/linguist/api-report.md @@ -10,7 +10,11 @@ import { Entity } from '@backstage/catalog-model'; import { JSX as JSX_2 } from 'react'; // @public (undocumented) -export const EntityLinguistCard: () => JSX_2.Element; +export const EntityLinguistCard: ({ + title, +}: { + title?: string | undefined; +}) => JSX_2.Element; // @public (undocumented) export const isLinguistAvailable: (entity: Entity) => boolean; From e0bb6bfd5c43c79c9cf20d936e6a400e30aa695f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Pi=C4=85tkiewicz?= Date: Mon, 12 Feb 2024 11:50:10 +0100 Subject: [PATCH 3/8] Update .changeset/lazy-terms-shake.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Philipp Hugenroth Signed-off-by: Piotr Piątkiewicz --- .changeset/lazy-terms-shake.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/lazy-terms-shake.md b/.changeset/lazy-terms-shake.md index 41f5292709..62fd2d848e 100644 --- a/.changeset/lazy-terms-shake.md +++ b/.changeset/lazy-terms-shake.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-linguist': minor +'@backstage/plugin-linguist': patch --- Allow to optionally pass component's title as LinguistCard parameter From fe8e16df4a20c93c86722010585c7663ef23519d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Pi=C4=85tkiewicz?= Date: Mon, 12 Feb 2024 15:44:05 +0100 Subject: [PATCH 4/8] Get linguist component title from translation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piotr Piątkiewicz --- .changeset/lazy-terms-shake.md | 2 +- plugins/linguist/README.md | 6 ----- plugins/linguist/api-report.md | 6 +---- .../components/LinguistCard/LinguistCard.tsx | 7 +++-- plugins/linguist/src/translation.ts | 26 +++++++++++++++++++ 5 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 plugins/linguist/src/translation.ts diff --git a/.changeset/lazy-terms-shake.md b/.changeset/lazy-terms-shake.md index 62fd2d848e..03c0fee21f 100644 --- a/.changeset/lazy-terms-shake.md +++ b/.changeset/lazy-terms-shake.md @@ -2,4 +2,4 @@ '@backstage/plugin-linguist': patch --- -Allow to optionally pass component's title as LinguistCard parameter +Get component's title from translation file diff --git a/plugins/linguist/README.md b/plugins/linguist/README.md index 72855c0894..7ad70f1db6 100644 --- a/plugins/linguist/README.md +++ b/plugins/linguist/README.md @@ -79,12 +79,6 @@ To setup the Linguist Card frontend you'll need to do the following steps: ``` -3. (optionally) Set component's title - default is "Languages" - - ```tsx - - ``` - **Notes:** - The `if` prop is optional on the `EntitySwitch.Case`, you can remove it if you always want to see the tab even if the entity being viewed does not have the needed annotation diff --git a/plugins/linguist/api-report.md b/plugins/linguist/api-report.md index ca1ce3cdd2..71e2460088 100644 --- a/plugins/linguist/api-report.md +++ b/plugins/linguist/api-report.md @@ -10,11 +10,7 @@ import { Entity } from '@backstage/catalog-model'; import { JSX as JSX_2 } from 'react'; // @public (undocumented) -export const EntityLinguistCard: ({ - title, -}: { - title?: string | undefined; -}) => JSX_2.Element; +export const EntityLinguistCard: () => JSX_2.Element; // @public (undocumented) export const isLinguistAvailable: (entity: Entity) => boolean; diff --git a/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx b/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx index 3b63abd406..95aa5e0d89 100644 --- a/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx +++ b/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx @@ -27,6 +27,8 @@ import React from 'react'; import slugify from 'slugify'; import { useEntity } from '@backstage/plugin-catalog-react'; import { useLanguages } from '../../hooks'; +import { useTranslationRef } from '@backstage/core-plugin-api/alpha'; +import { linguistTranslationRef } from '../../translation'; const useStyles = makeStyles(theme => ({ infoCard: { @@ -55,7 +57,8 @@ const useStyles = makeStyles(theme => ({ }, })); -export const LinguistCard = ({ title = 'Languages' }) => { +export const LinguistCard = () => { + const { t } = useTranslationRef(linguistTranslationRef); const classes = useStyles(); const theme = useTheme(); const { entity } = useEntity(); @@ -70,7 +73,7 @@ export const LinguistCard = ({ title = 'Languages' }) => { if (items && items.languageCount === 0 && items.totalBytes === 0) { return ( - + diff --git a/plugins/linguist/src/translation.ts b/plugins/linguist/src/translation.ts new file mode 100644 index 0000000000..78a34f2f7e --- /dev/null +++ b/plugins/linguist/src/translation.ts @@ -0,0 +1,26 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { createTranslationRef } from '@backstage/core-plugin-api/alpha'; + +/** @alpha */ +export const linguistTranslationRef = createTranslationRef({ + id: 'linguist', + messages: { + component: { + title: 'Languages', + }, + }, +}); From 5bc5d5cf30fd328d96b42d772b9330777f420911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Pi=C4=85tkiewicz?= Date: Mon, 12 Feb 2024 16:52:55 +0100 Subject: [PATCH 5/8] Export translation in linguist package.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piotr Piątkiewicz --- plugins/linguist/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/linguist/package.json b/plugins/linguist/package.json index 4d308b2f73..dbc5da2d31 100644 --- a/plugins/linguist/package.json +++ b/plugins/linguist/package.json @@ -10,7 +10,8 @@ "exports": { ".": "./src/index.ts", "./alpha": "./src/alpha.ts", - "./package.json": "./package.json" + "./package.json": "./package.json", + "./src/translation": "./src/translation.ts" }, "typesVersions": { "*": { From 8d3734b42af16f1322d37ce26da7265eebc52f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Pi=C4=85tkiewicz?= Date: Tue, 13 Feb 2024 08:37:06 +0100 Subject: [PATCH 6/8] fix translation import, added one more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piotr Piątkiewicz --- .changeset/lazy-terms-shake.md | 2 +- plugins/linguist/api-report-alpha.md | 10 ++++++++++ plugins/linguist/package.json | 3 +-- plugins/linguist/src/alpha.ts | 1 + .../src/components/LinguistCard/LinguistCard.tsx | 4 +--- plugins/linguist/src/translation.ts | 1 + 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.changeset/lazy-terms-shake.md b/.changeset/lazy-terms-shake.md index 03c0fee21f..efe89f1c12 100644 --- a/.changeset/lazy-terms-shake.md +++ b/.changeset/lazy-terms-shake.md @@ -2,4 +2,4 @@ '@backstage/plugin-linguist': patch --- -Get component's title from translation file +Get component's title from translation file. See: https://backstage.io/docs/plugins/internationalization#for-an-application-developer-overwrite-plugin-messages diff --git a/plugins/linguist/api-report-alpha.md b/plugins/linguist/api-report-alpha.md index 418439d331..4a250535b0 100644 --- a/plugins/linguist/api-report-alpha.md +++ b/plugins/linguist/api-report-alpha.md @@ -4,10 +4,20 @@ ```ts import { BackstagePlugin } from '@backstage/frontend-plugin-api'; +import { TranslationRef } from '@backstage/core-plugin-api/alpha'; // @alpha (undocumented) const _default: BackstagePlugin<{}, {}>; export default _default; +// @alpha (undocumented) +export const linguistTranslationRef: TranslationRef< + 'linguist', + { + readonly 'component.title': 'Languages'; + readonly 'component.noData': 'There is currently no language data for this entity.'; + } +>; + // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/linguist/package.json b/plugins/linguist/package.json index dbc5da2d31..4d308b2f73 100644 --- a/plugins/linguist/package.json +++ b/plugins/linguist/package.json @@ -10,8 +10,7 @@ "exports": { ".": "./src/index.ts", "./alpha": "./src/alpha.ts", - "./package.json": "./package.json", - "./src/translation": "./src/translation.ts" + "./package.json": "./package.json" }, "typesVersions": { "*": { diff --git a/plugins/linguist/src/alpha.ts b/plugins/linguist/src/alpha.ts index e80f131817..287775ade0 100644 --- a/plugins/linguist/src/alpha.ts +++ b/plugins/linguist/src/alpha.ts @@ -16,3 +16,4 @@ export * from './alpha/index'; export { default } from './alpha/index'; +export * from './translation'; diff --git a/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx b/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx index 95aa5e0d89..3a07dd35e2 100644 --- a/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx +++ b/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx @@ -76,9 +76,7 @@ export const LinguistCard = () => { - - There is currently no language data for this entity. - + {t('component.noData')} diff --git a/plugins/linguist/src/translation.ts b/plugins/linguist/src/translation.ts index 78a34f2f7e..f971b70490 100644 --- a/plugins/linguist/src/translation.ts +++ b/plugins/linguist/src/translation.ts @@ -21,6 +21,7 @@ export const linguistTranslationRef = createTranslationRef({ messages: { component: { title: 'Languages', + noData: 'There is currently no language data for this entity.', }, }, }); From d1d602e6d971529160b45479396a561d22714590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Pi=C4=85tkiewicz?= Date: Tue, 13 Feb 2024 10:39:44 +0100 Subject: [PATCH 7/8] updated translations keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piotr Piątkiewicz --- plugins/linguist/api-report-alpha.md | 4 ++-- plugins/linguist/src/components/LinguistCard/LinguistCard.tsx | 4 ++-- plugins/linguist/src/translation.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/linguist/api-report-alpha.md b/plugins/linguist/api-report-alpha.md index 4a250535b0..07d2244e30 100644 --- a/plugins/linguist/api-report-alpha.md +++ b/plugins/linguist/api-report-alpha.md @@ -14,8 +14,8 @@ export default _default; export const linguistTranslationRef: TranslationRef< 'linguist', { - readonly 'component.title': 'Languages'; - readonly 'component.noData': 'There is currently no language data for this entity.'; + readonly 'entityCard.title': 'Languages'; + readonly 'entityCard.noData': 'There is currently no language data for this entity.'; } >; diff --git a/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx b/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx index 3a07dd35e2..19225f1471 100644 --- a/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx +++ b/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx @@ -73,10 +73,10 @@ export const LinguistCard = () => { if (items && items.languageCount === 0 && items.totalBytes === 0) { return ( - + - {t('component.noData')} + {t('entityCard.noData')} diff --git a/plugins/linguist/src/translation.ts b/plugins/linguist/src/translation.ts index f971b70490..7055d3dfe8 100644 --- a/plugins/linguist/src/translation.ts +++ b/plugins/linguist/src/translation.ts @@ -19,7 +19,7 @@ import { createTranslationRef } from '@backstage/core-plugin-api/alpha'; export const linguistTranslationRef = createTranslationRef({ id: 'linguist', messages: { - component: { + entityCard: { title: 'Languages', noData: 'There is currently no language data for this entity.', }, From d8eea9b165220c609b4aae726cfd2b06a49259d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Pi=C4=85tkiewicz?= Date: Tue, 13 Feb 2024 12:22:31 +0100 Subject: [PATCH 8/8] added missing translation reference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piotr Piątkiewicz --- plugins/linguist/src/components/LinguistCard/LinguistCard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx b/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx index 19225f1471..213ca316ca 100644 --- a/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx +++ b/plugins/linguist/src/components/LinguistCard/LinguistCard.tsx @@ -89,7 +89,7 @@ export const LinguistCard = () => { const processedDate = items?.processedDate; return breakdown && processedDate ? ( - + {breakdown.map((language, index: number) => { barWidth = barWidth + language.percentage;