# svelte-django-gettext

> Use django gettext in Svelte

Latest version **1.1.0** (published 2026-09-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install svelte-django-gettext
pnpm add svelte-django-gettext
yarn add svelte-django-gettext
bun add svelte-django-gettext
```

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2026-09-19 |
| First published | 2021-11-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jan Pieter Waagmeester |
| Maintainers | jieter |
| Keywords | Svelte, django, gettext, i18n |

## Links

- npm: https://www.npmjs.com/package/svelte-django-gettext
- npm.io page: https://npm.io/package/svelte-django-gettext

## Recent versions

- 1.1.0 (latest) — 2026-09-19
- 1.0.3 — 2024-01-19
- 1.0.2 — 2024-01-19
- 1.0.1 — 2021-12-17
- 1.0.0 — 2021-11-22
- 0.0.1 — 2021-11-19

## README

# Use django's `gettext` in Svelte

Wrapper around django's JavaScript i18n features in Svelte.

Django docs: [Using the JavaScript translation catalog](https://docs.djangoproject.com/en/stable/topics/i18n/translation/#using-the-javascript-translation-catalog)

In your rollup configuration:
```JavaScript
import svelte from 'rollup-plugin-svelte';
import { writeGettextExtracts, gettextStringExtractor } from 'svelte-django-gettext/build';

export default {
    input: 'app.js',
    output: {...},
    plugins: [
        svelte({
            preprocessors: {
                markup: gettextStringExtractor
            }
        }),
        writeGettextExtracts('js/_svelte_django_extracted_messages.js'),
    ]
}
```

Or with vite:

```JavaScript
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';

import { gettextStringExtractor, writeGettextExtracts } from 'svelte-django-gettext/build';

export default defineConfig({
    base: '',
    plugins: [
        svelte({
            preprocess: {
                markup: gettextStringExtractor
            },
        }),
        writeGettextExtracts('js/_svelte_django_extracted_messages.js'),
    ],
});
```


In your application:

```Svelte
<script>
import gettext from 'svelte-django-gettext';

</script>

<h1>{gettext('hello')}</h1>
```

Make sure the page loads the generated catalog, from a django template: `<script src="{% url 'javascript-catalog' %}"></script>`.
If this is not the case, all functions will just return their message id.

# How it works:

Django's `./manage.py makemessages` cannot parse `.svelte` files to extract `gettext()` calls.
A preprocessor extracts `gettext()` calls and outputs `_svelte_django_extracted_messages.js`, which then contains `gettext` calls extracted from your `.svelte` files.

This file should be added to `.gitignore`, but Django's [`makemessages` management command](https://docs.djangoproject.com/en/stable/ref/django-admin/#django-admin-makemessages) can read translations strings from it.

---
_Source: https://npm.io/package/svelte-django-gettext · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
