Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
Cómo usar la traducción __() con hipervínculos

Al crear un bloque en WordPress, tendré que agregar una traducción con un enlace dentro. Lo estoy haciendo de esta manera en JS, pero no proporciona los resultados esperados:

 import { render } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; export default function Final() { let d = <a href="https://example.com">bothered me.</a>; return ( <p> { __( 'The cold never {d} anyway.', 'text-domain' ) } </p> ) } document.addEventListener( "DOMContentLoaded", function(event) { const appRoot = document.getElementById( 'root' ); if ( appRoot ) { render( <Final/>, appRoot ) } });

En PHP, podría hacerlo fácilmente con sprintf y usando un marcador de posición como %1s.

 echo sprintf( __( 'The cold never %1s anyway', 'text-domain' ), '<a href="https://example.com">bothered me.</a>' );

¿Cómo hago el equivalente de sprintf al crear un bloque en reaccionar?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Está intentando insertar una etiqueta html dentro de una oración traducida usando React. Deberá mantener un marcador de posición (algo así como {0} ) y luego deberá reemplazarlo con el componente real.

Cuando con PHP simplemente está reemplazando texto con otro texto (que es su HTML), al reaccionar está usando componentes, por lo que no puede simplemente reemplazarlos.

 export default function Final() { const [before, after] = __('The cold never {0} anyway.', 'text-domain').split('{0}'); return (<p> { before } <a href="https://example.com">bothered me.</a> { after } </p>); }

Nota al margen

Este 'The cold never {d} anyway.' es una cadena simple, tal vez pretendías `The cold never ${d} anyway.` (para plantillas de cadena).

over 4 years ago · Santiago Trujillo Report

0

Intente usar cadenas de plantilla (ES6):

 export default function Final() { let d = <a href="https://example.com">bothered me.</a>; return ( <p> { __( `The cold never ${d} anyway.`, 'text-domain' ) } </p> ) }

Pregunta similar

over 4 years ago · Santiago Trujillo Report

0

Otra forma es usar sprintf integrado con @wordpress/i18n

 import { render } from '@wordpress/element'; import { sprintf, __ } from '@wordpress/i18n'; export default function Final() { let d = '<a href="https://example.com">bothered me.</a>'; let txt = sprintf(__('The cold never %1s anyway.', 'text-domain'), d); return ( <p dangerouslySetInnerHTML={{__html: txt }}></p> ) }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!