From a55b575e8089ee6cab7c5c262a7e6db55d0e34d6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:46:50 +0100 Subject: unslug es: move --- .../intl/relativetimeformat/index.html | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 files/es/web/javascript/reference/global_objects/intl/relativetimeformat/index.html (limited to 'files/es/web/javascript/reference/global_objects/intl/relativetimeformat') 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 +--- +
{{JSRef}}
+ +

El objeto Intl.RelativeTimeFormat te proporciona una manera de formatear tiempos relativos con traducciones.

+ +
{{EmbedInteractiveExample("pages/js/intl-relativetimeformat.html")}}
+ + + +

Constructor

+ +
+
{{jsxref("RelativeTimeFormat.RelativeTimeFormat()", "Intl.RelativeTimeFormat.RelativeTimeFormat()")}}
+
Crea una nueva instancia de Intl.RelativeTimeFormat.
+
+ +

Métodos estáticos

+ +
+
{{jsxref("RelativeTimeFormat.supportedLocalesOf", "Intl.RelativeTimeFormat.supportedLocalesOf()")}}
+
Devuelve un {{jsxref("Array")}} con todos los idiomas disponibles sin necesidad de usar el que hay por defecto.
+
+ +

Métodos de instancia

+ +
+
{{jsxref("RelativeTimeFormat.format", "Intl.RelativeTimeFormat.prototype.format()")}}
+
Formatea value y unit conforme al idioma y las opciones de formateo al crear la instancia con Intl.RelativeTimeFormat.
+
{{jsxref("RelativeTimeFormat.formatToParts", "Intl.RelativeTimeFormat.prototype.formatToParts()")}}
+
Devuelve un {{jsxref("Array")}} de objetos representando el tiempo relativo en partes que pueden ser usadas en traducciones.
+
{{jsxref("RelativeTimeFormat.resolvedOptions", "Intl.RelativeTimeFormat.prototype.resolvedOptions()")}}
+
Devuelve un nuevo objeto con las propiedades que reflejan las opciones de localización y formato usadas durante la inicialización del objeto.
+
+ +

Ejemplos

+ +

Ejemplo básico

+ +

El siguiente ejemplo muestra cómo conseguir el tiempo relativo para el mejor idioma según el usuario.

+ +
// 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");
+// > "Hace 1 día"
+
+// Formatea el tiempo relativo con valores positivos (1).
+rtf.format(1, "day");
+// > "Dentro de 1 día"
+ +

Usando formatToParts

+ +

El siguiente ejemplo muestra cómo crear un formateador de tiempo relativo que devuelve las partes separadas:

+ +
const rtf = new Intl.RelativeTimeFormat("es", { numeric: "auto" });
+
+// Formatea el tiempo relativo usando día como unidad.
+rtf.formatToParts(-1, "day");
+// > [{ type: "literal", value: "ayer"}]
+
+rtf.formatToParts(100, "day");
+// > [{ type: "literal", value: "Dentro de " },
+// >  { type: "integer", value: "100", unit: "day" },
+// >  { type: "literal", value: " días" }]
+
+ +

Especificaciones

+ + + + + + + + + + + + + + +
EspecificaciónEstadoComentario
{{SpecName('ES Int Draft', '#relativetimeformat-objects', 'RelativeTimeFormat')}}
+ +

Compatibilidad en navegadores

+ + + +

{{Compat("javascript.builtins.Intl.RelativeTimeFormat")}}

+ +

Ver también

+ + -- cgit v1.2.3-54-g00ecf