Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add i18n to topology package #7315

Merged

Conversation

jeff-phillips-18
Copy link
Member

@openshift-ci-robot openshift-ci-robot added the component/knative Related to knative-plugin label Nov 24, 2020
@openshift-ci-robot openshift-ci-robot added component/kubevirt Related to kubevirt-plugin component/sdk Related to console-plugin-sdk component/shared Related to console-shared labels Nov 24, 2020
@jeff-phillips-18
Copy link
Member Author

/retest

Comment on lines 22 to 28
<strong>{node.getLabel()}</strong>
{targetGroup
? t('topology~ from {{sourceGroup}} to {{targetGroup}}?', {
sourceGroup: sourceGroup.getLabel(),
targetGroup: targetGroup.getLabel(),
})
: t('topology~ from {{sourceGroup}}?', { sourceGroup: sourceGroup.getLabel() })}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 There is a pattern that can be used here...

Quick search through the codebase got me:

"teams-help": "Optionally list organizations. If specified, only GitHub users that are members of at least one of the listed organizations will be allowed to log in. Cannot be used in combination with <1>teams</1>.",

And:

            <Trans i18nKey="teams-help" ns="github-idp-form">
              Optionally list organizations. If specified, only GitHub users that are members of at
              least one of the listed organizations will be allowed to log in. Cannot be used in
              combination with <strong>teams</strong>.
            </Trans>

Ref: github-idp-form.tsx

cc @christianvogt might know more -- I'm reverse engineering here.

@@ -29,15 +30,15 @@ const cleanUpWorkloadNode = async (workload: OdcNodeModel): Promise<K8sResourceK
return cleanUpWorkload(workload.resource, workload.data?.isKnativeResource ?? false);
};

