Jelajahi Sumber

Create traslation utils

Shun Miyazawa 1 tahun lalu
induk
melakukan
ce7f378f70
1 mengubah file dengan 15 tambahan dan 0 penghapusan
  1. 15 0
      apps/app/src/client/util/t-with-opt.ts

+ 15 - 0
apps/app/src/client/util/t-with-opt.ts

@@ -0,0 +1,15 @@
+import { useCallback } from 'react';
+
+import { useTranslation } from 'next-i18next';
+
+export const useTWithOpt = (): (key: string, opt?: any) => string => {
+
+  const { t } = useTranslation();
+
+  return useCallback((key, opt) => {
+    if (typeof opt === 'object') {
+      return t(key, opt).toString();
+    }
+    return t(key);
+  }, [t]);
+};