Skip to content

Commit

Permalink
Merge pull request #78 from ricardoerl/translate/context
Browse files Browse the repository at this point in the history
Translate Context
  • Loading branch information
Darking360 committed Feb 21, 2019
2 parents fcc9e73 + a93f0ab commit 6aae81b
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 89 deletions.
133 changes: 67 additions & 66 deletions content/docs/context.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/context/motivation-problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class App extends React.Component {

function Toolbar(props) {
// highlight-range{1-4,7}
// The Toolbar component must take an extra "theme" prop
// and pass it to the ThemedButton. This can become painful
// if every single button in the app needs to know the theme
// because it would have to be passed through all components.
// El componente Toolbar debe tener un prop adicional "theme"
// y pasarlo a ThemedButton. Esto puede llegar a ser trabajoso
// si cada botón en la aplicación necesita saber el tema,
// porque tendría que pasar a través de todos los componentes.
return (
<div>
<ThemedButton theme={props.theme} />
Expand Down
22 changes: 11 additions & 11 deletions examples/context/motivation-solution.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// highlight-range{1-4}
// Context lets us pass a value deep into the component tree
// without explicitly threading it through every component.
// Create a context for the current theme (with "light" as the default).
// Context nos permite pasar un valor a lo profundo del árbol de componentes
// sin pasarlo explícitamente a través de cada componente.
// Crear un Context para el tema actual (con "light" como valor predeterminado).
const ThemeContext = React.createContext('light');

class App extends React.Component {
render() {
// highlight-range{1-3,5}
// Use a Provider to pass the current theme to the tree below.
// Any component can read it, no matter how deep it is.
// In this example, we're passing "dark" as the current value.
// Usa un Provider para pasar el tema actual al árbol de abajo.
// Cualquier componente puede leerlo, sin importar qué tan profundo se encuentre.
// En este ejemplo, estamos pasando "dark" como valor actual.
return (
<ThemeContext.Provider value="dark">
<Toolbar />
Expand All @@ -19,8 +19,8 @@ class App extends React.Component {
}

// highlight-range{1,2}
// A component in the middle doesn't have to
// pass the theme down explicitly anymore.
// Un componente en el medio no tiene que
// pasar el tema hacia abajo explícitamente.
function Toolbar(props) {
return (
<div>
Expand All @@ -31,9 +31,9 @@ function Toolbar(props) {

class ThemedButton extends React.Component {
// highlight-range{1-3,6}
// Assign a contextType to read the current theme context.
// React will find the closest theme Provider above and use its value.
// In this example, the current theme is "dark".
// Asigna un contextType para leer el contexto del tema actual.
// React encontrará el Provider superior más cercano y usará su valor.
// En este ejemplo, el tema actual es "dark".
static contextType = ThemeContext;
render() {
return <Button theme={this.context} />;
Expand Down
6 changes: 3 additions & 3 deletions examples/context/multiple-contexts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Theme context, default to light theme
const ThemeContext = React.createContext('light');

// Signed-in user context
// Contexto de usuario registrado
const UserContext = React.createContext({
name: 'Guest',
});
Expand All @@ -10,7 +10,7 @@ class App extends React.Component {
render() {
const {signedInUser, theme} = this.props;

// App component that provides initial context values
// Componente App que proporciona valores de contexto iniciales
// highlight-range{2-3,5-6}
return (
<ThemeContext.Provider value={theme}>
Expand All @@ -31,7 +31,7 @@ function Layout() {
);
}

// A component may consume multiple contexts
// Un componente puede consumir múltiples contextos.
function Content() {
// highlight-range{2-10}
return (
Expand Down
8 changes: 4 additions & 4 deletions examples/context/theme-detailed-app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ThemeContext, themes} from './theme-context';
import ThemedButton from './themed-button';

// An intermediate component that uses the ThemedButton
// Un componente intermedio que utiliza ThemedButton.
function Toolbar(props) {
return (
<ThemedButton onClick={props.changeTheme}>
Expand Down Expand Up @@ -29,9 +29,9 @@ class App extends React.Component {

render() {
//highlight-range{1-3}
// The ThemedButton button inside the ThemeProvider
// uses the theme from state while the one outside uses
// the default dark theme
// El botón ThemedButton dentro de ThemeProvider
// usa el tema del estado mientras que el exterior usa
// el tema oscuro predeterminado
//highlight-range{3-5,7}
return (
<Page>
Expand Down
2 changes: 1 addition & 1 deletion examples/context/theme-detailed-theme-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export const themes = {

// highlight-range{1-3}
export const ThemeContext = React.createContext(
themes.dark // default value
themes.dark // valor por defecto
);

0 comments on commit 6aae81b

Please sign in to comment.