const deleteGroup = (application: TopologyApplicationObject) => {
const deleteGroup = (application: TopologyApplicationObject, t: TFunction) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, you put t at the start of other methods 🤔

I have no opinion one way or another, just thought it was noteworthy.

Comment on lines 80 to 82
{t('topology~Connect')}
<strong>{` ${edge.getSource().getLabel()} `}</strong>
to
{t('topology~to')}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be one translation otherwise it won't come out properly in other languages.


const ConnectedTopologyServiceBindingRequestPanel: React.FC<PropsFromState &
PropsFromDispatch &
TopologyServiceBindingRequestPanelProps> = ({ edge, onClickTab, selectedDetailsTab }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what is happening here... why this change? Seems like new functionality for an I18n PR.

@andrewballantyne
Copy link
Contributor

Add page looks translated...
Screen Shot 2020-11-26 at 2 48 34 PM
But we have actions that don't look translated:
Screen Shot 2020-11-26 at 2 48 21 PM
Screen Shot 2020-11-26 at 2 49 13 PM
Screen Shot 2020-11-26 at 2 52 31 PM


Sidebar has a lot of non-translated chunks... not sure if that's a topology package issue with the new code location 🤔
Screen Shot 2020-11-26 at 2 49 56 PM


All the actions but the two layouts look uncaught by I18n...
Screen Shot 2020-11-26 at 2 50 11 PM


Partially missing translation:
Screen Shot 2020-11-26 at 2 51 23 PM


Not sure who covers the build decorator 🤔 This is in the Topology package... so I assume this PR...
Screen Shot 2020-11-26 at 2 52 08 PM

Copy link
Contributor

@christianvogt christianvogt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I question the use of passing around t over simply using the global translation function when the translation of errors isn't reactive anyways.


namespace ExtensionProperties {
export interface PostFormSubmissionAction<T, P> {
/** action type */
type: string;
/** callback for the related action */
callback: (arg: T, payload?: P) => Promise<T>;
callback: (t: TFunction, arg: T, payload?: P) => Promise<T>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary. It seems like the only reason for translation is related to error messages.
These error messages can be translated using the global i18next object because there's no way these will be reactive anyways to a change in locale. We wouldn't be running the callback again with the new lang so therefore it's a one time translation.

const resourceObj = getResource(edge.getSource());
const resourceModel = modelFor(referenceFor(resourceObj));

return {
label: 'Move Connector',
label: t('topology~Move Connector'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use labelKey for actions.

callback: () => {
moveConnectionModal({ edge, availableTargets });
moveConnectionModal({ edge, availableTargets, t: (x) => x });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary to pass t here because the modal has access to useTranslation or withTranslation.

@@ -15,33 +16,33 @@ import { TYPE_CONNECTS_TO, TYPE_SERVICE_BINDING, TYPE_TRAFFIC_CONNECTOR } from '
import { moveConnectionModal } from '../components/modals/MoveConnectionModal';
import { removeConnection } from '../utils';

const moveConnection = (edge: Edge, availableTargets: Node[]) => {
const moveConnection = (edge: Edge, availableTargets: Node[], t: TFunction) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use labelKey for actions.
Same comment for all actions.

submitDanger: true,
executeFn: () => {
return removeTopologyResourceConnection(edge).catch((err) => {
return removeTopologyResourceConnection(t, edge).catch((err) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have confirmModal accept a callback which is either executed in the render context so that the function can use useTranslation or it gets passed in the translation function. This would make it easier to use these modal launchers without the need for the consumer to provide it's own t function.

@@ -97,6 +98,7 @@ export const getResourceKind = (node: Node): K8sResourceKindReference => {
};

export const updateTopologyResourceApplication = (
t: TFunction,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again it seems we're passing around t to localize the return value of async operations that won't be re-run if the locale changes.
Seems unnecessary to pass t around everywhere for this and instead use the global i18next

aria-label="Shortcuts"
bodyContent={TopologyShortcuts}
aria-label={t('topology~Shortcuts')}
bodyContent={getTopologyShortcuts(t)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API accepts a ReactNode. TopologyShortcuts can make use of useTranslation

Suggested change
bodyContent={getTopologyShortcuts(t)}
bodyContent={<TopologyShortcuts />}

@@ -42,6 +45,7 @@ const MoveConnectionForm: React.FC<FormikProps<FormikValues> & MoveConnectionMod
isSubmitting,
cancel,
values,
t,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use useTranslation instead.

@@ -31,6 +34,7 @@ type EditApplicationModalProps = EditApplicationFormProps & {
};

const EditApplicationForm: React.FC<FormikProps<FormikValues> & EditApplicationFormProps> = ({
t,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use useTranslation instead.

@@ -75,7 +76,7 @@ export const groupContextMenu = (element: Node, connectorSource?: Node) => {

const graphData = element.getGraph().getData();
return createMenuItems(
kebabOptionsToMenu(groupActions(graphData, applicationData, connectorSource)),
kebabOptionsToMenu(groupActions(t, graphData, applicationData, connectorSource)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actions can use labelKey

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 27, 2020
@openshift-ci-robot openshift-ci-robot added component/core Related to console core functionality component/dev-console Related to dev-console needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 30, 2020
@jeff-phillips-18
Copy link
Member Author

@andrewballantyne Side bar is part of public/components/overview (not topology). I believe I have addressed other comments.

@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 1, 2020
@vikram-raj
Copy link
Member

/retest

Comment on lines 57 to 61
<<<<<<< HEAD
const { filters, setTopologyFilters: onFiltersChange } = React.useContext(FilterContext);
=======
const { t } = useTranslation();
>>>>>>> Add i18n to topology package
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeff-phillips-18 Missed this Merge conflict marker encountered.

Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I misunderstand Trans vs t ... but I think you can use t for all strings, and Trans when React components or DOM elements get in the way

Comment on lines 113 to 115
Search results may appear outside of the visible area.{' '}
<Trans ns="topology">
Search results may appear outside of the visible area.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need the space 🤔

const title = targetGroup ? (
<Trans ns="topology">Move Component Node</Trans>
) : (
<Trans ns="topology">Remove Component Node from Application</Trans>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think you need to use Trans on static strings 🤔

const btnText = targetGroup ? (
<Trans ns="topology">Move</Trans>
) : (
<Trans ns="topology">Remove</Trans>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

<Trans ns="topology">
Deleting the visual connector removes the `connects-to` annotation from the resources. Are
you sure you want to delete the visual connector?
</Trans>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

</p>
);

return confirmModal({
title: (
<>
<YellowExclamationTriangleIcon className="co-icon-space-r" /> Delete Connector?
<YellowExclamationTriangleIcon className="co-icon-space-r" />{' '}
<Trans ns="topology">Delete Connector?</Trans>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

</>
),
message,
btnText: 'Delete',
btnText: <Trans ns="topology">Delete</Trans>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -17,6 +18,7 @@ type TopologyEdgeResourcesPanelProps = {
};

const TopologyEdgeResourcesPanel: React.FC<TopologyEdgeResourcesPanelProps> = ({ edge }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed Connections string passed to SidebarSectionHeading on line 36.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, missed the title missing.

With the pseudo lang:
Screen Shot 2020-12-01 at 11 36 18 AM

With the "default" lang:
Screen Shot 2020-12-01 at 11 36 23 AM

Copy link
Member

@vikram-raj vikram-raj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing header of the connector sidepanel
missing-connector-header

missing key warning
missing-key-warning

@@ -38,7 +39,8 @@ export const AddHealthChecks = (model: K8sKind, obj: K8sResourceKind): KebabOpti

export const EditHealthChecks = (model: K8sKind, obj: K8sResourceKind): KebabOption => {
return {
label: 'Edit Health Checks',
// t('console-app~Edit Health Checks')
labelKey: 'Edit Health Checks',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
labelKey: 'Edit Health Checks',
labelKey: 'console-app~Edit Health Checks',

{ready} of {desired} pods
</Link>
);
return <Link to={href}>{t('topology~{{ready}} of {{desired}} pods', { ready, desired })}</Link>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return <Link to={href}>{t('topology~{{ready}} of {{desired}} pods', { ready, desired })}</Link>;
return <Link to={href}>{t('topology~{{ready, number}} of {{count, number}} pod', { ready, count: desired })}</Link>;

@jeff-phillips-18
Copy link
Member Author

@andrewballantyne @vikram-raj Updated per comments.

@@ -50,11 +53,11 @@ const StatusCellResourceStatus: React.FC<StatusCellResourceStatus> = ({ obj, pod
if (!filteredPods.length) {
return null;
}
return <Link to={href}>{filteredPods.length} pods</Link>;
return <Link to={href}>{t('topology~{{length}} pods', { length: filteredPods.length })}</Link>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return <Link to={href}>{t('topology~{{length}} pods', { length: filteredPods.length })}</Link>;
return <Link to={href}>{t('topology~{{count, number}} pod', { count: filteredPods.length })}</Link>;

Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 1, 2020
@christianvogt
Copy link
Contributor

/approve

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 1, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 1, 2020
@andrewballantyne
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 1, 2020
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne, christianvogt, jeff-phillips-18

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 838da0c into openshift:master Dec 2, 2020
@jeff-phillips-18 jeff-phillips-18 deleted the topology-i18n branch December 2, 2020 13:32
@spadgett spadgett added this to the v4.7 milestone Dec 9, 2020
@spadgett spadgett added the kind/i18n Indicates issue or PR relates to internationalization or has content that needs to be translated label Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/core Related to console core functionality component/dev-console Related to dev-console component/knative Related to knative-plugin component/kubevirt Related to kubevirt-plugin component/sdk Related to console-plugin-sdk component/shared Related to console-shared kind/i18n Indicates issue or PR relates to internationalization or has content that needs to be translated lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants