vite-plugin-drupal-t 1.0.3 → 1.0.5
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/dist/index.d.ts +1 -1
- package/dist/index.js +15 -1
- package/package.json +3 -2
- package/src/index.test.ts +5 -7
- package/src/index.ts +16 -2
- package/src/drupal.d.ts +0 -41
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,6 +4,20 @@ export default function extractDrupalT(options = {}) {
|
|
|
4
4
|
const translations = new Set();
|
|
5
5
|
return {
|
|
6
6
|
name: 'extract-drupal-t',
|
|
7
|
+
config() {
|
|
8
|
+
return {
|
|
9
|
+
build: {
|
|
10
|
+
rollupOptions: {
|
|
11
|
+
external: ['Drupal'],
|
|
12
|
+
output: {
|
|
13
|
+
globals: {
|
|
14
|
+
Drupal: 'Drupal',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
},
|
|
7
21
|
transform(code, id) {
|
|
8
22
|
if (!filter(id))
|
|
9
23
|
return null;
|
|
@@ -30,7 +44,7 @@ export default function extractDrupalT(options = {}) {
|
|
|
30
44
|
// Format each translation as a comment.
|
|
31
45
|
// Replace '(Drupal)' with 'Drupal' for consistency.
|
|
32
46
|
// Drupal can find the translations it needs to include.
|
|
33
|
-
.map((translation) =>
|
|
47
|
+
.map((translation) => translation.replace('(Drupal)', 'Drupal').split('\n').map(line => `// ${line}`).join('\n'))
|
|
34
48
|
.join('\n');
|
|
35
49
|
this.emitFile({
|
|
36
50
|
type: 'asset',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-drupal-t",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A Vite plugin that automatically extracts Drupal.t() and Drupal.formatPlural() translation calls for seamless internationalization",
|
|
5
5
|
"author": "Märt Rang <rang501@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"formatPlural"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@rollup/pluginutils": "^4.2.1"
|
|
43
|
+
"@rollup/pluginutils": "^4.2.1",
|
|
44
|
+
"ts-for-drupal-core": "^0.0.7"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@types/estree": "^1.0.7",
|
package/src/index.test.ts
CHANGED
|
@@ -161,7 +161,7 @@ multiline string\`);`;
|
|
|
161
161
|
const output = generateOutput(plugin);
|
|
162
162
|
|
|
163
163
|
expect(output).toContain('// Drupal.t(`This is a');
|
|
164
|
-
expect(output).toContain('multiline string`)');
|
|
164
|
+
expect(output).toContain('// multiline string`)');
|
|
165
165
|
});
|
|
166
166
|
|
|
167
167
|
it('should extract single-line template literals', () => {
|
|
@@ -193,7 +193,7 @@ Line 2\`, {});`;
|
|
|
193
193
|
const output = generateOutput(plugin);
|
|
194
194
|
|
|
195
195
|
expect(output).toContain('// Drupal.t(`Line 1');
|
|
196
|
-
expect(output).toContain('Line 2`, {})');
|
|
196
|
+
expect(output).toContain('// Line 2`, {})');
|
|
197
197
|
});
|
|
198
198
|
|
|
199
199
|
it('should extract multiline formatPlural strings', () => {
|
|
@@ -205,11 +205,9 @@ items\`, {});`;
|
|
|
205
205
|
callTransform(plugin, code, id);
|
|
206
206
|
const output = generateOutput(plugin);
|
|
207
207
|
|
|
208
|
-
expect(output).toContain('// Drupal.formatPlural(5,');
|
|
209
|
-
expect(output).toContain('`
|
|
210
|
-
expect(output).toContain('
|
|
211
|
-
expect(output).toContain('`Many');
|
|
212
|
-
expect(output).toContain('items`, {})');
|
|
208
|
+
expect(output).toContain('// Drupal.formatPlural(5, `One');
|
|
209
|
+
expect(output).toContain('// item`, `Many');
|
|
210
|
+
expect(output).toContain('// items`, {})');
|
|
213
211
|
});
|
|
214
212
|
});
|
|
215
213
|
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createFilter } from '@rollup/pluginutils';
|
|
2
|
-
import type { Plugin } from '
|
|
2
|
+
import type { Plugin } from 'vite';
|
|
3
3
|
|
|
4
4
|
export interface ExtractDrupalTOptions {
|
|
5
5
|
include?: string | string[];
|
|
@@ -12,6 +12,20 @@ export default function extractDrupalT(options: ExtractDrupalTOptions = {}): Plu
|
|
|
12
12
|
|
|
13
13
|
return {
|
|
14
14
|
name: 'extract-drupal-t',
|
|
15
|
+
config() {
|
|
16
|
+
return {
|
|
17
|
+
build: {
|
|
18
|
+
rollupOptions: {
|
|
19
|
+
external: ['Drupal'],
|
|
20
|
+
output: {
|
|
21
|
+
globals: {
|
|
22
|
+
Drupal: 'Drupal',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
},
|
|
15
29
|
transform(code: string, id: string) {
|
|
16
30
|
if (!filter(id)) return null;
|
|
17
31
|
|
|
@@ -42,7 +56,7 @@ export default function extractDrupalT(options: ExtractDrupalTOptions = {}): Plu
|
|
|
42
56
|
// Format each translation as a comment.
|
|
43
57
|
// Replace '(Drupal)' with 'Drupal' for consistency.
|
|
44
58
|
// Drupal can find the translations it needs to include.
|
|
45
|
-
.map((translation) =>
|
|
59
|
+
.map((translation) => translation.replace('(Drupal)', 'Drupal').split('\n').map(line => `// ${line}`).join('\n'))
|
|
46
60
|
.join('\n');
|
|
47
61
|
|
|
48
62
|
this.emitFile({
|
package/src/drupal.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
declare namespace Drupal {
|
|
2
|
-
/**
|
|
3
|
-
* Translates a string to the current language.
|
|
4
|
-
*
|
|
5
|
-
* @param str
|
|
6
|
-
* A string containing the English text to translate.
|
|
7
|
-
* @param args
|
|
8
|
-
* An object of replacements pairs to make after translation. Incidences
|
|
9
|
-
* of any key in this array are replaced with the corresponding value.
|
|
10
|
-
* @param options
|
|
11
|
-
* Additional options for translation.
|
|
12
|
-
* @returns
|
|
13
|
-
* The translated string.
|
|
14
|
-
*/
|
|
15
|
-
function t(str: string, args?: Record<string, string>, options?: { context?: string }): string;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Translates a string to the current language and formats it as a plural.
|
|
19
|
-
*
|
|
20
|
-
* @param count
|
|
21
|
-
* The number to determine the plural form.
|
|
22
|
-
* @param singular
|
|
23
|
-
* The singular form of the string.
|
|
24
|
-
* @param plural
|
|
25
|
-
* The plural form of the string.
|
|
26
|
-
* @param args
|
|
27
|
-
* An object of replacements pairs to make after translation. Incidences
|
|
28
|
-
* of any key in this array are replaced with the corresponding value.
|
|
29
|
-
* @param options
|
|
30
|
-
* Additional options for translation.
|
|
31
|
-
* @returns
|
|
32
|
-
* The translated string in the correct plural form.
|
|
33
|
-
*/
|
|
34
|
-
function formatPlural(
|
|
35
|
-
count: number,
|
|
36
|
-
singular: string,
|
|
37
|
-
plural: string,
|
|
38
|
-
args?: Record<string, string>,
|
|
39
|
-
options?: { context?: string }
|
|
40
|
-
): string;
|
|
41
|
-
}
|