An open API service indexing awesome lists of open source software.

https://github.com/dinoscapeprogramming/express-translify

A drop-in translation module for real-world Express applications
https://github.com/dinoscapeprogramming/express-translify

Last synced: 10 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# 🚀 Express Translify 🚀

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

* 🊄 **Drop-in** *(no refactoring needed)*
* ðŸŠķ **Lightweight** *(< 19 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...",
// ...
]
}
}
```

âœĻ Or, if you prefer, you can simply provide a path to an external config file like `"translify.json"` to keep things neat and separate:

```json
{
"translify": "translify.json"
}
```

This way, you get all the flexibility without cluttering your `package.json`! 🎉

### ✍ïļ 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

```

> **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. 🌍âœĻ