UNPKG

nuxt-i18n-micro

Version:

Nuxt I18n Micro is a lightweight, high-performance internationalization module for Nuxt, designed to handle multi-language support with minimal overhead, fast build times, and efficient runtime performance.

116 lines (78 loc) 5.29 kB
[![npm version](https://img.shields.io/npm/v/nuxt-i18n-micro/latest?style=for-the-badge)](https://www.npmjs.com/package/nuxt-i18n-micro) [![npm downloads](https://img.shields.io/npm/dw/nuxt-i18n-micro?style=for-the-badge)](https://www.npmjs.com/package/nuxt-i18n-micro) [![License](https://img.shields.io/npm/l/nuxt-i18n-micro?style=for-the-badge)](https://www.npmjs.com/package/nuxt-i18n-micro) [![Donate](https://img.shields.io/badge/Donate-Donationalerts-ff4081?style=for-the-badge)](https://www.donationalerts.com/r/s00d88) <p align="center"> <img src="https://github.com/s00d/nuxt-i18n-micro/blob/main/logo.png?raw=true" alt="logo"> </p> # Nuxt I18n Micro `Nuxt I18n Micro` is a fast, simple, and lightweight internationalization (i18n) module for Nuxt. Despite its compact size, it's designed with large projects in mind, offering significant performance improvements over traditional i18n solutions like `nuxt-i18n`. The module was built from the ground up to be highly efficient, focusing on minimizing build times, reducing server load, and shrinking bundle sizes. ## Why Nuxt I18n Micro? The `Nuxt I18n Micro` module was created to address critical performance issues found in the original `nuxt-i18n` module, particularly in high-traffic environments and projects with large translation files. Key issues with `nuxt-i18n` include: - **High Memory Consumption**: Consumes significant memory during both build and runtime, leading to performance bottlenecks. - **Slow Performance**: Especially with large translation files, it causes noticeable slowdowns in build times and server response. - **Large Bundle Size**: Generates a large bundle, negatively impacting application performance. - **Memory Leaks and Bugs**: Known for memory leaks and unpredictable behavior under heavy load. ### Performance Comparison To showcase the efficiency of `Nuxt I18n Micro`, we conducted tests under identical conditions. Both modules were tested with a 10MB translation file on the same hardware. #### Build Time and Resource Consumption Исправленные значения для сравнения: **Nuxt I18n v9**: - **Total size (build)**: 13.7 MB (2.2 MB gzip) - **Max CPU Usage**: 248.50% - **Max Memory Usage**: 3057.23 MB - **Elapsed Time**: 0h 0m 12s **Nuxt I18n Micro**: - **Total size (build)**: 229 KB (152 KB gzip) — **13.47 MB or 98.36% smaller (2.05 MB or 93.10% smaller gzip)** - **Max CPU Usage**: 195.00% — **21.53% lower** - **Max Memory Usage**: 1140.63 MB — **-1916.6 MB less memory** - **Elapsed Time**: 0h 0m 7s — **-5 seconds faster** #### Server Performance (10k Requests) **Nuxt I18n v9**: - **Requests per second**: 34 [#/sec] (mean) - **Time per request**: 1487.60 ms (mean) - **Max Memory Usage**: 9958.67 MB **Nuxt I18n Micro**: - **Requests per second**: 339 [#/sec] (mean) — **305 more requests per second (897.06% increase)** - **Time per request**: 5.10 ms (mean) — **-1482.50 ms faster (99.66% reduction)** - **Max Memory Usage**: 405.20 MB — **-9553.47 MB less memory usage (95.93% reduction)** These results clearly demonstrate that `Nuxt I18n Micro` significantly outperforms the original module in every critical area. ## Key Features - 🌐 **Compact Yet Powerful**: Despite its small size, `Nuxt I18n Micro` is designed for large-scale projects, focusing on performance and efficiency. -**Optimized Build and Runtime**: Reduces build times, memory usage, and server load, making it ideal for high-traffic applications. - 🛠 **Minimalist Design**: The module is structured around just 5 components (1 module and 4 plugins), making it easy to understand, extend, and maintain. - 📏 **Efficient Routing**: Generates only 2 routes regardless of the number of locales, thanks to dynamic regex-based routing, unlike other i18n modules that generate separate routes for each locale. - 🗂 **Streamlined Translation Loading**: Only JSON files are supported, with translations split between a global file for common texts (e.g., menus) and page-specific files, which are auto-generated in the `dev` mode if not present. ## Quick Setup Install the module in your Nuxt application with: ```bash npm install nuxt-i18n-micro ``` Then, add it to your `nuxt.config.ts`: ```typescript export default defineNuxtConfig({ modules: [ 'nuxt-i18n-micro', ], i18n: { locales: [ { code: 'en', iso: 'en-US', dir: 'ltr' }, { code: 'fr', iso: 'fr-FR', dir: 'ltr' }, { code: 'ar', iso: 'ar-SA', dir: 'rtl' }, ], defaultLocale: 'en', translationDir: 'locales', meta: true, }, }) ``` That's it! You're now ready to use Nuxt I18n Micro in your Nuxt app. [Docs](https://s00d.github.io/nuxt-i18n-micro/) [Plugin Methods](https://s00d.github.io/nuxt-i18n-micro/api/methods) [Performanc](https://s00d.github.io/nuxt-i18n-micro/guide/performance) [Performance Test Results](https://s00d.github.io/nuxt-i18n-micro/guide/performance-results) [Components](https://s00d.github.io/nuxt-i18n-micro/components/i18n-t) [Layers](https://s00d.github.io/nuxt-i18n-micro/guide/layers) [Seo](https://s00d.github.io/nuxt-i18n-micro/guide/seo) [Migration](https://s00d.github.io/nuxt-i18n-micro/guide/migration) [Contribution](https://s00d.github.io/nuxt-i18n-micro/guide/contribution)