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

[Refactoring] User-Facing Strings Should Be Wrapped #330

Open
sejli opened this issue Oct 11, 2023 · 3 comments · May be fixed by #334
Open

[Refactoring] User-Facing Strings Should Be Wrapped #330

sejli opened this issue Oct 11, 2023 · 3 comments · May be fixed by #334
Assignees
Labels
good first issue Good for newcomers

Comments

@sejli
Copy link
Member

sejli commented Oct 11, 2023

Description

This has been brought to attention by this comment on a PR. We have many user-facing strings that are not wrapped for internalization. This is not consistent with OpenSearch Dashboards guidelines. User-facing strings should be updated to be compatible with the default message extraction tool.

OSD example usage

<EuiEmptyPrompt
          iconType="alert"
          iconColor="danger"
          title={
            <h2>
              <FormattedMessage
                id="core.application.appNotFound.title"
                defaultMessage="Application Not Found"
              />
            </h2>
          }
          body={
            <p>
              <FormattedMessage
                id="core.application.appNotFound.pageDescription"
                defaultMessage="No application was found at this URL. Try going back or choosing an app from the menu."
              />
            </p>
          }
        />

dashboards-search-relevance example of missing FormattedMessage

@nung22
Copy link
Contributor

nung22 commented Oct 16, 2023

@sejli I'd like to pick this up

@noCharger
Copy link
Collaborator

noCharger commented Oct 17, 2023

Thanks for picking it up @nung22 !

@nung22 nung22 linked a pull request Oct 17, 2023 that will close this issue
@nung22
Copy link
Contributor

nung22 commented Nov 8, 2023

Notes for wrapping user-facing strings

Collection of resources for completing this task.

Procedures

I18n Provider

Translated components need to be wrapped by I18nProvider.

Before translation:

export const Flyout = () => {
  const { setShowFlyout } = useSearchRelevanceContext();

  return (
    <EuiFlyout>
      {...}
    </EuiFlyout>
  );
};

After translation:

import { I18nProvider, FormattedMessage } from '@osd/i18n/react';

export const Flyout = () => {
  const { setShowFlyout } = useSearchRelevanceContext();

  return (
    <I18nProvider>
      <EuiFlyout>
        {...}
      </EuiFlyout>
    </I18nProvider>
  );
};

Simple Message

Before translation:

<p>Add at least one query to display search results.</p>

After translation:

<p>
    <FormattedMessage
         id="searchRelevance.result.noQueryPrompt"
         defaultMessage="Add at least one query to display search results."
     />
</p>

Complex Message (contains other tags like OuiCode, OuiLink, and strong)

String should be divided with inner messages placed into the values property of FormattedMessage

Before translation:

<p>
  Enter a query in{' '}
  <EuiLink
    target="_blank"
    href="https://opensearch.org/docs/latest/opensearch/query-dsl/index/"
  >
    OpenSearch Query DSL
  </EuiLink>
  . Use the <EuiCode>%SearchText%</EuiCode> variable to refer to the text in the search
  bar. When you enter <strong>Search</strong>, the queries are sent to the search engine
  using the <EuiCode>GET</EuiCode> HTTP method and the <EuiCode>_search</EuiCode>{' '}
  endpoint.
</p>

After translation:

<p>
  <FormattedMessage
    id="searchRelevance.flyout.queryFormatDetail"
    defaultMessage="Enter a query in {queryDslLink}. Use the {variableName} variable to refer
    to the text in the search bar. When you enter {strongSearch}, the queries are sent to the search
    engine using the {methodName} HTTP method and the {endpointName} endpoint."
    values={{
      queryDslLink: (
        <EuiLink
          target="_blank"
          href="https://opensearch.org/docs/latest/opensearch/query-dsl/index/"
        >
          <FormattedMessage
            id="searchRelevance.flyout.queryFormatDetail.queryDslLinkLabel"
            defaultMessage="OpenSearch Query DSL"
          />
        </EuiLink>
      ),
      variableName: (
        <EuiCode>
          <FormattedMessage
            id="searchRelevance.flyout.queryFormatDetail.variableNameCodeLabel"
            defaultMessage="%SearchText%"
          />
        </EuiCode>
      ),
      strongSearch: (
        <strong>
          <FormattedMessage
            id="searchRelevance.flyout.queryFormatDetail.strongSearchLabel"
            defaultMessage="Search"
          />
        </strong>
      ),
      methodName: (
        <EuiCode>
          <FormattedMessage
            id="searchRelevance.flyout.queryFormatDetail.methodNameCodeLabel"
            defaultMessage="GET"
          />
        </EuiCode>
      ),
      endpointName: (
        <EuiCode>
          <FormattedMessage
            id="searchRelevance.flyout.queryFormatDetail.endpointNameCodeLabel"
            defaultMessage="_search"
          />
        </EuiCode>
      ),
    }}
  />
</p>

Unit Tests

Replace mount with shallow in the test file.

Before translation:

import { configure, mount } from 'enzyme';
const wrapper = mount(
  <SearchRelevanceContextProvider>
    <Flyout />
  </SearchRelevanceContextProvider>
);

After translation:

import { configure, shallow } from 'enzyme';
const wrapper = shallow(
  <SearchRelevanceContextProvider>
    <Flyout />
  </SearchRelevanceContextProvider>
);

Documentation

Similar Implementations in OSD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants