aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/reference/global_objects/intl/relativetimeformat
diff options
context:
space:
mode:
authorFlorian Merz <me@fiji-flo.de>2021-02-11 14:46:50 +0100
committerFlorian Merz <me@fiji-flo.de>2021-02-11 14:46:50 +0100
commita55b575e8089ee6cab7c5c262a7e6db55d0e34d6 (patch)
tree5032e6779a402a863654c9d65965073f09ea4182 /files/es/web/javascript/reference/global_objects/intl/relativetimeformat
parent8260a606c143e6b55a467edf017a56bdcd6cba7e (diff)
downloadtranslated-content-a55b575e8089ee6cab7c5c262a7e6db55d0e34d6.tar.gz
translated-content-a55b575e8089ee6cab7c5c262a7e6db55d0e34d6.tar.bz2
translated-content-a55b575e8089ee6cab7c5c262a7e6db55d0e34d6.zip
unslug es: move
Diffstat (limited to 'files/es/web/javascript/reference/global_objects/intl/relativetimeformat')
-rw-r--r--files/es/web/javascript/reference/global_objects/intl/relativetimeformat/index.html106
1 files changed, 106 insertions, 0 deletions
diff --git a/files/es/web/javascript/reference/global_objects/intl/relativetimeformat/index.html b/files/es/web/javascript/reference/global_objects/intl/relativetimeformat/index.html
new file mode 100644
index 0000000000..fc15049fa6
--- /dev/null
+++ b/files/es/web/javascript/reference/global_objects/intl/relativetimeformat/index.html
@@ -0,0 +1,106 @@
+---
+title: Intl.RelativeTimeFormat
+slug: Web/JavaScript/Referencia/Objetos_globales/Intl/RelativeTimeFormat
+tags:
+ - RelatimeTimeFormat
+translation_of: Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat
+---
+<div>{{JSRef}}</div>
+
+<p>El objeto <strong><code>Intl.RelativeTimeFormat</code></strong> te proporciona una manera de formatear tiempos relativos con traducciones.</p>
+
+<div>{{EmbedInteractiveExample("pages/js/intl-relativetimeformat.html")}}</div>
+
+<p class="hidden">El código de este ejemplo interactivo está disponible en un repositorio GitHub. Si quieres contribuir a los ejemplos interactivos del proyecto, por favor, clona <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> y manda una Pull Request.</p>
+
+<h2 id="Constructor">Constructor</h2>
+
+<dl>
+ <dt>{{jsxref("RelativeTimeFormat.RelativeTimeFormat()", "Intl.RelativeTimeFormat.RelativeTimeFormat()")}}</dt>
+ <dd>Crea una nueva instancia de <code>Intl.RelativeTimeFormat</code>.</dd>
+</dl>
+
+<h2 id="Métodos_estáticos">Métodos estáticos</h2>
+
+<dl>
+ <dt>{{jsxref("RelativeTimeFormat.supportedLocalesOf", "Intl.RelativeTimeFormat.supportedLocalesOf()")}}</dt>
+ <dd>Devuelve un {{jsxref("Array")}} con todos los idiomas disponibles sin necesidad de usar el que hay por defecto.</dd>
+</dl>
+
+<h2 id="Métodos_de_instancia">Métodos de instancia</h2>
+
+<dl>
+ <dt>{{jsxref("RelativeTimeFormat.format", "Intl.RelativeTimeFormat.prototype.format()")}}</dt>
+ <dd>Formatea <code>value</code> y <code>unit</code> conforme al idioma y las opciones de formateo al crear la instancia con <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl.RelativeTimeFormat"><code>Intl.RelativeTimeFormat</code></a>.</dd>
+ <dt>{{jsxref("RelativeTimeFormat.formatToParts", "Intl.RelativeTimeFormat.prototype.formatToParts()")}}</dt>
+ <dd>Devuelve un {{jsxref("Array")}} de objetos representando el tiempo relativo en partes que pueden ser usadas en traducciones.</dd>
+ <dt>{{jsxref("RelativeTimeFormat.resolvedOptions", "Intl.RelativeTimeFormat.prototype.resolvedOptions()")}}</dt>
+ <dd>Devuelve un nuevo objeto con las propiedades que reflejan las opciones de localización y formato usadas durante la inicialización del objeto.</dd>
+</dl>
+
+<h2 id="Ejemplos">Ejemplos</h2>
+
+<h3 id="Ejemplo_básico">Ejemplo básico</h3>
+
+<p>El siguiente ejemplo muestra cómo conseguir el tiempo relativo para el mejor idioma según el usuario.</p>
+
+<pre class="brush: js notranslate">// Crea un formateador de tiempo relativo en tu lenguaje
+// con los valores por defectos pasados expresamente.
+const rtf = new Intl.RelativeTimeFormat("en", {
+ localeMatcher: "best fit", // otros valores: "lookup"
+ numeric: "always", // otros valores: "auto"
+ style: "long", // otros valores: "short" or "narrow"
+});
+
+// Formatea el tiempo relativo con valores negativos (-1).
+rtf.format(-1, "day");
+// &gt; "Hace 1 día"
+
+// Formatea el tiempo relativo con valores positivos (1).
+rtf.format(1, "day");
+// &gt; "Dentro de 1 día"</pre>
+
+<h3 id="Usando_formatToParts">Usando <code>formatToParts</code></h3>
+
+<p>El siguiente ejemplo muestra cómo crear un formateador de tiempo relativo que devuelve las partes separadas:</p>
+
+<pre class="brush: js notranslate">const rtf = new Intl.RelativeTimeFormat("es", { numeric: "auto" });
+
+// Formatea el tiempo relativo usando día como unidad.
+rtf.formatToParts(-1, "day");
+// &gt; [{ type: "literal", value: "ayer"}]
+
+rtf.formatToParts(100, "day");
+// &gt; [{ type: "literal", value: "Dentro de " },
+// &gt; { type: "integer", value: "100", unit: "day" },
+// &gt; { type: "literal", value: " días" }]
+</pre>
+
+<h2 id="Especificaciones">Especificaciones</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificación</th>
+ <th scope="col">Estado</th>
+ <th scope="col">Comentario</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES Int Draft', '#relativetimeformat-objects', 'RelativeTimeFormat')}}</td>
+ <td></td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidad_en_navegadores">Compatibilidad en navegadores</h2>
+
+<div class="hidden">La tabla de compatibilidad es generada a partir de datos estructurados. Si quieres contribuir, por favor, revisa <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> y envíanos una Pull Request.</div>
+
+<p>{{Compat("javascript.builtins.Intl.RelativeTimeFormat")}}</p>
+
+<h2 id="Ver_también">Ver también</h2>
+
+<ul>
+ <li><a href="https://developers.google.com/web/updates/2018/10/intl-relativetimeformat">The Intl.RelativeTimeFormat API</a></li>
+</ul>