I18n: Add doc comment for t() (#99024)

* Add comment doc

* Reorder information
This commit is contained in:
Andrej Ocenas 2025-01-15 17:31:06 +01:00 committed by GitHub
parent d00592ffa0
commit 5d45af1110
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -68,7 +68,14 @@ export const Trans = (props: TransProps): ReactElement => {
return <I18NextTrans shouldUnescape ns={NAMESPACES} {...props} />;
};
// 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<string, unknown>) => {
if (!tFunc) {
if (process.env.NODE_ENV !== 'test') {