@intlayer/docs 5.7.7 → 5.8.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blog/ar/intlayer_with_next-i18next.md +3 -4
- package/blog/ar/intlayer_with_next-intl.md +3 -4
- package/blog/ar/intlayer_with_react-i18next.md +1 -1
- package/blog/ar/intlayer_with_react-intl.md +1 -1
- package/blog/de/intlayer_with_next-i18next.md +3 -4
- package/blog/de/intlayer_with_react-intl.md +1 -1
- package/blog/en/intlayer_with_next-i18next.md +3 -4
- package/blog/en/intlayer_with_next-intl.md +3 -4
- package/blog/en/intlayer_with_react-i18next.md +1 -1
- package/blog/en/intlayer_with_react-intl.md +1 -1
- package/blog/en-GB/intlayer_with_next-i18next.md +3 -4
- package/blog/en-GB/intlayer_with_next-intl.md +3 -4
- package/blog/en-GB/intlayer_with_react-i18next.md +1 -1
- package/blog/en-GB/intlayer_with_react-intl.md +1 -1
- package/blog/es/intlayer_with_next-i18next.md +3 -4
- package/blog/es/intlayer_with_next-intl.md +3 -4
- package/blog/es/intlayer_with_react-i18next.md +1 -1
- package/blog/es/intlayer_with_react-intl.md +1 -1
- package/blog/fr/intlayer_with_next-i18next.md +3 -4
- package/blog/fr/intlayer_with_next-intl.md +3 -4
- package/blog/fr/intlayer_with_react-i18next.md +1 -1
- package/blog/fr/intlayer_with_react-intl.md +1 -1
- package/blog/hi/intlayer_with_next-i18next.md +3 -4
- package/blog/hi/intlayer_with_next-intl.md +3 -4
- package/blog/hi/intlayer_with_react-i18next.md +1 -1
- package/blog/hi/intlayer_with_react-intl.md +1 -1
- package/blog/it/intlayer_with_next-i18next.md +3 -4
- package/blog/it/intlayer_with_next-intl.md +3 -4
- package/blog/it/intlayer_with_react-i18next.md +1 -1
- package/blog/it/intlayer_with_react-intl.md +1 -1
- package/blog/ja/intlayer_with_next-i18next.md +3 -4
- package/blog/ja/intlayer_with_next-intl.md +3 -4
- package/blog/ja/intlayer_with_react-intl.md +1 -1
- package/blog/ko/intlayer_with_next-i18next.md +3 -4
- package/blog/ko/intlayer_with_next-intl.md +3 -4
- package/blog/ko/intlayer_with_react-intl.md +1 -1
- package/blog/pt/intlayer_with_next-i18next.md +3 -4
- package/blog/pt/intlayer_with_next-intl.md +3 -4
- package/blog/pt/intlayer_with_react-intl.md +1 -1
- package/blog/ru/intlayer_with_next-i18next.md +3 -4
- package/blog/ru/intlayer_with_next-intl.md +3 -4
- package/blog/ru/intlayer_with_react-i18next.md +1 -1
- package/blog/ru/intlayer_with_react-intl.md +1 -1
- package/blog/zh/intlayer_with_next-i18next.md +3 -4
- package/blog/zh/intlayer_with_next-intl.md +3 -4
- package/blog/zh/intlayer_with_react-i18next.md +1 -1
- package/blog/zh/intlayer_with_react-intl.md +1 -1
- package/dist/cjs/generated/docs.entry.cjs +41 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +41 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/CI_CD.md +67 -41
- package/docs/ar/formatters.md +239 -0
- package/docs/ar/interest_of_intlayer.md +162 -49
- package/docs/ar/introduction.md +3 -3
- package/docs/ar/packages/intlayer/index.md +3 -3
- package/docs/ar/packages/next-intlayer/index.md +3 -3
- package/docs/de/CI_CD.md +63 -37
- package/docs/de/formatters.md +239 -0
- package/docs/de/interest_of_intlayer.md +161 -47
- package/docs/de/introduction.md +3 -3
- package/docs/de/packages/intlayer/index.md +3 -3
- package/docs/de/packages/next-intlayer/index.md +3 -3
- package/docs/de/packages/react-intlayer/index.md +3 -3
- package/docs/en/CI_CD.md +51 -27
- package/docs/en/formatters.md +250 -0
- package/docs/en/interest_of_intlayer.md +159 -46
- package/docs/en/introduction.md +3 -3
- package/docs/en/packages/intlayer/index.md +3 -3
- package/docs/en/packages/next-intlayer/index.md +3 -3
- package/docs/en/packages/react-intlayer/index.md +3 -3
- package/docs/en-GB/CI_CD.md +58 -32
- package/docs/en-GB/formatters.md +239 -0
- package/docs/en-GB/interest_of_intlayer.md +160 -53
- package/docs/en-GB/packages/intlayer/index.md +3 -3
- package/docs/en-GB/packages/next-intlayer/index.md +3 -3
- package/docs/en-GB/packages/react-intlayer/index.md +3 -3
- package/docs/es/CI_CD.md +68 -42
- package/docs/es/formatters.md +239 -0
- package/docs/es/interest_of_intlayer.md +159 -47
- package/docs/es/introduction.md +3 -3
- package/docs/es/packages/intlayer/index.md +3 -3
- package/docs/es/packages/next-intlayer/index.md +3 -3
- package/docs/fr/formatters.md +239 -0
- package/docs/fr/interest_of_intlayer.md +160 -46
- package/docs/fr/introduction.md +3 -3
- package/docs/fr/packages/intlayer/index.md +3 -3
- package/docs/fr/packages/next-intlayer/index.md +3 -3
- package/docs/fr/packages/react-intlayer/index.md +3 -3
- package/docs/hi/CI_CD.md +69 -44
- package/docs/hi/formatters.md +239 -0
- package/docs/hi/interest_of_intlayer.md +158 -42
- package/docs/hi/introduction.md +3 -3
- package/docs/hi/packages/intlayer/index.md +3 -3
- package/docs/hi/packages/next-intlayer/index.md +3 -3
- package/docs/hi/packages/react-intlayer/index.md +3 -3
- package/docs/it/CI_CD.md +67 -41
- package/docs/it/formatters.md +239 -0
- package/docs/it/interest_of_intlayer.md +160 -46
- package/docs/it/introduction.md +3 -3
- package/docs/it/packages/intlayer/index.md +3 -3
- package/docs/it/packages/next-intlayer/index.md +3 -3
- package/docs/it/packages/react-intlayer/index.md +3 -3
- package/docs/ja/CI_CD.md +67 -41
- package/docs/ja/formatters.md +261 -0
- package/docs/ja/interest_of_intlayer.md +157 -48
- package/docs/ja/introduction.md +3 -3
- package/docs/ja/packages/intlayer/index.md +3 -3
- package/docs/ja/packages/next-intlayer/index.md +3 -3
- package/docs/ja/packages/react-intlayer/index.md +3 -3
- package/docs/ko/CI_CD.md +63 -37
- package/docs/ko/formatters.md +258 -0
- package/docs/ko/interest_of_intlayer.md +160 -48
- package/docs/ko/introduction.md +3 -3
- package/docs/ko/packages/intlayer/index.md +3 -3
- package/docs/ko/packages/next-intlayer/index.md +3 -3
- package/docs/ko/packages/react-intlayer/index.md +3 -3
- package/docs/pt/CI_CD.md +67 -41
- package/docs/pt/formatters.md +239 -0
- package/docs/pt/interest_of_intlayer.md +162 -47
- package/docs/pt/introduction.md +3 -3
- package/docs/pt/packages/intlayer/index.md +3 -3
- package/docs/pt/packages/next-intlayer/index.md +3 -3
- package/docs/pt/packages/react-intlayer/index.md +3 -3
- package/docs/ru/CI_CD.md +70 -44
- package/docs/ru/formatters.md +239 -0
- package/docs/ru/interest_of_intlayer.md +168 -50
- package/docs/ru/introduction.md +3 -3
- package/docs/ru/packages/intlayer/index.md +3 -3
- package/docs/ru/packages/next-intlayer/index.md +3 -3
- package/docs/ru/packages/react-intlayer/index.md +3 -3
- package/docs/zh/CI_CD.md +62 -36
- package/docs/zh/formatters.md +239 -0
- package/docs/zh/interest_of_intlayer.md +158 -48
- package/docs/zh/introduction.md +3 -3
- package/docs/zh/packages/intlayer/index.md +3 -3
- package/docs/zh/packages/next-intlayer/index.md +3 -3
- package/docs/zh/packages/react-intlayer/index.md +3 -3
- package/package.json +12 -12
- package/src/generated/docs.entry.ts +41 -0
|
@@ -110,8 +110,8 @@ const clientComponentContent = {
|
|
|
110
110
|
content: {
|
|
111
111
|
myTranslatedContent: t({
|
|
112
112
|
en: "Hello World",
|
|
113
|
-
fr: "Bonjour le monde",
|
|
114
113
|
es: "Hola Mundo",
|
|
114
|
+
fr: "Bonjour le monde",
|
|
115
115
|
}),
|
|
116
116
|
numberOfCar: enu({
|
|
117
117
|
"<-1": "Less than minus one car",
|
|
@@ -136,8 +136,8 @@ const clientComponentContent = {
|
|
|
136
136
|
content: {
|
|
137
137
|
myTranslatedContent: t({
|
|
138
138
|
en: "Hello World",
|
|
139
|
-
fr: "Bonjour le monde",
|
|
140
139
|
es: "Hola Mundo",
|
|
140
|
+
fr: "Bonjour le monde",
|
|
141
141
|
}),
|
|
142
142
|
numberOfCar: enu({
|
|
143
143
|
"<-1": "Less than minus one car",
|
|
@@ -162,8 +162,8 @@ const clientComponentContent = {
|
|
|
162
162
|
content: {
|
|
163
163
|
myTranslatedContent: t({
|
|
164
164
|
en: "Hello World",
|
|
165
|
-
fr: "Bonjour le monde",
|
|
166
165
|
es: "Hola Mundo",
|
|
166
|
+
fr: "Bonjour le monde",
|
|
167
167
|
}),
|
|
168
168
|
numberOfCar: enu({
|
|
169
169
|
"<-1": "Less than minus one car",
|
|
@@ -110,8 +110,8 @@ const component1Content = {
|
|
|
110
110
|
content: {
|
|
111
111
|
myTranslatedContent: t({
|
|
112
112
|
en: "Hello World",
|
|
113
|
-
fr: "Bonjour le monde",
|
|
114
113
|
es: "Hola Mundo",
|
|
114
|
+
fr: "Bonjour le monde",
|
|
115
115
|
}),
|
|
116
116
|
numberOfCar: enu({
|
|
117
117
|
"<-1": "Less than minus one car",
|
|
@@ -136,8 +136,8 @@ const component1Content = {
|
|
|
136
136
|
content: {
|
|
137
137
|
myTranslatedContent: t({
|
|
138
138
|
en: "Hello World",
|
|
139
|
-
fr: "Bonjour le monde",
|
|
140
139
|
es: "Hola Mundo",
|
|
140
|
+
fr: "Bonjour le monde",
|
|
141
141
|
}),
|
|
142
142
|
numberOfCar: enu({
|
|
143
143
|
"<-1": "Less than minus one car",
|
|
@@ -162,8 +162,8 @@ const component1Content = {
|
|
|
162
162
|
content: {
|
|
163
163
|
myTranslatedContent: t({
|
|
164
164
|
en: "Hello World",
|
|
165
|
-
fr: "Bonjour le monde",
|
|
166
165
|
es: "Hola Mundo",
|
|
166
|
+
fr: "Bonjour le monde",
|
|
167
167
|
}),
|
|
168
168
|
numberOfCar: enu({
|
|
169
169
|
"<-1": "Less than minus one car",
|
package/docs/es/CI_CD.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-05-20
|
|
3
|
-
updatedAt: 2025-
|
|
3
|
+
updatedAt: 2025-08-13
|
|
4
4
|
title: Integración CI/CD
|
|
5
|
-
description: Aprende cómo integrar Intlayer en tu pipeline
|
|
5
|
+
description: Aprende cómo integrar Intlayer en tu pipeline CI/CD para la gestión y despliegue automatizado de contenido.
|
|
6
6
|
keywords:
|
|
7
7
|
- CI/CD
|
|
8
8
|
- Integración Continua
|
|
@@ -19,13 +19,13 @@ slugs:
|
|
|
19
19
|
|
|
20
20
|
# Generación Automática de Traducciones en un Pipeline CI/CD
|
|
21
21
|
|
|
22
|
-
Intlayer permite la generación automática de traducciones para tus archivos de declaración de contenido. Existen
|
|
22
|
+
Intlayer permite la generación automática de traducciones para tus archivos de declaración de contenido. Existen múltiples formas de lograr esto dependiendo de tu flujo de trabajo.
|
|
23
23
|
|
|
24
24
|
## Uso del CMS
|
|
25
25
|
|
|
26
|
-
Con Intlayer, puedes adoptar un flujo de trabajo donde solo se declara un único locale localmente, mientras que todas las traducciones se gestionan de forma remota a través del CMS. Esto permite que el contenido y las traducciones estén completamente desacoplados
|
|
26
|
+
Con Intlayer, puedes adoptar un flujo de trabajo donde solo se declara un único locale localmente, mientras que todas las traducciones se gestionan de forma remota a través del CMS. Esto permite que el contenido y las traducciones estén completamente desacoplados del código base, ofreciendo más flexibilidad para los editores de contenido y habilitando la recarga en caliente del contenido (no es necesario reconstruir la aplicación para aplicar cambios).
|
|
27
27
|
|
|
28
|
-
### Configuración de
|
|
28
|
+
### Configuración de Ejemplo
|
|
29
29
|
|
|
30
30
|
```ts fileName="intlayer.config.ts"
|
|
31
31
|
import { Locales, type IntlayerConfig } from "intlayer";
|
|
@@ -45,7 +45,7 @@ const config: IntlayerConfig = {
|
|
|
45
45
|
clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
46
46
|
},
|
|
47
47
|
ai: {
|
|
48
|
-
applicationContext: "
|
|
48
|
+
applicationContext: "Esta es una aplicación de prueba", // Ayuda a asegurar una generación consistente de traducciones
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
51
|
|
|
@@ -58,7 +58,7 @@ Para aprender más sobre el CMS, consulta la [documentación oficial](https://gi
|
|
|
58
58
|
|
|
59
59
|
Puedes integrar la generación de traducciones en tu flujo de trabajo local de Git usando [Husky](https://typicode.github.io/husky/).
|
|
60
60
|
|
|
61
|
-
### Configuración de
|
|
61
|
+
### Configuración de Ejemplo
|
|
62
62
|
|
|
63
63
|
```ts fileName="intlayer.config.ts"
|
|
64
64
|
import { Locales, type IntlayerConfig } from "intlayer";
|
|
@@ -66,7 +66,7 @@ import { Locales, type IntlayerConfig } from "intlayer";
|
|
|
66
66
|
const config: IntlayerConfig = {
|
|
67
67
|
internationalization: {
|
|
68
68
|
locales: [Locales.ENGLISH, Locales.SPANISH, Locales.FRENCH],
|
|
69
|
-
requiredLocales: [Locales.ENGLISH], // Los locales opcionales se
|
|
69
|
+
requiredLocales: [Locales.ENGLISH], // Los locales opcionales se manejan de forma remota
|
|
70
70
|
defaultLocale: Locales.ENGLISH,
|
|
71
71
|
},
|
|
72
72
|
editor: {
|
|
@@ -77,7 +77,7 @@ const config: IntlayerConfig = {
|
|
|
77
77
|
provider: "openai",
|
|
78
78
|
apiKey: process.env.OPENAI_API_KEY, // Usa tu propia clave API
|
|
79
79
|
|
|
80
|
-
applicationContext: "
|
|
80
|
+
applicationContext: "Esta es una aplicación de prueba", // Ayuda a asegurar una generación consistente de traducciones
|
|
81
81
|
},
|
|
82
82
|
};
|
|
83
83
|
|
|
@@ -91,7 +91,7 @@ npx intlayer fill --unpushed --mode fill # Solo rellena el contenido faltante
|
|
|
91
91
|
|
|
92
92
|
> Para más información sobre los comandos CLI de Intlayer y su uso, consulta la [documentación CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_cli.md).
|
|
93
93
|
|
|
94
|
-
> Si tienes múltiples aplicaciones en tu repositorio usando instancias separadas de Intlayer, puedes usar el argumento `--base-dir`
|
|
94
|
+
> Si tienes múltiples aplicaciones en tu repositorio usando instancias separadas de Intlayer, puedes usar el argumento `--base-dir` de esta manera:
|
|
95
95
|
|
|
96
96
|
```bash fileName=".husky/pre-push"
|
|
97
97
|
# App 1
|
|
@@ -105,68 +105,94 @@ npx intlayer fill --base-dir ./app2 --unpushed --mode fill
|
|
|
105
105
|
|
|
106
106
|
## Uso de GitHub Actions
|
|
107
107
|
|
|
108
|
-
Intlayer proporciona un comando CLI para
|
|
108
|
+
Intlayer proporciona un comando CLI para rellenar automáticamente y revisar el contenido del diccionario. Esto se puede integrar en tu flujo de trabajo CI/CD usando GitHub Actions.
|
|
109
109
|
|
|
110
110
|
```yaml fileName=".github/workflows/intlayer-translate.yml"
|
|
111
|
-
name:
|
|
111
|
+
name: Relleno Automático de Intlayer
|
|
112
|
+
# Condiciones para activar este flujo de trabajo
|
|
112
113
|
on:
|
|
113
|
-
push:
|
|
114
|
-
branches: [ main ]
|
|
115
|
-
paths:
|
|
116
|
-
- 'src/**'
|
|
117
114
|
pull_request:
|
|
118
|
-
branches:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
branches:
|
|
116
|
+
- "main"
|
|
117
|
+
|
|
118
|
+
permissions:
|
|
119
|
+
contents: write
|
|
120
|
+
pull-requests: write
|
|
122
121
|
|
|
123
122
|
concurrency:
|
|
124
|
-
group:
|
|
123
|
+
group: "autofill-${{ github.ref }}"
|
|
125
124
|
cancel-in-progress: true
|
|
126
125
|
|
|
127
126
|
jobs:
|
|
128
127
|
autofill:
|
|
129
128
|
runs-on: ubuntu-latest
|
|
130
129
|
env:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
# OpenAI
|
|
131
|
+
AI_MODEL: openai
|
|
132
|
+
AI_PROVIDER: gpt-5-mini
|
|
133
|
+
AI_API_KEY: ${{ secrets.AI_API_KEY }}
|
|
134
134
|
|
|
135
135
|
steps:
|
|
136
|
+
# Paso 1: Obtener el código más reciente del repositorio
|
|
136
137
|
- name: ⬇️ Clonar repositorio
|
|
137
|
-
uses: actions/checkout@
|
|
138
|
+
uses: actions/checkout@v4
|
|
138
139
|
with:
|
|
139
|
-
persist-credentials: true
|
|
140
|
+
persist-credentials: true # Mantener credenciales para crear PRs
|
|
141
|
+
fetch-depth: 0 # Obtener todo el historial git para análisis de diferencias
|
|
140
142
|
|
|
143
|
+
# Paso 2: Configurar el entorno de Node.js
|
|
141
144
|
- name: 🟢 Configurar Node.js
|
|
142
|
-
uses: actions/setup-node@
|
|
145
|
+
uses: actions/setup-node@v4
|
|
143
146
|
with:
|
|
144
|
-
node-version: 20
|
|
147
|
+
node-version: 20 # Usar Node.js 20 LTS para estabilidad
|
|
145
148
|
|
|
149
|
+
# Paso 3: Instalar dependencias del proyecto
|
|
146
150
|
- name: 📦 Instalar dependencias
|
|
147
|
-
run: npm
|
|
151
|
+
run: npm install
|
|
152
|
+
|
|
153
|
+
# Paso 4: Instalar Intlayer CLI globalmente para gestión de traducciones
|
|
154
|
+
- name: 📦 Instalar Intlayer
|
|
155
|
+
run: npm install -g intlayer-cli
|
|
148
156
|
|
|
157
|
+
# Paso 5: Construir el proyecto Intlayer para generar archivos de traducción
|
|
149
158
|
- name: ⚙️ Construir proyecto Intlayer
|
|
150
159
|
run: npx intlayer build
|
|
151
160
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
# Paso 6: Usar IA para rellenar automáticamente las traducciones faltantes
|
|
162
|
+
- name: 🤖 Rellenar automáticamente las traducciones faltantes
|
|
163
|
+
run: npx intlayer fill --git-diff --mode fill --provider $AI_PROVIDER --model $AI_MODEL --api-key $AI_API_KEY
|
|
164
|
+
|
|
165
|
+
# Paso 7: Verificar si hay cambios y confirmarlos
|
|
166
|
+
- name: � Verificar cambios
|
|
167
|
+
id: check-changes
|
|
168
|
+
run: |
|
|
169
|
+
if [ -n "$(git status --porcelain)" ]; then
|
|
170
|
+
echo "has-changes=true" >> $GITHUB_OUTPUT
|
|
171
|
+
else
|
|
172
|
+
echo "has-changes=false" >> $GITHUB_OUTPUT
|
|
173
|
+
fi
|
|
174
|
+
|
|
175
|
+
# Paso 8: Confirmar y enviar cambios si existen
|
|
176
|
+
- name: 📤 Confirmar y enviar cambios
|
|
177
|
+
if: steps.check-changes.outputs.has-changes == 'true'
|
|
178
|
+
run: |
|
|
179
|
+
git config --local user.email "action@github.com"
|
|
180
|
+
git config --local user.name "GitHub Action"
|
|
181
|
+
git add .
|
|
182
|
+
git commit -m "chore: auto-fill missing translations [skip ci]"
|
|
183
|
+
git push origin HEAD:${{ github.head_ref }}
|
|
162
184
|
```
|
|
163
185
|
|
|
164
|
-
|
|
186
|
+
Para configurar las variables de entorno, vaya a GitHub → Configuración → Secrets and variables → Actions y agregue el secreto .
|
|
187
|
+
|
|
188
|
+
> Al igual que con Husky, en el caso de un monorepo, puede usar el argumento `--base-dir` para tratar secuencialmente cada aplicación.
|
|
165
189
|
|
|
166
190
|
> Por defecto, el argumento `--git-diff` filtra los diccionarios que incluyen cambios desde la base (por defecto `origin/main`) hasta la rama actual (por defecto: `HEAD`).
|
|
167
191
|
|
|
168
|
-
> Para más información sobre los comandos de
|
|
192
|
+
> Para más información sobre los comandos de Intlayer CLI y su uso, consulte la [documentación del CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_cli.md).
|
|
169
193
|
|
|
170
194
|
## Historial del documento
|
|
171
195
|
|
|
172
|
-
|
|
196
|
+
| Versión | Fecha | Cambios |
|
|
197
|
+
| ------- | ---------- | ----------------- |
|
|
198
|
+
| 5.5.10 | 2025-06-29 | Historial inicial |
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2024-08-13
|
|
3
|
+
updatedAt: 2025-08-20
|
|
4
|
+
title: Formateadores
|
|
5
|
+
description: Utilidades de formato conscientes de la configuración regional basadas en Intl para números, porcentajes, moneda, fechas, tiempo relativo, unidades y notación compacta. Incluye un ayudante Intl con caché.
|
|
6
|
+
keywords:
|
|
7
|
+
- Formateadores
|
|
8
|
+
- Intl
|
|
9
|
+
- Número
|
|
10
|
+
- Moneda
|
|
11
|
+
- Porcentaje
|
|
12
|
+
- Fecha
|
|
13
|
+
- Tiempo Relativo
|
|
14
|
+
- Unidades
|
|
15
|
+
- Compacto
|
|
16
|
+
- Internacionalización
|
|
17
|
+
slugs:
|
|
18
|
+
- doc
|
|
19
|
+
- formatters
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
# Formateadores de Intlayer
|
|
23
|
+
|
|
24
|
+
## Resumen
|
|
25
|
+
|
|
26
|
+
Intlayer proporciona un conjunto de ayudantes ligeros construidos sobre las APIs nativas `Intl`, además de un envoltorio `Intl` con caché para evitar construir repetidamente formateadores pesados. Estas utilidades son totalmente conscientes de la configuración regional y pueden usarse desde el paquete principal `intlayer`.
|
|
27
|
+
|
|
28
|
+
### Importar
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import {
|
|
32
|
+
Intl,
|
|
33
|
+
number,
|
|
34
|
+
percentage,
|
|
35
|
+
currency,
|
|
36
|
+
date,
|
|
37
|
+
relativeTime,
|
|
38
|
+
units,
|
|
39
|
+
compact,
|
|
40
|
+
} from "intlayer";
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Si usas React, también hay disponibles hooks; consulta `react-intlayer/format`.
|
|
44
|
+
|
|
45
|
+
## Intl con caché
|
|
46
|
+
|
|
47
|
+
El `Intl` exportado es un envoltorio delgado con caché alrededor del `Intl` global. Memoiza instancias de `NumberFormat`, `DateTimeFormat`, `RelativeTimeFormat`, lo que evita reconstruir el mismo formateador repetidamente.
|
|
48
|
+
|
|
49
|
+
Debido a que la construcción de formateadores es relativamente costosa, esta caché mejora el rendimiento sin cambiar el comportamiento. El envoltorio expone la misma API que el `Intl` nativo, por lo que el uso es idéntico.
|
|
50
|
+
|
|
51
|
+
- La caché es por proceso y transparente para los llamadores.
|
|
52
|
+
|
|
53
|
+
> Si `Intl.DisplayNames` no está disponible en el entorno, se imprime una única advertencia solo para desarrollo (considera un polyfill).
|
|
54
|
+
|
|
55
|
+
Ejemplo:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { Intl } from "intlayer";
|
|
59
|
+
|
|
60
|
+
const numberFormat = new Intl.NumberFormat("en-GB", {
|
|
61
|
+
style: "currency",
|
|
62
|
+
currency: "GBP",
|
|
63
|
+
});
|
|
64
|
+
numberFormat.format(1234.5); // "£1,234.50"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Formateadores
|
|
68
|
+
|
|
69
|
+
Todos los ayudantes a continuación se exportan desde `intlayer`.
|
|
70
|
+
|
|
71
|
+
### `number(value, options?)`
|
|
72
|
+
|
|
73
|
+
Formatea un valor numérico usando agrupación y decimales sensibles a la configuración regional.
|
|
74
|
+
|
|
75
|
+
- **value**: `number | string`
|
|
76
|
+
- **options**: `Intl.NumberFormatOptions & { locale?: LocalesValues }`
|
|
77
|
+
|
|
78
|
+
Ejemplos:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { number } from "intlayer";
|
|
82
|
+
|
|
83
|
+
number(123456.789); // "123,456.789" (en en-US)
|
|
84
|
+
number("1000000", { locale: "fr" }); // "1 000 000"
|
|
85
|
+
number(1234.5, { minimumFractionDigits: 2 }); // "1,234.50"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### `percentage(value, options?)`
|
|
89
|
+
|
|
90
|
+
Formatea un número como una cadena de porcentaje.
|
|
91
|
+
|
|
92
|
+
Comportamiento: los valores mayores que 1 se interpretan como porcentajes enteros y se normalizan (por ejemplo, `25` → `25%`, `0.25` → `25%`).
|
|
93
|
+
|
|
94
|
+
- **value**: `number | string`
|
|
95
|
+
- **options**: `Intl.NumberFormatOptions & { locale?: LocalesValues }`
|
|
96
|
+
|
|
97
|
+
Ejemplos:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { percentage } from "intlayer";
|
|
101
|
+
|
|
102
|
+
percentage(0.25); // "25%"
|
|
103
|
+
percentage(25); // "25%"
|
|
104
|
+
percentage(0.237, { minimumFractionDigits: 1 }); // "23.7%"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### `currency(value, options?)`
|
|
108
|
+
|
|
109
|
+
Formatea un valor como moneda localizada. Por defecto es `USD` con dos dígitos decimales.
|
|
110
|
+
|
|
111
|
+
- **value**: `number | string`
|
|
112
|
+
- **options**: `Intl.NumberFormatOptions & { locale?: LocalesValues }`
|
|
113
|
+
- Campos comunes: `currency` (por ejemplo, `"EUR"`), `currencyDisplay` (`"symbol" | "code" | "name"`)
|
|
114
|
+
|
|
115
|
+
Ejemplos:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { currency } from "intlayer";
|
|
119
|
+
|
|
120
|
+
currency(1234.5, { currency: "EUR" }); // "€1,234.50"
|
|
121
|
+
currency("5000", { locale: "fr", currency: "CAD", currencyDisplay: "code" }); // "5 000,00 CAD"
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### `date(date, optionsOrPreset?)`
|
|
125
|
+
|
|
126
|
+
Formatea un valor de fecha/hora con `Intl.DateTimeFormat`.
|
|
127
|
+
|
|
128
|
+
- **date**: `Date | string | number`
|
|
129
|
+
- **optionsOrPreset**: `Intl.DateTimeFormatOptions & { locale?: LocalesValues }` o uno de los preajustes:
|
|
130
|
+
- Preajustes: `"short" | "long" | "dateOnly" | "timeOnly" | "full"`
|
|
131
|
+
|
|
132
|
+
Ejemplos:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { date } from "intlayer";
|
|
136
|
+
|
|
137
|
+
date(new Date(), "short"); // p. ej., "08/02/25, 14:30"
|
|
138
|
+
date("2025-08-02T14:30:00Z", { locale: "fr", month: "long", day: "numeric" }); // "2 août"
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### `relativeTime(from, to = new Date(), options?)`
|
|
142
|
+
|
|
143
|
+
Formatea el tiempo relativo entre dos instantes con `Intl.RelativeTimeFormat`.
|
|
144
|
+
|
|
145
|
+
- Pasa "now" como el primer argumento y el objetivo como el segundo para obtener una frase natural.
|
|
146
|
+
- **from**: `Date | string | number`
|
|
147
|
+
- **to**: `Date | string | number` (por defecto `new Date()`)
|
|
148
|
+
- **options**: `{ locale?: LocalesValues; unit?: Intl.RelativeTimeFormatUnit; numeric?: Intl.RelativeTimeFormatNumeric; style?: Intl.RelativeTimeFormatStyle }`
|
|
149
|
+
- El valor predeterminado de `unit` es `"second"`.
|
|
150
|
+
|
|
151
|
+
Ejemplos:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { relativeTime } from "intlayer";
|
|
155
|
+
|
|
156
|
+
const now = new Date();
|
|
157
|
+
const in3Days = new Date(now.getTime() + 3 * 864e5);
|
|
158
|
+
relativeTime(now, in3Days, { unit: "day" }); // "in 3 days"
|
|
159
|
+
|
|
160
|
+
const twoHoursAgo = new Date(now.getTime() - 2 * 3600e3);
|
|
161
|
+
relativeTime(now, twoHoursAgo, { unit: "hour", numeric: "auto" }); // "2 hours ago"
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### `units(value, options?)`
|
|
165
|
+
|
|
166
|
+
Formatea un valor numérico como una cadena de unidad localizada usando `Intl.NumberFormat` con `style: 'unit'`.
|
|
167
|
+
|
|
168
|
+
- **value**: `number | string`
|
|
169
|
+
- **options**: `Intl.NumberFormatOptions & { locale?: LocalesValues }`
|
|
170
|
+
- Campos comunes: `unit` (por ejemplo, `"kilometer"`, `"byte"`), `unitDisplay` (`"short" | "narrow" | "long"`)
|
|
171
|
+
- Valores predeterminados: `unit: 'day'`, `unitDisplay: 'short'`, `useGrouping: false`
|
|
172
|
+
|
|
173
|
+
Ejemplos:
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
import { units } from "intlayer";
|
|
177
|
+
|
|
178
|
+
units(5, { unit: "kilometer", unitDisplay: "long", locale: "en-GB" }); // "5 kilometers"
|
|
179
|
+
units(1024, { unit: "byte", unitDisplay: "narrow" }); // "1,024B" (dependiente del locale)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### `compact(value, options?)`
|
|
183
|
+
|
|
184
|
+
Formatea un número usando notación compacta (por ejemplo, `1.2K`, `1M`).
|
|
185
|
+
|
|
186
|
+
- **value**: `number | string`
|
|
187
|
+
- **options**: `Intl.NumberFormatOptions & { locale?: LocalesValues }` (utiliza `notation: 'compact'` internamente)
|
|
188
|
+
|
|
189
|
+
Ejemplos:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { compact } from "intlayer";
|
|
193
|
+
|
|
194
|
+
compact(1200); // "1.2K"
|
|
195
|
+
compact("1000000", { locale: "fr", compactDisplay: "long" }); // "1 millón"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Notas
|
|
199
|
+
|
|
200
|
+
- Todos los helpers aceptan entradas de tipo `string`; internamente se convierten a números o fechas.
|
|
201
|
+
- El locale por defecto es el configurado en `internationalization.defaultLocale` si no se proporciona.
|
|
202
|
+
- Estas utilidades son envoltorios ligeros; para formateos avanzados, pase las opciones estándar de `Intl`.
|
|
203
|
+
|
|
204
|
+
## Puntos de entrada y re-exportaciones (`@index.ts`)
|
|
205
|
+
|
|
206
|
+
Los formateadores residen en el paquete core y se re-exportan desde paquetes de nivel superior para mantener las importaciones ergonómicas en diferentes entornos:
|
|
207
|
+
|
|
208
|
+
Ejemplos:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
// Código de la aplicación (recomendado)
|
|
212
|
+
import { number, currency, date, Intl } from "intlayer";
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### React
|
|
216
|
+
|
|
217
|
+
Componentes cliente:
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
import { useNumber, useCurrency, useDate } from "react-intlayer/format";
|
|
221
|
+
// o en aplicaciones Next.js
|
|
222
|
+
import { useNumber, useCurrency, useDate } from "next-intlayer/client/format";
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Componentes servidor (o runtime React Server):
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
import { useNumber, useCurrency, useDate } from "intlayer/server/format";
|
|
229
|
+
// o en aplicaciones Next.js
|
|
230
|
+
import { useNumber, useCurrency, useDate } from "next-intlayer/server/format";
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
> Esos hooks considerarán el locale desde el `IntlayerProvider` o `IntlayerServerProvider`
|
|
234
|
+
|
|
235
|
+
## Historial de la documentación
|
|
236
|
+
|
|
237
|
+
| Versión | Fecha | Cambios |
|
|
238
|
+
| ------- | ---------- | -------------------------------------- |
|
|
239
|
+
| 5.8.0 | 2025-08-18 | Añadida documentación de formateadores |
|