UNPKG

express-translify

Version:

A drop-in translation module for real-world Express applications

99 lines (70 loc) â€Ē 1.95 kB
# 🚀 Express Translify 🚀 A drop-in translation module for real-world Express applications 🌍 * 🊄 **Drop-in** *(no refactoring needed)* * ðŸŠķ **Lightweight** *(18 KB)* * ⚡ **Fast** *(smart client-side caching)* --- ## 1. ðŸ“Ķ Installation ```sh $ npm install express-translify ``` ## 2. 🌐 Specify Your Languages & Terms to Translate * 📝 Head into your `package.json` * ➕ Add your Translify options: ```js { // ... "translify": { "default": "en", // default value is "en" "languages": [ "de", // ðŸ‡Đ🇊 "es", // 🇊ðŸ‡ļ "zh", // ðŸ‡ĻðŸ‡ģ // ... ], "terms": [ "Welcome!", "Lorem ipsum...", // ... ] } } ``` ### ✍ïļ Placeholders in Terms Use `[...]` to mark dynamic parts in your terms: ```json "terms": [ "Hello, [...]!", "You have [...] new messages" ] ``` > `[...]` means "leave this part out" - it won't be translated. ## 3. 🛠ïļ Generate Your Locales ```sh $ npx translate ``` Need a custom output path? Use the `--out` option ðŸ›Ģïļ: ```sh $ npx translate --out custom-path ``` ## 4. ðŸ§Đ Use Our Express Middleware ```js const translify = require("express-translify"); app.use(translify()); ``` Using a custom locales path? Pass it in with the `path` option 🗂ïļ: ```js app.use(translify({ path: "custom-path" })); ``` ## 5. ðŸ“Ĩ Import Translify Into Your Website ```html <!-- Our middleware automatically serves all necessary assets --> <script src="/translify.js"></script> ``` > **Note:** If a term matches the page title, `document.title` is translated too. ## 6. 🧭 Switching Languages at Runtime ```js translify("de"); // ðŸ‡Đ🇊 Switches to German ``` ## 7. 🎉 Enjoy Translations in Your App That's it! Your Express app now speaks multiple languages - no refactoring, no stress. 🌍âœĻ