https://github.com/wuespace/honolate
Honolate is a localization library designed specifically for the Hono web framework in Deno. It provides an easy way to manage translations and localize your web applications.
https://github.com/wuespace/honolate
backend deno gettext hono i18n internationalization library localization translation
Last synced: 4 months ago
JSON representation
Honolate is a localization library designed specifically for the Hono web framework in Deno. It provides an easy way to manage translations and localize your web applications.
- Host: GitHub
- URL: https://github.com/wuespace/honolate
- Owner: wuespace
- License: mit
- Created: 2025-11-23T13:58:22.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-11-25T00:23:17.000Z (7 months ago)
- Last Synced: 2026-02-17T08:19:38.182Z (4 months ago)
- Topics: backend, deno, gettext, hono, i18n, internationalization, library, localization, translation
- Language: TypeScript
- Homepage: https://jsr.io/@wuespace/honolate/doc
- Size: 86.9 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Honolate – Localization for Hono in Deno
[](https://jsr.io/@wuespace)
[](https://jsr.io/@wuespace/honolate)
[](https://jsr.io/@wuespace/honolate)
[](https://github.com/wuespace/honolate/actions/workflows/publish-jsr.yml)
Honolate is a localization library designed specifically for the Hono web
framework in Deno. It provides an easy way to manage translations and localize
your web applications.
## Getting Started
Install Honolate via Deno:
```bash
deno add jsr:@wuespace/honolate
```
Create an `i18n.ts` file to configure your localization settings:
```typescript
#!/usr/bin/env -S deno run --allow-read --allow-write=./locales/ --allow-env
import { initHonolate, InitHonolateOptions, runCLI } from "@wuespace/honolate";
const config = {
defaultLanguage: "en",
languages: {
en: import.meta.resolve("./locales/en.json"),
de: import.meta.resolve("./locales/de.json"),
},
} satisfies InitHonolateOptions;
// CLI
import.meta.main && await runCLI(config, import.meta.dirname ?? Deno.cwd());
// Middleware for Hono
export const i18n = await initHonolate(config);
```
Run the script to initialize your localization files:
```bash
./i18n.ts
```
This will create a `locales` directory with `en.json` and `de.json` files. When
added terms in your code, you can re-run the script to update the localization
files.
## Usage
### Using Honolate Middleware in Hono
Import the `i18n` middleware and use it in your Hono application:
```typescript
import { Hono } from "@hono/hono";
import { jsxRenderer } from "@hono/hono/jsx-renderer";
import { i18n } from "./i18n.ts";
const app = new Hono()
.use(jsxRenderer(), i18n)
.get("/", (c) => {
// [...]
});
Deno.serve(app);
```
### Eager strings
You can use eager strings for immediate translation:
```typescript
import { t } from "@wuespace/honolate";
c.render(
{t`Hello world!`}
{t`We can also use variables like ${new Date()}.`}
,
);
```
### Lazy strings
Sometimes, you need to define strings outside of a component context. In this
case, you can use lazy strings:
```typescript
import { lt } from "@wuespace/honolate";
export const greeting = lt`Hello world!`;
```
Later, inside a component, you can resolve the lazy string using the `t`
function:
```typescript
import { t } from "@wuespace/honolate";
import { greeting } from "./greeting.ts";
c.render(
{t(greeting)}
,
);
```
### Updating localization files
Whenever you add new terms to your code, you can update the localization files
by re-running the `i18n.ts` script:
```bash
./i18n.ts
```
This will scan your code for new terms and add them to the respective locale
files.
Note that the middleware automatically loads the localization files on startup,
so you can just edit the JSON files, restart your application, and see the
changes immediately.
## About the name
The name "Honolate" is a combination of "Hono" and "translate", reflecting its
purpose as a localization library for the Hono framework. It also is a play on
the fact that lazy strings are only translated when needed (late), allowing for
a more powerful and flexible localization approach.