שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Clarify that content test exits non-zero on missing required locales"v6.1.027.10.2026
- "Make test async and add build option"v6.0.15.10.2025
- "Introduction of testing"v6.0.020.9.2025
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתאם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודהעתקת ה-Markdown של המסמך ללוח
Testing your content
This guide shows how to automatically verify your dictionaries are complete, catch missing translations before shipping, and test localized UI in your app.
What you can test
- Missing translations: fail CI if any required locales are missing for any dictionary.
- Localized UI rendering: render components with a specific locale provider and assert on visible text/attributes.
- Build-time audits: run
npx intlayer content testlocally or in CI; it exits non-zero when required translations are missing.
Quick start: audit via CLI
Run the audit from your project root:
העתקת הקוד ללוח
Useful flags:
--env-file [path]: load environment variables from a file.-e, --env [name]: select an environment profile.--base-dir [path]: set the app base directory for resolution.--verbose: show verbose logs.--prefix [label]: prefix log lines.--build [build]: build the dictionaries before testing to ensure the content is up to date. True will force the build, false will skip the build, undefined will allow using the cache of the build.
The command exits with code 1 when any required locale is missing (see requiredLocales in your configuration), and 0 otherwise. You can use it directly to fail CI jobs or commit hooks. The programmatic test below is an optional alternative.
Programmatic test (Vitest/Jest)
Use the Intlayer CLI API to assert there are no missing translations for your required locales.
העתקת הקוד ללוח
Jest equivalent:
העתקת הקוד ללוח
How it works:
- Intlayer reads your configuration (locales, requiredLocales) and declared dictionaries, then reports:
missingTranslations: per‑key, which locales are missing and from which file.missingLocales: union of all missing locales.missingRequiredLocales: subset limited torequiredLocales(or all locales ifrequiredLocalesis not set).
Testing localized UI (React / Next.js)
Render components under an Intlayer provider and assert on visible content.
React example (Testing Library):
העתקת הקוד ללוח
Next.js (App Router) example: use the framework wrapper:
העתקת הקוד ללוח
Tips:
- When you need raw string values for attributes (e.g.,
aria-label), access the.valuefield returned byuseIntlayerin React. - Keep dictionaries colocated with components for easier unit testing and cleanup.
Continuous Integration
Run the CLI audit in CI. It fails the job when required translations are missing.
package.json:
העתקת הקוד ללוח
Alternative: Vitest
העתקת הקוד ללוח
GitHub Actions example:
העתקת הקוד ללוח
Optional: run the CLI audit for a human-readable summary alongside tests:
העתקת הקוד ללוח
Troubleshooting
- Ensure your Intlayer configuration defines
localesand (optionally)requiredLocales. - If your app uses dynamic or remote dictionaries, run tests in an environment where the dictionaries are available.
- For mixed monorepos, use
--base-dirto point the CLI at the correct application root.
