Browse Source

feat(replays): Create a helper `isStaticString` so replays can hook into locale data (#49513)

Punching a hole here for an experiment:
https://github.com/getsentry/getsentry/pull/10615
Ryan Albrecht 1 year ago
parent
commit
19d2643318
1 changed files with 11 additions and 1 deletions
  1. 11 1
      static/app/locale.tsx

+ 11 - 1
static/app/locale.tsx

@@ -42,6 +42,7 @@ export function toggleLocaleDebug() {
  * Global Jed locale object loaded with translations via setLocale
  */
 let i18n: Jed | null = null;
+const staticTranslations = new Set<string>();
 
 /**
  * Set the current application locale.
@@ -50,7 +51,7 @@ let i18n: Jed | null = null;
  * translation functions, as this mutates a singleton translation object used
  * to lookup translations at runtime.
  */
-export function setLocale(translations: any) {
+export function setLocale(translations: any): Jed {
   i18n = new Jed({
     domain: 'sentry',
     missing_key_callback: () => {},
@@ -80,6 +81,14 @@ function getClient(): Jed | null {
   return i18n;
 }
 
+export function isStaticString(formatString: string): boolean {
+  if (formatString.trim() === '') {
+    return false;
+  }
+
+  return staticTranslations.has(formatString);
+}
+
 /**
  * printf style string formatting which render as react nodes.
  */
@@ -324,6 +333,7 @@ export function gettext(string: string, ...args: FormatArg[]): string {
   const val: string = getClient().gettext(string);
 
   if (args.length === 0) {
+    staticTranslations.add(val);
     return mark(val);
   }