mirror of https://github.com/grafana/grafana.git
i18n: exports TFunction from @grafana/i18n package (#105921)
This commit is contained in:
parent
c35803d992
commit
c7cd06d5f5
|
|
@ -1,4 +1,4 @@
|
|||
import i18n, { InitOptions, ReactOptions, TFunction } from 'i18next';
|
||||
import i18n, { InitOptions, ReactOptions, TFunction as I18NextTFunction } from 'i18next';
|
||||
import LanguageDetector, { DetectorOptions } from 'i18next-browser-languagedetector';
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { initReactI18next, setDefaults, setI18n, Trans as I18NextTrans, getI18n } from 'react-i18next';
|
||||
|
|
@ -6,9 +6,9 @@ import { initReactI18next, setDefaults, setI18n, Trans as I18NextTrans, getI18n
|
|||
import { DEFAULT_LANGUAGE, PSEUDO_LOCALE } from './constants';
|
||||
import { initRegionalFormat } from './dates';
|
||||
import { LANGUAGES } from './languages';
|
||||
import { TransProps, TransType } from './types';
|
||||
import { TFunction, TransProps, TransType } from './types';
|
||||
|
||||
let tFunc: TFunction<string[], undefined> | undefined;
|
||||
let tFunc: I18NextTFunction<string[], undefined> | undefined;
|
||||
let transComponent: TransType;
|
||||
|
||||
export async function initPluginTranslations(id: string) {
|
||||
|
|
@ -140,7 +140,7 @@ export function addResourceBundle(language: string, namespace: string, resource:
|
|||
getI18nInstance().addResourceBundle(language, namespace, resource, undefined, true);
|
||||
}
|
||||
|
||||
export function t(id: string, defaultMessage: string, values?: Record<string, unknown>) {
|
||||
export const t: TFunction = (id: string, defaultMessage: string, values?: Record<string, unknown>) => {
|
||||
if (!tFunc) {
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
console.warn(
|
||||
|
|
@ -156,7 +156,7 @@ export function t(id: string, defaultMessage: string, values?: Record<string, un
|
|||
}
|
||||
|
||||
return tFunc(id, defaultMessage, values);
|
||||
}
|
||||
};
|
||||
|
||||
export function useTranslate() {
|
||||
return { t };
|
||||
|
|
|
|||
|
|
@ -23,5 +23,5 @@ export {
|
|||
DEFAULT_LANGUAGE,
|
||||
} from './constants';
|
||||
export { initPluginTranslations, Trans, useTranslate } from './i18n';
|
||||
export type { TransProps } from './types';
|
||||
export type { TFunction, TransProps } from './types';
|
||||
export { formatDate, formatDuration, formatDateRange } from './dates';
|
||||
|
|
|
|||
|
|
@ -9,12 +9,6 @@
|
|||
* preventing the code from being importable by plugins or other npm packages making it truly "internal".
|
||||
*
|
||||
*/
|
||||
import { t } from '../i18n';
|
||||
|
||||
type TFunction = typeof t;
|
||||
|
||||
export type { TFunction };
|
||||
export { t };
|
||||
|
||||
export {
|
||||
addResourceBundle,
|
||||
|
|
@ -23,4 +17,5 @@ export {
|
|||
getLanguage,
|
||||
getResolvedLanguage,
|
||||
initializeI18n,
|
||||
t,
|
||||
} from '../i18n';
|
||||
|
|
|
|||
|
|
@ -60,4 +60,9 @@ declare function Trans(props: TransProps): React.ReactElement;
|
|||
*/
|
||||
type TransType = typeof Trans;
|
||||
|
||||
export type { UseTranslateHook, TransProps, TransType };
|
||||
/**
|
||||
* Type for the translation function
|
||||
*/
|
||||
type TFunction = (id: string, defaultMessage: string, values?: Record<string, unknown>) => string;
|
||||
|
||||
export type { UseTranslateHook, TransProps, TransType, TFunction };
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { css } from '@emotion/css';
|
||||
|
||||
import { FeatureState, GrafanaTheme2, ThemeRegistryItem } from '@grafana/data';
|
||||
import { useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, useTranslate } from '@grafana/i18n';
|
||||
import { FeatureBadge, RadioButtonDot, useStyles2 } from '@grafana/ui';
|
||||
|
||||
import { ThemePreview } from '../Theme/ThemePreview';
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import { css } from '@emotion/css';
|
|||
import { useMemo } from 'react';
|
||||
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { Trans, useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, Trans, useTranslate } from '@grafana/i18n';
|
||||
import { Grid, Modal, useStyles2, Text } from '@grafana/ui';
|
||||
import { getModKey } from 'app/core/utils/browser';
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ import { FC, useCallback, useMemo, useState } from 'react';
|
|||
import { Controller, FormProvider, useFieldArray, useForm, useFormContext } from 'react-hook-form';
|
||||
|
||||
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
|
||||
import { Trans, useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, Trans, useTranslate } from '@grafana/i18n';
|
||||
import { Button, Field, InlineLabel, Input, LoadingPlaceholder, Space, Stack, Text, useStyles2 } from '@grafana/ui';
|
||||
|
||||
import { labelsApi } from '../../../api/labelsApi';
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import { css } from '@emotion/css';
|
|||
import { Controller, useFormContext } from 'react-hook-form';
|
||||
|
||||
import { DataSourceInstanceSettings, GrafanaTheme2 } from '@grafana/data';
|
||||
import { Trans, useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, Trans, useTranslate } from '@grafana/i18n';
|
||||
import { Card, Field, FieldSet, Input, useStyles2 } from '@grafana/ui';
|
||||
import { DataSourcePicker } from 'app/features/datasources/components/picker/DataSourcePicker';
|
||||
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { DataSourceInstanceSettings } from '@grafana/data';
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
import { useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, useTranslate } from '@grafana/i18n';
|
||||
import { DataSourceRef } from '@grafana/schema';
|
||||
|
||||
import { useDatasources } from '../../hooks';
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ import { firstValueFrom } from 'rxjs';
|
|||
|
||||
import { AppEvents, PanelData, SelectableValue, LoadingState } from '@grafana/data';
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
import { Trans, useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, Trans, useTranslate } from '@grafana/i18n';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
import { Button, CodeEditor, Field, Select, useStyles2 } from '@grafana/ui';
|
||||
import { appEvents } from 'app/core/core';
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ import { usePrevious } from 'react-use';
|
|||
import { ListChildComponentProps, ListOnItemsRenderedProps } from 'react-window';
|
||||
|
||||
import { AbsoluteTimeRange, LogsSortOrder, TimeRange } from '@grafana/data';
|
||||
import { useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, useTranslate } from '@grafana/i18n';
|
||||
import { config, reportInteraction } from '@grafana/runtime';
|
||||
import { Spinner, useStyles2 } from '@grafana/ui';
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ import { useId } from 'react';
|
|||
import { SubmitHandler, useForm } from 'react-hook-form';
|
||||
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { Trans, useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, Trans, useTranslate } from '@grafana/i18n';
|
||||
import { Modal, Button, Stack, TextLink, Field, Input, Text, useStyles2 } from '@grafana/ui';
|
||||
import { AlertWithTraceID } from 'app/features/migrate-to-cloud/shared/AlertWithTraceID';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { skipToken } from '@reduxjs/toolkit/query/react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import { Trans, useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, Trans, useTranslate } from '@grafana/i18n';
|
||||
import { config } from '@grafana/runtime';
|
||||
import { AlertVariant, Box, Stack, Text } from '@grafana/ui';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { Trans, useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, Trans, useTranslate } from '@grafana/i18n';
|
||||
import { Button, Modal, Stack, Text } from '@grafana/ui';
|
||||
|
||||
import { MigrateDataResponseItemDto } from '../api';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, useTranslate } from '@grafana/i18n';
|
||||
import { CellProps } from '@grafana/ui';
|
||||
|
||||
import { ResourceTableItem } from './types';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { useRef, useEffect } from 'react';
|
||||
|
||||
import { useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, useTranslate } from '@grafana/i18n';
|
||||
import { useAppNotification } from 'app/core/copy/appNotification';
|
||||
|
||||
import { GetSnapshotResponseDto, SnapshotDto } from '../api';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
import { useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, useTranslate } from '@grafana/i18n';
|
||||
import { config, reportInteraction } from '@grafana/runtime';
|
||||
import { ConfirmModal } from '@grafana/ui';
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import { useEffect, useMemo, useState } from 'react';
|
|||
import { Controller, useForm } from 'react-hook-form';
|
||||
import { useNavigate } from 'react-router-dom-v5-compat';
|
||||
|
||||
import { Trans, useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, Trans, useTranslate } from '@grafana/i18n';
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import { css } from '@emotion/css';
|
|||
import { useState } from 'react';
|
||||
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { Trans, useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, Trans, useTranslate } from '@grafana/i18n';
|
||||
import { Alert, Stack, useStyles2 } from '@grafana/ui';
|
||||
import { useGetFrontendSettingsQuery, Repository } from 'app/api/clients/provisioning';
|
||||
import provisioningSvg from 'img/provisioning/provisioning.svg';
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { useMemo } from 'react';
|
||||
|
||||
import { intervalToAbbreviatedDurationString, TraceKeyValuePair } from '@grafana/data';
|
||||
import { Trans, useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, Trans, useTranslate } from '@grafana/i18n';
|
||||
import { Alert, Badge, Box, Card, Icon, InteractiveTable, Spinner, Stack, Text } from '@grafana/ui';
|
||||
import { Job, Repository, SyncStatus } from 'app/api/clients/provisioning';
|
||||
import KeyValuesTable from 'app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/KeyValuesTable';
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import { FormProvider, useForm } from 'react-hook-form';
|
|||
import { useNavigate } from 'react-router-dom-v5-compat';
|
||||
|
||||
import { AppEvents, GrafanaTheme2 } from '@grafana/data';
|
||||
import { useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, useTranslate } from '@grafana/i18n';
|
||||
import { getAppEvents, isFetchError } from '@grafana/runtime';
|
||||
import { Alert, Box, Button, Stack, Text, useStyles2 } from '@grafana/ui';
|
||||
import { useDeleteRepositoryMutation, useGetFrontendSettingsQuery } from 'app/api/clients/provisioning';
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import { css } from '@emotion/css';
|
|||
import { FormEvent } from 'react';
|
||||
|
||||
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
|
||||
import { Trans, useTranslate } from '@grafana/i18n';
|
||||
import { TFunction } from '@grafana/i18n/internal';
|
||||
import { TFunction, Trans, useTranslate } from '@grafana/i18n';
|
||||
import { config } from '@grafana/runtime';
|
||||
import { Button, Checkbox, Stack, RadioButtonGroup, useStyles2 } from '@grafana/ui';
|
||||
import { SortPicker } from 'app/core/components/Select/SortPicker';
|
||||
|
|
|
|||
Loading…
Reference in New Issue