Skip to content

Commit

Permalink
[i18n] Externalize strings in ./packages/operator-lifecycle-manager/src
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealJon committed Jan 6, 2021
1 parent f0ca5ee commit bbe2970
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 45 deletions.
18 changes: 17 additions & 1 deletion frontend/packages/operator-lifecycle-manager/locales/en/olm.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,21 @@
"Uninstall Operator?": "Uninstall Operator?",
"This will remove Operator <1>{{name}}</1> from <4>{{namespace}}</4>. Removing the Operator will not remove any of its custom resource definitions or managed resources. If your Operator has deployed applications on the cluster or configured off-cluster resources, these will continue to run and need to be cleaned up manually.": "This will remove Operator <1>{{name}}</1> from <4>{{namespace}}</4>. Removing the Operator will not remove any of its custom resource definitions or managed resources. If your Operator has deployed applications on the cluster or configured off-cluster resources, these will continue to run and need to be cleaned up manually.",
"Message from Operator developer": "Message from Operator developer",
"Uninstall": "Uninstall"
"Uninstall": "Uninstall",
"Operator description": "Operator description",
"This resource is provided by {{displayName}}, a Kubernetes Operator enabled by the Operator Lifecycle Manager.": "This resource is provided by {{displayName}}, a Kubernetes Operator enabled by the Operator Lifecycle Manager.",
"Operator Backed": "Operator Backed",
"Browse for a variety of managed services that are installed by cluster administrators. Cluster administrators can customize the content made available in the catalog.": "Browse for a variety of managed services that are installed by cluster administrators. Cluster administrators can customize the content made available in the catalog.",
"**Operator backed** includes a variety of services managed by Kubernetes controllers.": "**Operator backed** includes a variety of services managed by Kubernetes controllers.",
"Pending": "Pending",
"OK": "OK",
"Failed": "Failed",
"Unknown": "Unknown",
"Upgrade available": "Upgrade available",
"Upgrading": "Upgrading",
"Up to date": "Up to date",
"Hide operator description": "Hide operator description",
"Show operator description": "Show operator description",
"This resource is provided by {{operatorName}}, a Kubernetes Operator enabled by the Operator Lifecycle Manager.": "This resource is provided by {{operatorName}}, a Kubernetes Operator enabled by the Operator Lifecycle Manager.",
"Capability level": "Capability level"
}

This file was deleted.

