Skip to content

Commit 5e5cce0

Browse files
Translate “Add React to an Existing Project" (#665)
* feat: “add react to an existing project” spanish translation --------- Co-authored-by: Mateo Guzmán <[email protected]> Co-authored-by: Mateo Guzmán <[email protected]>
1 parent 86e7edf commit 5e5cce0

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
---
2-
title: Add React to an Existing Project
2+
title: Agregar React a un proyecto existente
33
---
44

55
<Intro>
66

7-
If you want to add some interactivity to your existing project, you don't have to rewrite it in React. Add React to your existing stack, and render interactive React components anywhere.
7+
Si quieres añadir algo de interactividad a tu proyecto existente, no lo tienes que escribir de nuevo en React. Agrega React a tu stack *actual* y renderiza componentes React en cualquier lugar.
88

99
</Intro>
1010

1111
<Note>
1212

13-
**You need to install [Node.js](https://nodejs.org/en/) for local development.** Although you can [try React](/learn/installation#try-react) online or with a simple HTML page, realistically most JavaScript tooling you'll want to use for development requires Node.js.
13+
**Debes instalar [Node.js](https://nodejs.org/es/) para el desarrollo local.** Aunque puedes [probar React](/learn/installation#try-react) en línea o con una simple página HTML, siendo realista la mayoría de herramientas de JavaScript que querrás utilizar para desarrollar requieren Node.js.
1414

1515
</Note>
1616

17-
## Using React for an entire subroute of your existing website {/*using-react-for-an-entire-subroute-of-your-existing-website*/}
17+
## Utilizar React para una subruta completa de tu página web existente {/*using-react-for-an-entire-subroute-of-your-existing-website*/}
1818

19-
Let's say you have an existing web app at `example.com` built with another server technology (like Rails), and you want to implement all routes starting with `example.com/some-app/` fully with React.
19+
Digamos que tienes una aplicación web existente en `example.com` construida con otra tecnología de servidor (como Rails), y quieres implementar todas las rutas que comienzan por `example.com/some-app/` completamente con React.
2020

21-
Here's how we recommend to set it up:
21+
Así es como recomendamos configurarlo:
2222

23-
1. **Build the React part of your app** using one of the [React-based frameworks](/learn/start-a-new-react-project).
24-
2. **Specify `/some-app` as the *base path*** in your framework's configuration (here's how: [Next.js](https://nextjs.org/docs/api-reference/next.config.js/basepath), [Gatsby](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)).
25-
3. **Configure your server or a proxy** so that all requests under `/some-app/` are handled by your React app.
23+
1. **Construye la parte React de tu app** utilizando uno de los [*frameworks* basados en React](/learn/start-a-new-react-project).
24+
2. **Especifica `/some-app` como la *ruta base*** en la configuración de tu framework (aquí tienes como: [Next.js](https://nextjs.org/docs/api-reference/next.config.js/basepath), [Gatsby](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)).
25+
3. **Configura tu servidor o un proxy** para que todas las peticiones bajo `/some-app/` sean manejadas por tu aplicación React.
2626

27-
This ensures the React part of your app can [benefit from the best practices](/learn/start-a-new-react-project#can-i-use-react-without-a-framework) baked into those frameworks.
27+
Esto garantiza que la parte React de tu aplicación se pueda [beneficiar de las mejoras practicas](/learn/start-a-new-react-project#can-i-use-react-without-a-framework) integradas en aquellos frameworks.
2828

29-
Many React-based frameworks are full-stack and let your React app take advantage of the server. However, you can use the same approach even if you can't or don't want to run JavaScript on the server. In that case, serve the HTML/CSS/JS export ([`next export` output](https://nextjs.org/docs/advanced-features/static-html-export) for Next.js, default for Gatsby) at `/some-app/` instead.
29+
Muchos frameworks basados en React son full-stack y permiten que tu aplicación React aproveche del servidor. Sin embargo, puedes utilizar el mismo enfoque incluso si no puedes o no quieres ejecutar JavaScript en el servidor. En ese caso, sirve el HTML/CSS/JS exportado ([`next export` output](https://nextjs.org/docs/advanced-features/static-html-export) para Next.js, por defecto con Gatsby) en `/some-app/` en su lugar.
3030

31-
## Using React for a part of your existing page {/*using-react-for-a-part-of-your-existing-page*/}
31+
## Utilizar React para una parte de tu página existente {/*using-react-for-a-part-of-your-existing-page*/}
3232

33-
Let's say you have an existing page built with another technology (either a server one like Rails, or a client one like Backbone), and you want to render interactive React components somewhere on that page. That's a common way to integrate React--in fact, it's how most React usage looked at Meta for many years!
33+
Digamos que tienes una página existente creada con otra tecnología (una de servidor como Rails, o de cliente como Backbone), y quieres renderizar componentes React interactivos en algún lugar de la página. Esta es una forma común de integrar React y, de hecho, ¡así es como se veía la mayoría del uso de React en Meta durante muchos años!
3434

35-
You can do this in two steps:
35+
Puedes hacer esto en dos pasos:
3636

37-
1. **Set up a JavaScript environment** that lets you use the [JSX syntax](/learn/writing-markup-with-jsx), split your code into modules with the [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) / [`export`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) syntax, and use packages (for example, React) from the [npm](https://www.npmjs.com/) package registry.
38-
2. **Render your React components** where you want to see them on the page.
37+
1. **Configurar un entorno de JavaScript** que te permite utilizar la [sintaxis JSX](/learn/writing-markup-with-jsx), dividir tu código en módulos con la sintaxis [`import`](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Statements/import) / [`export`](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Statements/export), y utilizar paquetes (por ejemplo React) del gestor de paquetes [npm](https://www.npmjs.com/).
38+
2. **Renderizar tus componentes React** donde las deseas ver en la página.
3939

40-
The exact approach depends on your existing page setup, so let's walk through some details.
40+
El método exacto dependerá de la configuración de tu página existente, así que repasemos algunos detalles.
4141

42-
### Step 1: Set up a modular JavaScript environment {/*step-1-set-up-a-modular-javascript-environment*/}
42+
### Paso 1: Configurar un entorno de JavaScript modular {/*step-1-set-up-a-modular-javascript-environment*/}
4343

44-
A modular JavaScript environment lets you write your React components in individual files, as opposed to writing all of your code in a single file. It also lets you use all the wonderful packages published by other developers on the [npm](https://www.npmjs.com/) registry--including React itself! How you do this depends on your existing setup:
44+
Un entorno de JavaScript modular te permite escribir tus componentes React en archivos individuales, en lugar de escribir todo tu código en un solo archivo. También te permite utilizar todos los maravillosos paquetes publicados por otros desarrolladores en el registro [npm](https://www.npmjs.com/) (¡Incluyendo el propio React!) La manera de hacerlo depende de tu configuración existente:
4545

46-
* **If your app is already split into files that use `import` statements,** try to use the setup you already have. Check whether writing `<div />` in your JS code causes a syntax error. If it causes a syntax error, you might need to [transform your JavaScript code with Babel](https://babeljs.io/setup), and enable the [Babel React preset](https://babeljs.io/docs/babel-preset-react) to use JSX.
46+
* **Si tu aplicación ya está dividida en archivos que utilizan la sintaxis `import`,** prueba a utilizar tu configuración existente. Comprueba si escribir `<div />` en tu código JS causa un error de sintaxis. Si causa un error de sintaxis, es posible que necesites [transformar tu código JavaScript con Babel](https://babeljs.io/setup), y habilitar el [_preset_ de Babel React](https://babeljs.io/docs/babel-preset-react) para utilizar JSX.
4747

48-
* **If your app doesn't have an existing setup for compiling JavaScript modules,** set it up with [Vite](https://vitejs.dev/). The Vite community maintains [many integrations with backend frameworks](https://github.com/vitejs/awesome-vite#integrations-with-backends), including Rails, Django, and Laravel. If your backend framework is not listed, [follow this guide](https://vitejs.dev/guide/backend-integration.html) to manually integrate Vite builds with your backend.
48+
* **Si tu aplicación no tiene una configuración existente para compilar módulos JavaScript,** configurarlo con [Vite](https://es.vitejs.dev/). La comunidad de Vite mantienen [varias integraciones con *frameworks* de backend](https://github.com/vitejs/awesome-vite#integrations-with-backends), incluyendo Rails, Django y Laravel. Si tu *framework* de backend no aparece en la lista, [sigue esta guía](https://es.vitejs.dev/guide/backend-integration.html) para integrar la compilación con Vite con tu backend de forma manual.
4949

50-
To check whether your setup works, run this command in your project folder:
50+
Para comprobar que tu configuración funciona, lanza el siguiente comando en el directorio de tu proyecto:
5151

5252
<TerminalBlock>
5353
npm install react react-dom
5454
</TerminalBlock>
5555

56-
Then add these lines of code at the top of your main JavaScript file (it might be called `index.js` or `main.js`):
56+
Después agrega las siguientes líneas de código al principio de tu archivo JavaScript principal (quizás se llama `index.js` o `main.js`):
5757

5858
<Sandpack>
5959

@@ -62,60 +62,60 @@ Then add these lines of code at the top of your main JavaScript file (it might b
6262
<html>
6363
<head><title>My app</title></head>
6464
<body>
65-
<!-- Your existing page content (in this example, it gets replaced) -->
65+
<!-- El contenido de tu página actual (en este ejemplo, es reemplazado) -->
6666
</body>
6767
</html>
6868
```
6969

7070
```js index.js active
7171
import { createRoot } from 'react-dom/client';
7272

73-
// Clear the existing HTML content
73+
// Borrar el contenido HTML existente
7474
document.body.innerHTML = '<div id="app"></div>';
7575

76-
// Render your React component instead
76+
// Renderizar tu componente React en su lugar
7777
const root = createRoot(document.getElementById('app'));
78-
root.render(<h1>Hello, world</h1>);
78+
root.render(<h1>¡Hola, mundo!</h1>);
7979
```
8080

8181
</Sandpack>
8282

83-
If the entire content of your page was replaced by a "Hello, world!", everything worked! Keep reading.
83+
Si el contenido completo de tu página fue reemplazado por un "¡Hola, mundo!", ¡todo ha funcionado! Sigue leyendo.
8484

8585
<Note>
8686

87-
Integrating a modular JavaScript environment into an existing project for the first time can feel intimidating, but it's worth it! If you get stuck, try our [community resources](/community) or the [Vite Chat](https://chat.vitejs.dev/).
87+
Integrar un entorno de JavaScript modular en un proyecto existente por primera vez puede ser intimidante, ¡pero vale la pena! Si te quedas atascado, prueba nuestros [recursos de la comunidad](/community) o el [Vite Chat](https://chat.vitejs.dev/).
8888

8989
</Note>
9090

91-
### Step 2: Render React components anywhere on the page {/*step-2-render-react-components-anywhere-on-the-page*/}
91+
### Paso 2: Renderizar componentes React en cualquier lugar de la página {/*step-2-render-react-components-anywhere-on-the-page*/}
9292

93-
In the previous step, you put this code at the top of your main file:
93+
En el paso anterior, pusiste el siguiente código al principio de tu archivo principal:
9494

9595
```js
9696
import { createRoot } from 'react-dom/client';
9797

98-
// Clear the existing HTML content
98+
// Borrar el contenido HTML existente
9999
document.body.innerHTML = '<div id="app"></div>';
100100

101-
// Render your React component instead
101+
// Renderizar tu componente React en su lugar
102102
const root = createRoot(document.getElementById('app'));
103-
root.render(<h1>Hello, world</h1>);
103+
root.render(<h1>¡Hola, mundo!</h1>);
104104
```
105105

106-
Of course, you don't actually want to clear the existing HTML content!
106+
Por supuesto, ¡en realidad no deseas borrar el contenido HTML existente!
107107

108-
Delete this code.
108+
Elimina este código.
109109

110-
Instead, you probably want to render your React components in specific places in your HTML. Open your HTML page (or the server templates that generate it) and add a unique [`id`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id) attribute to any tag, for example:
110+
En cambio, probablemente quieres renderizar tus componentes React en zonas especificas de tu HTML. Abre tu página HTML (o las plantillas de servidor que lo generan) y agrega un [`id`](https://developer.mozilla.org/es/docs/Web/HTML/Global_attributes/id) único a cualquier etiqueta, por ejemplo:
111111

112112
```html
113-
<!-- ... somewhere in your html ... -->
113+
<!-- ... en algún lugar de tu html ... -->
114114
<nav id="navigation"></nav>
115-
<!-- ... more html ... -->
115+
<!-- ... más html ... -->
116116
```
117117

118-
This lets you find that HTML element with [`document.getElementById`](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById) and pass it to [`createRoot`](/reference/react-dom/client/createRoot) so that you can render your own React component inside:
118+
Esto te permite encontrar aquel elemento HTML con [`document.getElementById`](https://developer.mozilla.org/es/docs/Web/API/Document/getElementById) y pasarlo a [`createRoot`](/reference/react-dom/client/createRoot) para que puedas renderizar tu propio componente React dentro:
119119

120120
<Sandpack>
121121

@@ -124,9 +124,9 @@ This lets you find that HTML element with [`document.getElementById`](https://de
124124
<html>
125125
<head><title>My app</title></head>
126126
<body>
127-
<p>This paragraph is a part of HTML.</p>
127+
<p>Este párrafo es parte del HTML.</p>
128128
<nav id="navigation"></nav>
129-
<p>This paragraph is also a part of HTML.</p>
129+
<p>Este párrafo también es parte del HTML.</p>
130130
</body>
131131
</html>
132132
```
@@ -135,8 +135,8 @@ This lets you find that HTML element with [`document.getElementById`](https://de
135135
import { createRoot } from 'react-dom/client';
136136

137137
function NavigationBar() {
138-
// TODO: Actually implement a navigation bar
139-
return <h1>Hello from React!</h1>;
138+
// TODO: Realmente implementar una barra de navegación
139+
return <h1>Hola desde React!</h1>;
140140
}
141141

142142
const domNode = document.getElementById('navigation');
@@ -146,10 +146,10 @@ root.render(<NavigationBar />);
146146

147147
</Sandpack>
148148

149-
Notice how the original HTML content from `index.html` is preserved, but your own `NavigationBar` React component now appears inside the `<nav id="navigation">` from your HTML. Read the [`createRoot` usage documentation](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) to learn more about rendering React components inside an existing HTML page.
149+
Observa como el contenido HTML original de `index.html` se mantiene, pero ahora tu propio componente React `NavigationBar` aparece dentro del `<nav id="navigation">` de tu HTML. Lee la [documentación sobre el uso de `createRoot`](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) para aprender más sobre renderizar componentes React dentro de una página HTML existente.
150150

151-
When you adopt React in an existing project, it's common to start with small interactive components (like buttons), and then gradually keep "moving upwards" until eventually your entire page is built with React. If you ever reach that point, we recommend migrating to [a React framework](/learn/start-a-new-react-project) right after to get the most out of React.
151+
Cuando adoptas React en un proyecto existente, es común empezar con pequeños componentes interactivos (como botones), y luego seguir "moviendo hacia arriba" gradualmente hasta que finalmente toda tu página está construida con React. Si logras llegar a este punto, recomendamos migrar a [un framework de React](/learn/start-a-new-react-project) enseguida para sacar el máximo provecho de React.
152152

153-
## Using React Native in an existing native mobile app {/*using-react-native-in-an-existing-native-mobile-app*/}
153+
## Utilizar React Native en una aplicación móvil nativa existente {/*using-react-native-in-an-existing-native-mobile-app*/}
154154

155-
[React Native](https://reactnative.dev/) can also be integrated into existing native apps incrementally. If you have an existing native app for Android (Java or Kotlin) or iOS (Objective-C or Swift), [follow this guide](https://reactnative.dev/docs/integration-with-existing-apps) to add a React Native screen to it.
155+
[React Native](https://reactnative.dev/) también puede ser integrada en aplicaciones nativas existentes de forma incremental. Si tienes una aplicación nativa existente para Android (Java o Kotlin) o iOS (Objective-C o Swift), [sigue esta guía](https://reactnative.dev/docs/integration-with-existing-apps) para añadirle una pantalla de React Native.

src/sidebarLearn.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"path": "/learn/start-a-new-react-project"
3030
},
3131
{
32-
"title": "Add React to an Existing Project",
32+
"title": "Agregar React a un proyecto existente",
3333
"path": "/learn/add-react-to-an-existing-project"
3434
},
3535
{

0 commit comments

Comments
 (0)