KoreanThinker / react-native-translator

🌐 Unlimited free google translate component & hook (Unofficial)
https://www.npmjs.com/package/react-native-translator
MIT License
81 stars 9 forks source link

Translator stopping the text at new lines and ";" #7

Closed decamps-enmanuel closed 1 year ago

decamps-enmanuel commented 2 years ago

Hello, great lib. I'm stuck in an specific point. I'm trying to translate some text and the hook only returns the text until a special character is found.

Example: Input string: La excursión en kayak es nuestra actividad más popular; una aventura relajante donde puedes recorrer 5km por un río de aguas color azul turquesa, hermosos bancos de arena, árboles centenarios, y un paisaje autentico, agradable, y romántica para las parejas, divertida para amigos y familiares.

Output : The kayak excursion is our most popular activity;

As you can see it stops right at the first ";".

Removing the special characters allows the hook to translate it all but it's dynamic text so I can't really start replacing special characters.

Any ideas?

KoreanThinker commented 2 years ago

Could you please show your code?

decamps-enmanuel commented 2 years ago

Could you please show your code?

const contentText = "La excursión en kayak es nuestra actividad más popular; una aventura relajante donde puedes recorrer 5km por un río de aguas color azul turquesa, hermosos bancos de arena, árboles centenarios, y un paisaje autentico, agradable, y romántica para las parejas, divertida para amigos y familiares.

Esta excusión es guiada por jóvenes de la comunidad, capacitados y con experiencia para realizar deportes acuáticos.

Durante el recorrido puedes disfrutar de un refrigerio a base de productos locales, paradas para disfrutar dentro y fuera del agua, almuerzo típico en casa de familia, transporte interno, y los equipos necesarios para la actividad."

const onTranslate = async () => {
      console.log("contentText", contentText);
      const result = await translate("es", "en", `${contentText}`, {
        type: "google",
        timeout: 10000,
      });
      console.log("translation result is", result);
  };

The last console log only returns this: "The kayak excursion is our most popular activity;"

KoreanThinker commented 2 years ago

Is it not work?

const onTranslate = async () => {

    const result = await translate("es", "en", `${contentText.replace(/;/gi, "");}`, {
      type: "google",
      timeout: 10000,
    });
    console.log("translation result is", result);
};
decamps-enmanuel commented 2 years ago

If I replace that the content will lose the ";". The semi colon is not the only thing that's stopping the translator to stop.

KoreanThinker commented 2 years ago

I resolved issue by use encodeURI. Following are the command you can test new code.

  1. remove package.lock.json & node_modules
  2. remove react-native-translator: "1.1.3" from package.json
  3. run npm install
  4. run npm i --save https://github.com/KoreanThinker/react-native-translator.git#url-encoding
KoreanThinker commented 2 years ago

@decamps-enmanuel Do you resolve?

decamps-enmanuel commented 2 years ago

@decamps-enmanuel Are you resolved?

It now translates correctly but the output returns without spaces after periods.

Example:

Input > This is a test. Hello! How are you? Output > Esto es un ejemplo.Hola!Como estas?

rohankm commented 2 years ago

im also facing this issue.. any updates?

KoreanThinker commented 2 years ago

im also facing this issue.. any updates?

I'm so busy... I think this is easy to resolve. Can you pull some request?

By the refer https://github.com/KoreanThinker/react-native-translator/pull/8