24 changes: 13 additions & 11 deletions frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as _ from 'lodash';
import i18n from '@console/internal/i18n';
import { K8sResourceKind } from '@console/internal/module/k8s';
import { ClusterServiceVersionKind } from './types';
import { referenceForProvidedAPI, providedAPIsForCSV } from './components';
Expand All @@ -8,14 +9,12 @@ export const normalizeClusterServiceVersions = (
clusterServiceVersions: ClusterServiceVersionKind[],
): K8sResourceKind[] => {
const imgFor = (desc) =>
_.get(desc.csv, 'spec.icon')
? `data:${_.get(desc.csv, 'spec.icon', [])[0].mediatype};base64,${
_.get(desc.csv, 'spec.icon', [])[0].base64data
}`
desc.csv?.spec?.icon?.[0]
? `data:${desc.csv.spec.icon[0].mediatype};base64,${desc.csv.spec.icon[0].base64data}`
: operatorLogo;

const formatTileDescription = (csvDescription: string): string =>
`## Operator Description\n${csvDescription}`;
`## ${i18n.t('olm~Operator description')}\n${csvDescription}`;

const operatorProvidedAPIs: K8sResourceKind[] = _.flatten(
clusterServiceVersions.map((csv) => providedAPIsForCSV(csv).map((desc) => ({ ...desc, csv }))),
Expand All @@ -39,24 +38,27 @@ export const normalizeClusterServiceVersions = (
kind: 'InstalledOperator',
tileName: desc.displayName || desc.kind,
tileIconClass: null,
capabilityLevel: _.get(desc, ['csv', 'metadata', 'annotations', 'capabilities'], '')
capabilityLevel: (desc?.csv?.metadata?.annotations?.capabilities ?? '')
.toLowerCase()
.replace(/\s/g, ''),
tileImgUrl: imgFor(desc),
tileDescription: desc.description,
markdownDescription: formatTileDescription(desc.csv.spec.description),
tileProvider: desc.csv.spec.provider.name,
tags: desc.csv.spec.keywords,
createLabel: 'Create',
createLabel: i18n.t('public~Create'),
href: `/k8s/ns/${desc.csv.metadata.namespace}/clusterserviceversions/${
desc.csv.metadata.name
}/${referenceForProvidedAPI(desc)}/~new`,
supportUrl: desc.csv.metadata.annotations?.['marketplace.openshift.io/support-workflow'],
longDescription: `This resource is provided by ${desc.csv.spec.displayName}, a Kubernetes Operator enabled by the Operator Lifecycle Manager.`,
documentationUrl: _.get(
(desc.csv.spec.links || []).find(({ name }) => name === 'Documentation'),
'url',
longDescription: i18n.t(
'olm~This resource is provided by {{displayName}}, a Kubernetes Operator enabled by the Operator Lifecycle Manager.',
{
displayName: desc.csv.spec.displayName,
},
),
documentationUrl: (desc.csv.spec.links || []).find(({ name }) => name === 'Documentation')
?.url,
}));

return operatorProvidedAPIs;
Expand Down
12 changes: 6 additions & 6 deletions frontend/packages/operator-lifecycle-manager/src/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ const plugin: Plugin<ConsumedExtensions> = [
type: 'Catalog/ItemType',
properties: {
type: 'OperatorBackedService',
// t('operator-lifecycle-manager~Operator Backed')
title: '%operator-lifecycle-manager~Operator Backed%',
// t('operator-lifecycle-manager~Browse for a variety of managed services that are installed by cluster administrators. Cluster administrators can customize the content made available in the catalog.')
// t('olm~Operator Backed')
title: '%olm~Operator Backed%',
// t('olm~Browse for a variety of managed services that are installed by cluster administrators. Cluster administrators can customize the content made available in the catalog.')
catalogDescription:
'%operator-lifecycle-manager~Browse for a variety of managed services that are installed by cluster administrators. Cluster administrators can customize the content made available in the catalog.%',
// t('operator-lifecycle-manager~**Operator backed** includes a variety of services managed by Kubernetes controllers.')
'%olm~Browse for a variety of managed services that are installed by cluster administrators. Cluster administrators can customize the content made available in the catalog.%',
// t('olm~**Operator backed** includes a variety of services managed by Kubernetes controllers.')
typeDescription:
'%operator-lifecycle-manager~**Operator backed** includes a variety of services managed by Kubernetes controllers.%',
'%olm~**Operator backed** includes a variety of services managed by Kubernetes controllers.%',
groupings: [
{
label: 'Operators',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ClusterServiceVersionPhase,
ClusterServiceVersionStatus,
} from '../types';
import i18n from '@console/internal/i18n';

const pedingPhases = [
ClusterServiceVersionPhase.CSVPhasePending,
Expand All @@ -19,33 +20,37 @@ export const subscriptionForCSV = (
subscriptions: SubscriptionKind[],
csv: ClusterServiceVersionKind,
): SubscriptionKind =>
// TODO Replace _.find with Array.prototype.find
_.find(subscriptions, {
metadata: {
namespace: _.get(csv, ['metadata', 'annotations', 'olm.operatorNamespace']),
// FIXME Magic string. Make a constant.
namespace: csv?.metadata?.annotations?.['olm.operatorNamespace'],
},
status: {
installedCSV: getName(csv),
},
// TODO Imporove this type def
} as any); // 'as any' to supress typescript error caused by lodash;

export const getCSVStatus = (
csv: ClusterServiceVersionKind,
): { status: ClusterServiceVersionStatus; title: string } => {
const statusPhase = _.get(csv, 'status.phase', ClusterServiceVersionPhase.CSVPhaseUnknown);
const statusPhase = csv?.status?.phase ?? ClusterServiceVersionPhase.CSVPhaseUnknown;
// TODO Get rid of let.
let status: ClusterServiceVersionStatus;
if (pedingPhases.includes(statusPhase)) {
status = ClusterServiceVersionStatus.Pending;
status = i18n.t('olm~Pending');
} else {
switch (statusPhase) {
case ClusterServiceVersionPhase.CSVPhaseSucceeded:
status = ClusterServiceVersionStatus.OK;
status = i18n.t('olm~OK');
break;
case ClusterServiceVersionPhase.CSVPhaseFailed:
status = ClusterServiceVersionStatus.Failed;
status = i18n.t('olm~Failed');
break;
default:
return {
status: ClusterServiceVersionStatus.Unknown,
status: i18n.t('olm~Unknown'),
title: statusPhase,
};
}
Expand All @@ -62,17 +67,17 @@ export const getSubscriptionStatus = (subscription: SubscriptionKind): Subscript
case SubscriptionState.SubscriptionStateUpgradeAvailable:
return {
status,
title: 'Upgrade available',
title: i18n.t('olm~Upgrade available'),
};
case SubscriptionState.SubscriptionStateUpgradePending:
return {
status,
title: 'Upgrading',
title: i18n.t('olm~Upgrading'),
};
case SubscriptionState.SubscriptionStateAtLatest:
return {
status,
title: 'Up to date',
title: i18n.t('olm~Up to date'),
};
default:
return {
Expand Down
3 changes: 3 additions & 0 deletions frontend/packages/operator-lifecycle-manager/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export type StepResource = {
kind: string;
name: string;
manifest?: string;
sourceName?: string;
sourceNamespace?: string;
};

export type Step = {
Expand Down Expand Up @@ -235,6 +237,7 @@ export type PackageManifestKind = {
description?: string;
displayName: string;
icon: { mediatype: string; base64data: string }[];
keywords?: string[];
version: string;
provider: {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const ExpandCollapseDescription: React.FC<ExpandCollapseDescriptionProps>
};
return (
<ExpandCollapse
textExpanded={t('operator-lifecycle-manager~Hide operator description')}
textCollapsed={t('operator-lifecycle-manager~Show operator description')}
textExpanded={t('olm~Hide operator description')}
textCollapsed={t('olm~Show operator description')}
onToggle={toggle}
>
{/** used an empty Fragment here because Expandable always expects a children, using null throws react warning */}
Expand All @@ -41,7 +41,7 @@ const normalizeClusterServiceVersions = (
t: TFunction,
): CatalogItem[] => {
const formatTileDescription = (csvDescription: string): string =>
t('operator-lifecycle-manager~## Operator Description\n{{csvDescription}}', { csvDescription });
`## ${t('olm~Operator description')}\n${csvDescription}`;

const operatorProvidedAPIs: CatalogItem[] = _.flatten(
clusterServiceVersions.map((csv) => providedAPIsForCSV(csv).map((desc) => ({ ...desc, csv }))),
Expand All @@ -63,7 +63,7 @@ const normalizeClusterServiceVersions = (
desc.csv.metadata.annotations?.['marketplace.openshift.io/support-workflow'];
const markdownDescription = formatTileDescription(desc.csv.spec.description);
const longDescription = t(
'operator-lifecycle-manager~This resource is provided by {{operatorName}}, a Kubernetes Operator enabled by the Operator Lifecycle Manager.',
'olm~This resource is provided by {{operatorName}}, a Kubernetes Operator enabled by the Operator Lifecycle Manager.',
{ operatorName },
);
const documentationUrl = _.get(
Expand All @@ -76,7 +76,7 @@ const normalizeClusterServiceVersions = (

const detailsProperties = [
{
label: t('operator-lifecycle-manager~Capability Level'),
label: t('olm~Capability level'),
value: capabilityLevel,
},
];
Expand Down Expand Up @@ -118,7 +118,7 @@ const normalizeClusterServiceVersions = (
url: getImageForCSVIcon(desc.csv.spec.icon?.[0]),
},
cta: {
label: t('operator-lifecycle-manager~Create'),
label: t('public~Create'),
href: `/k8s/ns/${desc.csv.metadata.namespace}/clusterserviceversions/${
desc.csv.metadata.name
}/${referenceForProvidedAPI(desc)}/~new`,
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ i18n
'operator-hub-details',
'operator-hub-subscribe',
'operator-install-page',
'operator-lifecycle-manager',
'olm',
'pagerduty-receiver-form',
'pipelines-plugin',
'public',
Expand Down

0 comments on commit bbe2970

Please sign in to comment.