From 5d45af111015a7611b3753eb05a3fb6c3406ffbc Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Wed, 15 Jan 2025 17:31:06 +0100 Subject: [PATCH] I18n: Add doc comment for t() (#99024) * Add comment doc * Reorder information --- public/app/core/internationalization/index.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/public/app/core/internationalization/index.tsx b/public/app/core/internationalization/index.tsx index 2d31fc1d708..e3dbfb28270 100644 --- a/public/app/core/internationalization/index.tsx +++ b/public/app/core/internationalization/index.tsx @@ -68,7 +68,14 @@ export const Trans = (props: TransProps): ReactElement => { return ; }; -// Wrap t() to provide default namespaces and enforce a consistent API +/** + * This is a simple wrapper over i18n.t() to provide default namespaces and enforce a consistent API. + * Note: Don't use this in the top level module scope. This wrapper needs initialization, which is done during Grafana + * startup, and it will throw if used before. + * @param id ID of the translation string + * @param defaultMessage Default message to use if the translation is missing + * @param values Values to be interpolated into the string + */ export const t = (id: string, defaultMessage: string, values?: Record) => { if (!tFunc) { if (process.env.NODE_ENV !== 'test') {