svelte-django-gettext 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -7
- package/index.js +1 -3
- package/package.json +10 -6
- package/vite.config.js +8 -0
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@ Wrapper around django's JavaScript i18n features in Svelte.
|
|
|
5
5
|
Django docs: [Using the JavaScript translation catalog](https://docs.djangoproject.com/en/stable/topics/i18n/translation/#using-the-javascript-translation-catalog)
|
|
6
6
|
|
|
7
7
|
In your rollup configuration:
|
|
8
|
-
```
|
|
8
|
+
```JavaScript
|
|
9
9
|
import svelte from 'rollup-plugin-svelte';
|
|
10
|
-
import { writeGettextExtracts, gettextStringExtractor } from 'svelte-django-gettext';
|
|
10
|
+
import { writeGettextExtracts, gettextStringExtractor } from 'svelte-django-gettext/build';
|
|
11
11
|
|
|
12
12
|
export default {
|
|
13
13
|
input: 'app.js',
|
|
@@ -18,13 +18,32 @@ export default {
|
|
|
18
18
|
markup: gettextStringExtractor
|
|
19
19
|
}
|
|
20
20
|
}),
|
|
21
|
-
...
|
|
22
|
-
|
|
23
21
|
writeGettextExtracts('js/_svelte_django_extracted_messages.js'),
|
|
24
22
|
]
|
|
25
23
|
}
|
|
26
24
|
```
|
|
27
25
|
|
|
26
|
+
Or with vite:
|
|
27
|
+
|
|
28
|
+
```JavaScript
|
|
29
|
+
import { defineConfig } from 'vite';
|
|
30
|
+
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
31
|
+
|
|
32
|
+
import { gettextStringExtractor, writeGettextExtracts } from 'svelte-django-gettext/build';
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
base: '',
|
|
36
|
+
plugins: [
|
|
37
|
+
svelte({
|
|
38
|
+
preprocess: {
|
|
39
|
+
markup: gettextStringExtractor
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
writeGettextExtracts('js/_svelte_django_extracted_messages.js'),
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
28
47
|
|
|
29
48
|
In your application:
|
|
30
49
|
|
|
@@ -37,11 +56,12 @@ import gettext from 'svelte-django-gettext';
|
|
|
37
56
|
<h1>{gettext('hello')}</h1>
|
|
38
57
|
```
|
|
39
58
|
|
|
40
|
-
Make sure the page loads the generated catalog, from a django template: `<script src="{% url 'javascript-catalog' %}"></script>`.
|
|
59
|
+
Make sure the page loads the generated catalog, from a django template: `<script src="{% url 'javascript-catalog' %}"></script>`.
|
|
60
|
+
If this is not the case, all functions will just return their message id.
|
|
41
61
|
|
|
42
62
|
# How it works:
|
|
43
63
|
|
|
44
64
|
Django's `./manage.py makemessages` cannot parse `.svelte` files to extract `gettext()` calls.
|
|
45
|
-
A
|
|
65
|
+
A preprocessor extracts `gettext()` calls and outputs `_svelte_django_extracted_messages.js`, which then contains `gettext` calls extracted from your `.svelte` files.
|
|
46
66
|
|
|
47
|
-
This file should be added to `.gitignore`, but
|
|
67
|
+
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.
|
package/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/* Proxy to globally defined django.*gettext functions if it is available.
|
|
1
|
+
/* Proxies to globally defined django.*gettext functions if it is available.
|
|
4
2
|
*/
|
|
5
3
|
function capfirst(str, condition) {
|
|
6
4
|
return condition ? (str.charAt(0).toUpperCase() + str.slice(1)) : str;
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-django-gettext",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Use django gettext in Svelte",
|
|
5
|
+
"author": "Jan Pieter Waagmeester",
|
|
6
|
+
"license": "ISC",
|
|
5
7
|
"main": "index.js",
|
|
6
8
|
"type": "module",
|
|
7
9
|
"scripts": {
|
|
8
|
-
"test": "
|
|
10
|
+
"test": "vitest",
|
|
9
11
|
"eslint": "eslint -c package.json --fix *.js test/"
|
|
10
12
|
},
|
|
11
13
|
"keywords": [
|
|
@@ -14,13 +16,15 @@
|
|
|
14
16
|
"gettext",
|
|
15
17
|
"i18n"
|
|
16
18
|
],
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./index.js",
|
|
21
|
+
"./build": "./build.js"
|
|
22
|
+
},
|
|
19
23
|
"devDependencies": {
|
|
20
|
-
"@babel/preset-env": "^7.16.0",
|
|
21
24
|
"eslint": "^8.3.0",
|
|
22
25
|
"eslint-plugin-import": "^2.25.3",
|
|
23
|
-
"
|
|
26
|
+
"jsdom": "^23.2.0",
|
|
27
|
+
"vitest": "^1.2.1"
|
|
24
28
|
},
|
|
25
29
|
"jest": {
|
|
26
30
|
"testEnvironment": "jsdom"
|