From 8d2b3f973e1c047a0fe9185039b32ce4acd673c2 Mon Sep 17 00:00:00 2001 From: siddhikhapare <81567515+siddhikhapare@users.noreply.github.com> Date: Mon, 30 Oct 2023 16:06:08 +0530 Subject: [PATCH] Rich history drawer: Translation added (#77088) * query history translation added * Recommended changes added --- public/app/core/utils/richHistory.ts | 52 +++++++-- .../explore/RichHistory/RichHistory.tsx | 22 ++-- .../explore/RichHistory/RichHistoryCard.tsx | 106 +++++++++++++---- .../RichHistory/RichHistoryContainer.tsx | 7 +- .../RichHistory/RichHistoryQueriesTab.tsx | 66 +++++++++-- .../RichHistory/RichHistorySettingsTab.tsx | 66 ++++++++--- .../RichHistory/RichHistoryStarredTab.tsx | 50 ++++++-- .../app/features/explore/SecondaryActions.tsx | 13 ++- public/locales/de-DE/grafana.json | 109 ++++++++++++++++++ public/locales/en-US/grafana.json | 109 ++++++++++++++++++ public/locales/es-ES/grafana.json | 109 ++++++++++++++++++ public/locales/fr-FR/grafana.json | 109 ++++++++++++++++++ public/locales/pseudo-LOCALE/grafana.json | 109 ++++++++++++++++++ public/locales/zh-Hans/grafana.json | 109 ++++++++++++++++++ 14 files changed, 952 insertions(+), 84 deletions(-) diff --git a/public/app/core/utils/richHistory.ts b/public/app/core/utils/richHistory.ts index 9a4b64b1454..459e62b56d0 100644 --- a/public/app/core/utils/richHistory.ts +++ b/public/app/core/utils/richHistory.ts @@ -5,6 +5,7 @@ import { serializeStateToUrlParam } from '@grafana/data/src/utils/url'; import { getDataSourceSrv } from '@grafana/runtime'; import { notifyApp } from 'app/core/actions'; import { createErrorNotification, createWarningNotification } from 'app/core/copy/appNotification'; +import { t } from 'app/core/internationalization'; import { dispatch } from 'app/store/store'; import { RichHistoryQuery } from 'app/types/explore'; @@ -57,7 +58,14 @@ export async function addToRichHistory( richHistoryStorageFull = true; showQuotaExceededError && dispatch(notifyApp(createErrorNotification(error.message))); } else if (error.name !== RichHistoryServiceError.DuplicatedEntry) { - dispatch(notifyApp(createErrorNotification('Rich History update failed', error.message))); + dispatch( + notifyApp( + createErrorNotification( + t('explore.rich-history-utils-notification.update-failed', 'Rich History update failed'), + error.message + ) + ) + ); } } // Saving failed. Do not add new entry. @@ -98,7 +106,14 @@ export async function updateStarredInRichHistory(id: string, starred: boolean) { return await getRichHistoryStorage().updateStarred(id, starred); } catch (error) { if (error instanceof Error) { - dispatch(notifyApp(createErrorNotification('Saving rich history failed', error.message))); + dispatch( + notifyApp( + createErrorNotification( + t('explore.rich-history-utils-notification.saving-failed', 'Saving rich history failed'), + error.message + ) + ) + ); } return undefined; } @@ -109,7 +124,14 @@ export async function updateCommentInRichHistory(id: string, newComment: string return await getRichHistoryStorage().updateComment(id, newComment); } catch (error) { if (error instanceof Error) { - dispatch(notifyApp(createErrorNotification('Saving rich history failed', error.message))); + dispatch( + notifyApp( + createErrorNotification( + t('explore.rich-history-utils-notification.saving-failed', 'Saving rich history failed'), + error.message + ) + ) + ); } return undefined; } @@ -121,7 +143,14 @@ export async function deleteQueryInRichHistory(id: string) { return id; } catch (error) { if (error instanceof Error) { - dispatch(notifyApp(createErrorNotification('Saving rich history failed', error.message))); + dispatch( + notifyApp( + createErrorNotification( + t('explore.rich-history-utils-notification.saving-failed', 'Saving rich history failed'), + error.message + ) + ) + ); } return undefined; } @@ -130,7 +159,10 @@ export async function deleteQueryInRichHistory(id: string) { export const createUrlFromRichHistory = (query: RichHistoryQuery) => { const exploreState: ExploreUrlState = { /* Default range, as we are not saving timerange in rich history */ - range: { from: 'now-1h', to: 'now' }, + range: { + from: t('explore.rich-history-utils.default-from', 'now-1h'), + to: t('explore.rich-history-utils.default-to', 'now'), + }, datasource: query.datasourceName, queries: query.queries, }; @@ -146,19 +178,19 @@ export const mapNumbertoTimeInSlider = (num: number) => { let str; switch (num) { case 0: - str = 'today'; + str = t('explore.rich-history-utils.today', 'today'); break; case 1: - str = 'yesterday'; + str = t('explore.rich-history-utils.yesterday', 'yesterday'); break; case 7: - str = 'a week ago'; + str = t('explore.rich-history-utils.a-week-ago', 'a week ago'); break; case 14: - str = 'two weeks ago'; + str = t('explore.rich-history-utils.two-weeks-ago', 'two weeks ago'); break; default: - str = `${num} days ago`; + str = t('explore.rich-history-utils.days-ago', '{{num}} days ago', { num: `${num}` }); } return str; diff --git a/public/app/features/explore/RichHistory/RichHistory.tsx b/public/app/features/explore/RichHistory/RichHistory.tsx index 7998e2cc4dc..06ef8bbdb54 100644 --- a/public/app/features/explore/RichHistory/RichHistory.tsx +++ b/public/app/features/explore/RichHistory/RichHistory.tsx @@ -3,6 +3,7 @@ import React, { PureComponent } from 'react'; import { SelectableValue } from '@grafana/data'; import { Themeable2, TabbedContainer, TabConfig, withTheme2 } from '@grafana/ui'; +import { t } from 'app/core/internationalization'; import { SortOrder, RichHistorySearchFilters, RichHistorySettings } from 'app/core/utils/richHistory'; import { RichHistoryQuery } from 'app/types/explore'; @@ -20,10 +21,10 @@ export enum Tabs { export const getSortOrderOptions = () => [ - { label: 'Newest first', value: SortOrder.Descending }, - { label: 'Oldest first', value: SortOrder.Ascending }, - { label: 'Data source A-Z', value: SortOrder.DatasourceAZ }, - { label: 'Data source Z-A', value: SortOrder.DatasourceZA }, + { label: t('explore.rich-history.newest-first', 'Newest first'), value: SortOrder.Descending }, + { label: t('explore.rich-history.oldest-first', 'Oldest first'), value: SortOrder.Ascending }, + { label: t('explore.rich-history.datasource-a-z', 'Data source A-Z'), value: SortOrder.DatasourceAZ }, + { label: t('explore.rich-history.datasource-z-a', 'Data source Z-A'), value: SortOrder.DatasourceZA }, ].filter((option) => supportedFeatures().availableFilters.includes(option.value)); export interface RichHistoryProps extends Themeable2 { @@ -112,7 +113,7 @@ class UnThemedRichHistory extends PureComponent { const { loading } = this.state; const QueriesTab: TabConfig = { - label: 'Query history', + label: t('explore.rich-history.query-history', 'Query history'), value: Tabs.RichHistory, content: ( { }; const StarredTab: TabConfig = { - label: 'Starred', + label: t('explore.rich-history.starred', 'Starred'), value: Tabs.Starred, content: ( { }; const SettingsTab: TabConfig = { - label: 'Settings', + label: t('explore.rich-history.settings', 'Settings'), value: Tabs.Settings, content: ( { let tabs = [QueriesTab, StarredTab, SettingsTab]; return ( - + ); } } diff --git a/public/app/features/explore/RichHistory/RichHistoryCard.tsx b/public/app/features/explore/RichHistory/RichHistoryCard.tsx index 0f6d22249fb..9f418088739 100644 --- a/public/app/features/explore/RichHistory/RichHistoryCard.tsx +++ b/public/app/features/explore/RichHistory/RichHistoryCard.tsx @@ -9,6 +9,7 @@ import { DataQuery } from '@grafana/schema'; import { TextArea, Button, IconButton, useStyles2, LoadingPlaceholder } from '@grafana/ui'; import { notifyApp } from 'app/core/actions'; import { createSuccessNotification } from 'app/core/copy/appNotification'; +import { Trans, t } from 'app/core/internationalization'; import { copyStringToClipboard } from 'app/core/utils/explore'; import { createUrlFromRichHistory, createQueryText } from 'app/core/utils/richHistory'; import { createAndCopyShortLink } from 'app/core/utils/shortLinks'; @@ -214,7 +215,11 @@ export function RichHistoryCard(props: Props) { .join('\n'); copyStringToClipboard(queriesText); - dispatch(notifyApp(createSuccessNotification('Query copied to clipboard'))); + dispatch( + notifyApp( + createSuccessNotification(t('explore.rich-history-notification.query-copied', 'Query copied to clipboard')) + ) + ); }; const onCreateShortLink = async () => { @@ -225,7 +230,9 @@ export function RichHistoryCard(props: Props) { const onDeleteQuery = () => { const performDelete = (queryId: string) => { deleteHistoryItem(queryId); - dispatch(notifyApp(createSuccessNotification('Query deleted'))); + dispatch( + notifyApp(createSuccessNotification(t('explore.rich-history-notification.query-deleted', 'Query deleted'))) + ); reportInteraction('grafana_explore_query_history_deleted', { queryHistoryEnabled: config.queryHistoryEnabled, }); @@ -235,9 +242,12 @@ export function RichHistoryCard(props: Props) { if (query.starred) { getAppEvents().publish( new ShowConfirmModalEvent({ - title: 'Delete', - text: 'Are you sure you want to permanently delete your starred query?', - yesText: 'Delete', + title: t('explore.rich-history-card.delete-query-confirmation-title', 'Delete'), + text: t( + 'explore.rich-history-card.delete-starred-query-confirmation-text', + 'Are you sure you want to permanently delete your starred query?' + ), + yesText: t('explore.rich-history-card.confirm-delete', 'Delete'), icon: 'trash-alt', onConfirm: () => performDelete(query.id), }) @@ -281,18 +291,31 @@ export function RichHistoryCard(props: Props) { }; const updateComment = ( -
+