diff --git a/.eslintrc.js b/.eslintrc.js index 24b625b..b1c8ae2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -51,6 +51,8 @@ module.exports = { unnamedComponents: 'arrow-function', }, ], + 'react/jsx-props-no-spreading': 'off', + 'react/jsx-no-useless-fragment': 'off', 'no-unused-vars': ['error', { argsIgnorePattern: '^_' }], }, globals: { diff --git a/README.md b/README.md index 09db127..f07a5a2 100644 --- a/README.md +++ b/README.md @@ -23,21 +23,24 @@ or with yarn ## Usage > DISCLAIMER! -To be 100% legal please use the official [Google Translate API](https://cloud.google.com/translate). This project is mainly for pet projects and prototyping 😉. Always only use the most **recent version** of this package. This server is also very limited, for use in **production** see [PRODUCTION USAGE.](#production-usage) +To be 100% legal please use the official [Google Translate API](https://cloud.google.com/translate). This project is mainly for pet projects and prototyping 😉. The server is very limited, for use in **production** see [PRODUCTION USAGE.](#production-usage) Always only use the most **recent version** of this package. ### To translate whole component: ```jsx import Translator from '@miracleufo/react-g-translator'; -return ( - -
- ... -
-
-); +const Component = () => { + ... + return ( + +
+ ... +
+
+ ); +} ``` -**NB:** Each non-void React element is translated like a paragraph, for best translation please avoid
and use

instead; and end sentences with fullstop. **`` `from` and `to` props will always override [``](#to-translate-specific-text-inline) `from` and `to` props.** +**NB:** Each non-void React element is translated like a paragraph, for best translation please avoid
and use

instead, and always end sentences with fullstop. ### To translate specific text inline: ```jsx @@ -46,8 +49,12 @@ import { Translate } from '@miracleufo/react-g-translator'; return (

... -

Hello.

-

Hello in French.

+ Hello in French. + {/* Can also be used within elements */} +

+ Welcome in German. + Happy to meet you. +

...
); diff --git a/package.json b/package.json index 9ebe7e2..c61b807 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@miracleufo/react-g-translator", - "version": "1.0.0", + "version": "9.0.7", "description": "A modern, free, lightweight npm package for translating react apps (component wrapper.) No API keys or language list files are required.", "author": "Miracle Ufodiama", "license": "MIT", diff --git a/src/components/Translator.tsx b/src/components/Translator.tsx index 5dbf266..06db04b 100644 --- a/src/components/Translator.tsx +++ b/src/components/Translator.tsx @@ -1,4 +1,3 @@ -/* eslint-disable react/jsx-no-useless-fragment */ import React, { JSX, ReactNode, @@ -50,6 +49,11 @@ const recursivelyTranslate = ( } if (isValidElement(node)) { + // skip translation if functional component + // for scoping of `to` & `from` props in nested components + // (also applies to nested and wrappers) + if (typeof node.type === 'function') return node; + if (node.type === 'textarea' || node.type === 'input' || node.type === 'img') { return ( | Element | JSX.Element; + children: ReactNode | ReactElement | Element | JSX.Element; from?: language; to?: language; shouldFallback?: boolean; diff --git a/src/components/helpers/Translation.tsx b/src/components/helpers/Translation.tsx index b195699..c438403 100644 --- a/src/components/helpers/Translation.tsx +++ b/src/components/helpers/Translation.tsx @@ -1,4 +1,3 @@ -/* eslint-disable react/jsx-no-useless-fragment */ import React from 'react'; import determineRenderedText from '../../utils/determineRenderedText'; import useTranslation from '../../queries/useTranslation'; diff --git a/src/components/helpers/TranslationInputImage.tsx b/src/components/helpers/TranslationInputImage.tsx index 799d01a..4861cf8 100644 --- a/src/components/helpers/TranslationInputImage.tsx +++ b/src/components/helpers/TranslationInputImage.tsx @@ -1,4 +1,3 @@ -/* eslint-disable react/jsx-no-useless-fragment */ import React, { ReactNode, ReactElement,