express-translify
Version:
A drop-in translation module for real-world Express applications
99 lines (70 loc) âĒ 1.95 kB
Markdown
# ð 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. ðâĻ