svelte-django-gettext 1.0.0 → 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 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>`. If this is not the case, all functions will just return their message id.
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 rollup plugin extracts all `gettext()` calls and outputs `_svelte_django_extracted_messages.js`, containh contains `gettext` calls extracted from your `.svelte` files.
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 is readable by django's [`magemessages` management command](https://docs.djangoproject.com/en/stable/ref/django-admin/#django-admin-makemessages).
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
- export * from './build';
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.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": "jest 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
- "author": "Jan Pieter Waagmeester",
18
- "license": "ISC",
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
- "jest": "^27.3.1"
26
+ "jsdom": "^23.2.0",
27
+ "vitest": "^1.2.1"
24
28
  },
25
29
  "jest": {
26
30
  "testEnvironment": "jsdom"
package/vite.config.js ADDED
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from 'vite';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'jsdom',
7
+ }
8
+ });
package/.babelrc DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "@babel/preset-env",
5
- {
6
- "useBuiltIns": "entry",
7
- "corejs": {"version": "3"}
8
- }
9
- ]
10
- ]
11
- }
@@ -1,15 +0,0 @@
1
- name: CI
2
- on: [push]
3
- jobs:
4
- eslint:
5
- runs-on: ubuntu-latest
6
- steps:
7
- - uses: actions/checkout@v2.4.0
8
- - run: npm install
9
- - run: npm run eslint
10
- tests:
11
- runs-on: ubuntu-latest
12
- steps:
13
- - uses: actions/checkout@v2.4.0
14
- - run: npm install
15
- - run: npm run test
@@ -1,65 +0,0 @@
1
- /* globals describe, expect, test */
2
- import { gettext, ngettext, npgettext, pgettext } from '../index.js';
3
-
4
-
5
- describe('gettext', function() {
6
- test('Is identity function if django is not defined', function() {
7
- window.django = undefined;
8
- expect(gettext('house')).toBe('house');
9
- expect(gettext('house', true)).toBe('House');
10
- });
11
-
12
- test('Proxies to django.gettext', function() {
13
- window.django = {
14
- gettext: function() {
15
- return 'huis';
16
- }
17
- };
18
- expect(gettext('house')).toBe('huis');
19
- expect(gettext('house', true)).toBe('Huis');
20
- });
21
- });
22
-
23
- describe('ngettext', function() {
24
- test('Is identity function if django is not defined', function() {
25
- window.django = undefined;
26
- expect(ngettext('house', 'houses', 1)).toBe('house');
27
- expect(ngettext('house', 'houses', 2)).toBe('houses');
28
- expect(ngettext('house', 'houses', 1, true)).toBe('House');
29
- expect(ngettext('house', 'houses', 2, true)).toBe('Houses');
30
- });
31
- test('Proxies to django.ngettext', function() {
32
- window.django = {
33
- ngettext: function(singular, plural, count) {
34
- return count == 1 ? 'huis' : 'huizen';
35
- }
36
- };
37
- expect(ngettext('house', 'houses', 1)).toBe('huis');
38
- expect(ngettext('house', 'houses', 2)).toBe('huizen');
39
- });
40
- });
41
-
42
- describe('npgettext', function() {
43
- test('Is identity function if django is not defined', function() {
44
- window.django = undefined;
45
- expect(npgettext('search results', '1 result', '%d results', 1)).toBe('1 result');
46
- });
47
- });
48
-
49
-
50
- describe('pgettext', function() {
51
- test('Is identity function if django is not defined', function() {
52
- window.django = undefined;
53
- expect(pgettext('date', 'may')).toBe('may');
54
- expect(pgettext('date', 'may', true)).toBe('May');
55
- });
56
- test('Proxies to django.pgettext', function() {
57
- window.django = {
58
- pgettext: function() {
59
- return 'mei'
60
- }
61
- };
62
- expect(pgettext('date', 'may')).toBe('mei');
63
- expect(pgettext('date', 'may', true)).toBe('Mei');
64
- });
65
- });