dhre-ui-kit 0.0.374 → 0.0.375

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import React, { createContext, useContext, useState, useEffect, useRef, memo, useCallback } from 'react';
2
2
  import { useSelector } from 'react-redux';
3
3
  import { Dimensions, StyleSheet, Text, Pressable, View, Platform, KeyboardAvoidingView, TextInput, ScrollView, Animated, FlatList, TouchableOpacity, Modal as Modal$1, Alert, Linking, PanResponder } from 'react-native';
4
+ import translate from 'google-translate-api-x';
4
5
  import Modal from 'react-native-modal';
5
6
  import Clipboard from '@react-native-clipboard/clipboard';
6
7
  import LottieView from 'lottie-react-native';
@@ -338,14 +339,55 @@ const FONT_STYLES = {
338
339
  [FontStyle.L3_REGULAR]: createFontStyle("MeraasAktiv-Regular", 10, 14)
339
340
  };
340
341
 
342
+ const translateToArabic = async (text) => {
343
+ if (!text || text.trim() === "") {
344
+ return text;
345
+ }
346
+ try {
347
+ const result = await translate(text, { to: "ar" });
348
+ return result.text || text;
349
+ } catch (error) {
350
+ console.error("Translation error:", error);
351
+ return text;
352
+ }
353
+ };
354
+ const useArabicTranslation = (text, shouldTranslate = false) => {
355
+ const [translatedText, setTranslatedText] = useState(text || "");
356
+ const [isTranslating, setIsTranslating] = useState(false);
357
+ const [error, setError] = useState(null);
358
+ useEffect(() => {
359
+ if (!shouldTranslate || !text) {
360
+ setTranslatedText(text || "");
361
+ return;
362
+ }
363
+ const translate2 = async () => {
364
+ setIsTranslating(true);
365
+ setError(null);
366
+ try {
367
+ const translated = await translateToArabic(text);
368
+ setTranslatedText(translated);
369
+ } catch (err) {
370
+ setError(err instanceof Error ? err.message : "Translation failed");
371
+ setTranslatedText(text);
372
+ } finally {
373
+ setIsTranslating(false);
374
+ }
375
+ };
376
+ translate2();
377
+ }, [text, shouldTranslate]);
378
+ return { translatedText, isTranslating, error };
379
+ };
380
+
341
381
  const CustomTypography = ({
342
382
  variant,
343
383
  style,
344
384
  text,
345
385
  testID = "CUSTOM_TYPOGRAPHY",
386
+ translateToArabic = true,
346
387
  ...props
347
388
  }) => {
348
389
  const textStyle = FONT_STYLES[variant];
390
+ const { translatedText } = useArabicTranslation(text, translateToArabic);
349
391
  return /* @__PURE__ */ React.createElement(
350
392
  Text,
351
393
  {
@@ -353,7 +395,7 @@ const CustomTypography = ({
353
395
  style: [textStyle, styles$B.container, style],
354
396
  ...props
355
397
  },
356
- text
398
+ translatedText
357
399
  );
358
400
  };
359
401
  const styles$B = StyleSheet.create({