material-icon-theme 4.22.0 → 4.23.1
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/.eslintrc.json +51 -51
- package/.github/workflows/build.yml +45 -45
- package/.github/workflows/color-check.yml +22 -22
- package/.github/workflows/release.yml +73 -73
- package/.vscodeignore +21 -21
- package/CHANGELOG.md +1292 -1267
- package/README.md +199 -199
- package/icons/craco.svg +45 -0
- package/icons/folder-changesets-open.svg +5 -0
- package/icons/folder-changesets.svg +2 -0
- package/icons/folder-decorators-open.svg +2 -2
- package/icons/folder-decorators.svg +5 -5
- package/icons/folder-supabase-open.svg +5 -5
- package/icons/folder-supabase.svg +2 -2
- package/icons/sonarcloud.svg +4 -4
- package/icons/stylable.svg +10 -10
- package/icons/supabase.svg +4 -4
- package/icons/vitest.svg +6 -0
- package/images/contributors.png +0 -0
- package/images/fileIcons.png +0 -0
- package/images/folderIcons.png +0 -0
- package/package.json +252 -252
- package/package.nls.de.json +32 -32
- package/package.nls.es.json +29 -29
- package/package.nls.fr.json +29 -29
- package/package.nls.ja.json +32 -32
- package/package.nls.json +32 -32
- package/package.nls.nl.json +32 -32
- package/package.nls.pl.json +32 -32
- package/package.nls.pt-BR.json +29 -29
- package/package.nls.pt-PT.json +29 -29
- package/package.nls.ru.json +29 -29
- package/package.nls.zh-CN.json +29 -29
- package/package.nls.zh-TW.json +29 -29
- package/src/commands/activate.ts +28 -28
- package/src/commands/explorerArrows.ts +55 -55
- package/src/commands/folderColor.ts +96 -96
- package/src/commands/folders.ts +55 -55
- package/src/commands/grayscale.ts +55 -55
- package/src/commands/iconPacks.ts +64 -64
- package/src/commands/index.ts +30 -30
- package/src/commands/opacity.ts +46 -46
- package/src/commands/saturation.ts +46 -46
- package/src/extension.ts +37 -37
- package/src/helpers/customIcons.ts +8 -8
- package/src/helpers/index.ts +88 -88
- package/src/i18n/index.ts +78 -78
- package/src/i18n/lang-de.ts +43 -43
- package/src/i18n/lang-en.ts +43 -43
- package/src/i18n/lang-es.ts +43 -43
- package/src/i18n/lang-fr.ts +43 -43
- package/src/i18n/lang-ja.ts +43 -43
- package/src/i18n/lang-nl.ts +43 -43
- package/src/i18n/lang-pl.ts +43 -43
- package/src/i18n/lang-pt-br.ts +43 -43
- package/src/i18n/lang-pt-pt.ts +43 -43
- package/src/i18n/lang-ru.ts +43 -43
- package/src/i18n/lang-uk.ts +43 -43
- package/src/i18n/lang-zh-cn.ts +43 -43
- package/src/i18n/lang-zh-tw.ts +43 -43
- package/src/icons/fileIcons.ts +2197 -2159
- package/src/icons/folderIcons.ts +806 -804
- package/src/icons/generator/folderGenerator.ts +340 -340
- package/src/icons/generator/iconOpacity.ts +111 -111
- package/src/icons/generator/iconSaturation.ts +140 -140
- package/src/icons/generator/jsonGenerator.ts +191 -191
- package/src/icons/languageIcons.ts +141 -141
- package/src/models/i18n/translation.ts +41 -41
- package/src/models/iconConfiguration.ts +37 -37
- package/src/models/icons/iconJsonOptions.ts +21 -21
- package/src/models/index.ts +3 -3
- package/src/scripts/contributors/index.ts +138 -138
- package/src/scripts/helpers/screenshots.ts +32 -32
- package/src/scripts/icons/checks/checkIconAvailability.ts +215 -215
- package/src/scripts/icons/checks/checkIconConflicts.ts +152 -152
- package/src/scripts/icons/checks/checkIconUsage.ts +137 -137
- package/src/scripts/icons/checks/index.ts +7 -7
- package/src/scripts/preview/index.ts +40 -40
- package/src/scripts/preview/preview.ts +163 -163
- package/src/test/runTest.ts +26 -26
- package/src/test/spec/i18n/i18n.spec.ts +54 -54
- package/src/test/spec/icons/fileIcons.spec.ts +250 -250
- package/src/test/spec/icons/folderIcons.spec.ts +418 -418
- package/src/test/spec/icons/languageIcons.spec.ts +184 -184
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
import { writeFileSync } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { green, red } from '../helpers/painter';
|
|
4
|
-
import { createScreenshot } from '../helpers/screenshots';
|
|
5
|
-
import { toTitleCase } from './../helpers/titleCase';
|
|
6
|
-
|
|
7
|
-
const htmlDoctype = '<!DOCTYPE html>';
|
|
8
|
-
const cssFilePath = 'style.css';
|
|
9
|
-
const styling = `<link rel="stylesheet" href="${cssFilePath}">`;
|
|
10
|
-
|
|
11
|
-
const createHTMLTableHeadRow = (amount: number) => {
|
|
12
|
-
const pair = `
|
|
13
|
-
<th class="icon">Icon</th>
|
|
14
|
-
<th class="iconName">Name</th>
|
|
15
|
-
`;
|
|
16
|
-
const columns = [...Array(amount)].map(() => pair).join('');
|
|
17
|
-
return `
|
|
18
|
-
<tr>
|
|
19
|
-
${columns}
|
|
20
|
-
</tr>
|
|
21
|
-
`;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const createHTMLTableBodyRows = (items: IconDefinition[][]) => {
|
|
25
|
-
let rows = '';
|
|
26
|
-
items.forEach((row) => {
|
|
27
|
-
const columns = row
|
|
28
|
-
.map(
|
|
29
|
-
(icon) => `
|
|
30
|
-
<td class="icon">
|
|
31
|
-
<img src="./../../../icons/${icon.iconName}.svg" alt="${
|
|
32
|
-
icon.label
|
|
33
|
-
}">
|
|
34
|
-
</td>
|
|
35
|
-
<td class="iconName">${toTitleCase(icon.label)}</td>
|
|
36
|
-
`
|
|
37
|
-
)
|
|
38
|
-
.join('');
|
|
39
|
-
const tableRow = `
|
|
40
|
-
<tr>
|
|
41
|
-
${columns}
|
|
42
|
-
</tr>
|
|
43
|
-
`;
|
|
44
|
-
rows = rows + tableRow;
|
|
45
|
-
});
|
|
46
|
-
return rows;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const createHTMLTable = (headRow: string, bodyRows: string) => `
|
|
50
|
-
<table>
|
|
51
|
-
${headRow}
|
|
52
|
-
${bodyRows}
|
|
53
|
-
</table>
|
|
54
|
-
`;
|
|
55
|
-
|
|
56
|
-
const createPreviewTable = (icons: IconDefinition[][], size: number) => {
|
|
57
|
-
const table =
|
|
58
|
-
htmlDoctype +
|
|
59
|
-
styling +
|
|
60
|
-
createHTMLTable(
|
|
61
|
-
createHTMLTableHeadRow(size),
|
|
62
|
-
createHTMLTableBodyRows(icons)
|
|
63
|
-
);
|
|
64
|
-
return table;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const savePreview = (
|
|
68
|
-
fileName: string,
|
|
69
|
-
size: number,
|
|
70
|
-
icons: IconDefinition[][]
|
|
71
|
-
) => {
|
|
72
|
-
const filePath = join(__dirname, fileName + '.html');
|
|
73
|
-
|
|
74
|
-
// write the html file with the icon table
|
|
75
|
-
writeFileSync(filePath, createPreviewTable(icons, size));
|
|
76
|
-
|
|
77
|
-
// create the image
|
|
78
|
-
createScreenshot(filePath, fileName)
|
|
79
|
-
.then(() => {
|
|
80
|
-
console.log(
|
|
81
|
-
'> Material Icon Theme:',
|
|
82
|
-
green(`Successfully created ${fileName} preview image!`)
|
|
83
|
-
);
|
|
84
|
-
})
|
|
85
|
-
.catch(() => {
|
|
86
|
-
throw Error(red(`Error while creating ${fileName} preview image`));
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const getIconDefinitionsMatrix = (
|
|
91
|
-
icons: IconDefinition[],
|
|
92
|
-
size: number,
|
|
93
|
-
excluded: string[] = []
|
|
94
|
-
): IconDefinition[][] => {
|
|
95
|
-
const iconList = icons.sort((a, b) => a.label.localeCompare(b.label));
|
|
96
|
-
trimIconListToSize(iconList, size, excluded);
|
|
97
|
-
|
|
98
|
-
// list for the columns with the icons
|
|
99
|
-
const matrix: IconDefinition[][] = [];
|
|
100
|
-
|
|
101
|
-
// calculate the amount of icons per column
|
|
102
|
-
const itemsPerColumn = Math.floor(iconList.length / size);
|
|
103
|
-
|
|
104
|
-
// create the columns with the icons
|
|
105
|
-
let counter = 0;
|
|
106
|
-
for (let c = 0; c < itemsPerColumn; c++) {
|
|
107
|
-
matrix[c] = [];
|
|
108
|
-
}
|
|
109
|
-
for (let s = 0; s < size; s++) {
|
|
110
|
-
for (let i = 0; i < itemsPerColumn; i++) {
|
|
111
|
-
matrix[i][s] = iconList[counter];
|
|
112
|
-
counter++;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return matrix;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Function that generates the preview image for specific icons.
|
|
121
|
-
* @param name name of the preview
|
|
122
|
-
* @param icons icons for the preview
|
|
123
|
-
* @param size amount of table columns
|
|
124
|
-
* @param trimmableIcons List of icons that can possibly be trimmed
|
|
125
|
-
*/
|
|
126
|
-
export const generatePreview = (
|
|
127
|
-
name: string,
|
|
128
|
-
icons: IconDefinition[],
|
|
129
|
-
size: number,
|
|
130
|
-
trimmableIcons: string[] = []
|
|
131
|
-
) => {
|
|
132
|
-
savePreview(
|
|
133
|
-
name,
|
|
134
|
-
size,
|
|
135
|
-
getIconDefinitionsMatrix(icons, size, trimmableIcons)
|
|
136
|
-
);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
interface IconDefinition {
|
|
140
|
-
iconName: string;
|
|
141
|
-
label: string;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Trim the list of icons into the matrix
|
|
146
|
-
* @param iconList List of icons
|
|
147
|
-
* @param size Amount of columns
|
|
148
|
-
* @param trimmableIcons List of icons that can possibly be trimmed
|
|
149
|
-
*/
|
|
150
|
-
const trimIconListToSize = (
|
|
151
|
-
iconList: IconDefinition[],
|
|
152
|
-
size: number,
|
|
153
|
-
trimmableIcons: string[]
|
|
154
|
-
) => {
|
|
155
|
-
while (iconList.length % size !== 0) {
|
|
156
|
-
iconList.splice(
|
|
157
|
-
iconList.findIndex(
|
|
158
|
-
(i) => i.iconName === trimmableIcons[iconList.length % size]
|
|
159
|
-
),
|
|
160
|
-
1
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
1
|
+
import { writeFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { green, red } from '../helpers/painter';
|
|
4
|
+
import { createScreenshot } from '../helpers/screenshots';
|
|
5
|
+
import { toTitleCase } from './../helpers/titleCase';
|
|
6
|
+
|
|
7
|
+
const htmlDoctype = '<!DOCTYPE html>';
|
|
8
|
+
const cssFilePath = 'style.css';
|
|
9
|
+
const styling = `<link rel="stylesheet" href="${cssFilePath}">`;
|
|
10
|
+
|
|
11
|
+
const createHTMLTableHeadRow = (amount: number) => {
|
|
12
|
+
const pair = `
|
|
13
|
+
<th class="icon">Icon</th>
|
|
14
|
+
<th class="iconName">Name</th>
|
|
15
|
+
`;
|
|
16
|
+
const columns = [...Array(amount)].map(() => pair).join('');
|
|
17
|
+
return `
|
|
18
|
+
<tr>
|
|
19
|
+
${columns}
|
|
20
|
+
</tr>
|
|
21
|
+
`;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const createHTMLTableBodyRows = (items: IconDefinition[][]) => {
|
|
25
|
+
let rows = '';
|
|
26
|
+
items.forEach((row) => {
|
|
27
|
+
const columns = row
|
|
28
|
+
.map(
|
|
29
|
+
(icon) => `
|
|
30
|
+
<td class="icon">
|
|
31
|
+
<img src="./../../../icons/${icon.iconName}.svg" alt="${
|
|
32
|
+
icon.label
|
|
33
|
+
}">
|
|
34
|
+
</td>
|
|
35
|
+
<td class="iconName">${toTitleCase(icon.label)}</td>
|
|
36
|
+
`
|
|
37
|
+
)
|
|
38
|
+
.join('');
|
|
39
|
+
const tableRow = `
|
|
40
|
+
<tr>
|
|
41
|
+
${columns}
|
|
42
|
+
</tr>
|
|
43
|
+
`;
|
|
44
|
+
rows = rows + tableRow;
|
|
45
|
+
});
|
|
46
|
+
return rows;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const createHTMLTable = (headRow: string, bodyRows: string) => `
|
|
50
|
+
<table>
|
|
51
|
+
${headRow}
|
|
52
|
+
${bodyRows}
|
|
53
|
+
</table>
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
const createPreviewTable = (icons: IconDefinition[][], size: number) => {
|
|
57
|
+
const table =
|
|
58
|
+
htmlDoctype +
|
|
59
|
+
styling +
|
|
60
|
+
createHTMLTable(
|
|
61
|
+
createHTMLTableHeadRow(size),
|
|
62
|
+
createHTMLTableBodyRows(icons)
|
|
63
|
+
);
|
|
64
|
+
return table;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const savePreview = (
|
|
68
|
+
fileName: string,
|
|
69
|
+
size: number,
|
|
70
|
+
icons: IconDefinition[][]
|
|
71
|
+
) => {
|
|
72
|
+
const filePath = join(__dirname, fileName + '.html');
|
|
73
|
+
|
|
74
|
+
// write the html file with the icon table
|
|
75
|
+
writeFileSync(filePath, createPreviewTable(icons, size));
|
|
76
|
+
|
|
77
|
+
// create the image
|
|
78
|
+
createScreenshot(filePath, fileName)
|
|
79
|
+
.then(() => {
|
|
80
|
+
console.log(
|
|
81
|
+
'> Material Icon Theme:',
|
|
82
|
+
green(`Successfully created ${fileName} preview image!`)
|
|
83
|
+
);
|
|
84
|
+
})
|
|
85
|
+
.catch(() => {
|
|
86
|
+
throw Error(red(`Error while creating ${fileName} preview image`));
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const getIconDefinitionsMatrix = (
|
|
91
|
+
icons: IconDefinition[],
|
|
92
|
+
size: number,
|
|
93
|
+
excluded: string[] = []
|
|
94
|
+
): IconDefinition[][] => {
|
|
95
|
+
const iconList = icons.sort((a, b) => a.label.localeCompare(b.label));
|
|
96
|
+
trimIconListToSize(iconList, size, excluded);
|
|
97
|
+
|
|
98
|
+
// list for the columns with the icons
|
|
99
|
+
const matrix: IconDefinition[][] = [];
|
|
100
|
+
|
|
101
|
+
// calculate the amount of icons per column
|
|
102
|
+
const itemsPerColumn = Math.floor(iconList.length / size);
|
|
103
|
+
|
|
104
|
+
// create the columns with the icons
|
|
105
|
+
let counter = 0;
|
|
106
|
+
for (let c = 0; c < itemsPerColumn; c++) {
|
|
107
|
+
matrix[c] = [];
|
|
108
|
+
}
|
|
109
|
+
for (let s = 0; s < size; s++) {
|
|
110
|
+
for (let i = 0; i < itemsPerColumn; i++) {
|
|
111
|
+
matrix[i][s] = iconList[counter];
|
|
112
|
+
counter++;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return matrix;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Function that generates the preview image for specific icons.
|
|
121
|
+
* @param name name of the preview
|
|
122
|
+
* @param icons icons for the preview
|
|
123
|
+
* @param size amount of table columns
|
|
124
|
+
* @param trimmableIcons List of icons that can possibly be trimmed
|
|
125
|
+
*/
|
|
126
|
+
export const generatePreview = (
|
|
127
|
+
name: string,
|
|
128
|
+
icons: IconDefinition[],
|
|
129
|
+
size: number,
|
|
130
|
+
trimmableIcons: string[] = []
|
|
131
|
+
) => {
|
|
132
|
+
savePreview(
|
|
133
|
+
name,
|
|
134
|
+
size,
|
|
135
|
+
getIconDefinitionsMatrix(icons, size, trimmableIcons)
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
interface IconDefinition {
|
|
140
|
+
iconName: string;
|
|
141
|
+
label: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Trim the list of icons into the matrix
|
|
146
|
+
* @param iconList List of icons
|
|
147
|
+
* @param size Amount of columns
|
|
148
|
+
* @param trimmableIcons List of icons that can possibly be trimmed
|
|
149
|
+
*/
|
|
150
|
+
const trimIconListToSize = (
|
|
151
|
+
iconList: IconDefinition[],
|
|
152
|
+
size: number,
|
|
153
|
+
trimmableIcons: string[]
|
|
154
|
+
) => {
|
|
155
|
+
while (iconList.length % size !== 0) {
|
|
156
|
+
iconList.splice(
|
|
157
|
+
iconList.findIndex(
|
|
158
|
+
(i) => i.iconName === trimmableIcons[iconList.length % size]
|
|
159
|
+
),
|
|
160
|
+
1
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
};
|
package/src/test/runTest.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
2
|
-
import { runTests } from 'vscode-test';
|
|
3
|
-
|
|
4
|
-
const main = async () => {
|
|
5
|
-
try {
|
|
6
|
-
// The folder containing the Extension Manifest package.json
|
|
7
|
-
// Passed to `--extensionDevelopmentPath`
|
|
8
|
-
const extensionDevelopmentPath = resolve(__dirname, '../../');
|
|
9
|
-
|
|
10
|
-
// The path to the extension test script
|
|
11
|
-
// Passed to --extensionTestsPath
|
|
12
|
-
const extensionTestsPath = resolve(__dirname, './spec/index');
|
|
13
|
-
|
|
14
|
-
// Download VS Code, unzip it and run the integration test
|
|
15
|
-
await runTests({
|
|
16
|
-
extensionDevelopmentPath,
|
|
17
|
-
extensionTestsPath,
|
|
18
|
-
launchArgs: ['--disable-gpu', '--disable-workspace-trust'],
|
|
19
|
-
});
|
|
20
|
-
} catch (err) {
|
|
21
|
-
console.error('Failed to run tests');
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
main();
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { runTests } from 'vscode-test';
|
|
3
|
+
|
|
4
|
+
const main = async () => {
|
|
5
|
+
try {
|
|
6
|
+
// The folder containing the Extension Manifest package.json
|
|
7
|
+
// Passed to `--extensionDevelopmentPath`
|
|
8
|
+
const extensionDevelopmentPath = resolve(__dirname, '../../');
|
|
9
|
+
|
|
10
|
+
// The path to the extension test script
|
|
11
|
+
// Passed to --extensionTestsPath
|
|
12
|
+
const extensionTestsPath = resolve(__dirname, './spec/index');
|
|
13
|
+
|
|
14
|
+
// Download VS Code, unzip it and run the integration test
|
|
15
|
+
await runTests({
|
|
16
|
+
extensionDevelopmentPath,
|
|
17
|
+
extensionTestsPath,
|
|
18
|
+
launchArgs: ['--disable-gpu', '--disable-workspace-trust'],
|
|
19
|
+
});
|
|
20
|
+
} catch (err) {
|
|
21
|
+
console.error('Failed to run tests');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
main();
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { equal } from 'assert';
|
|
2
|
-
import { getObjectPropertyValue } from '../../../helpers/objects';
|
|
3
|
-
import { getTranslationValue, initTranslations, replace } from '../../../i18n';
|
|
4
|
-
import { Translation } from '../../../models';
|
|
5
|
-
|
|
6
|
-
describe('i18n', () => {
|
|
7
|
-
it('should initialize translations', () => {
|
|
8
|
-
return initTranslations();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('should translate key', () => {
|
|
12
|
-
equal(
|
|
13
|
-
getTranslationValue('activate', { activate: 'b' } as Translation),
|
|
14
|
-
'b'
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should return undefined if translation is not defined', () => {
|
|
19
|
-
equal(
|
|
20
|
-
getTranslationValue('activate', {} as Translation, {} as Translation),
|
|
21
|
-
undefined
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should use fallback if translation is not defined', () => {
|
|
26
|
-
equal(
|
|
27
|
-
getTranslationValue(
|
|
28
|
-
'activate',
|
|
29
|
-
{} as Translation,
|
|
30
|
-
{ activate: 'fb' } as Translation
|
|
31
|
-
),
|
|
32
|
-
'fb'
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should get the correct translation value of the translation object', () => {
|
|
37
|
-
const translation = {
|
|
38
|
-
a: {
|
|
39
|
-
b: {
|
|
40
|
-
c: 'c',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
equal(getObjectPropertyValue(translation, 'a.b.c'), 'c');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should use placeholder in translation', () => {
|
|
48
|
-
equal(replace('%0 with placeholder', 'test'), 'test with placeholder');
|
|
49
|
-
equal(
|
|
50
|
-
replace('%0 with %1', 'test', 'placeholder'),
|
|
51
|
-
'test with placeholder'
|
|
52
|
-
);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
1
|
+
import { equal } from 'assert';
|
|
2
|
+
import { getObjectPropertyValue } from '../../../helpers/objects';
|
|
3
|
+
import { getTranslationValue, initTranslations, replace } from '../../../i18n';
|
|
4
|
+
import { Translation } from '../../../models';
|
|
5
|
+
|
|
6
|
+
describe('i18n', () => {
|
|
7
|
+
it('should initialize translations', () => {
|
|
8
|
+
return initTranslations();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should translate key', () => {
|
|
12
|
+
equal(
|
|
13
|
+
getTranslationValue('activate', { activate: 'b' } as Translation),
|
|
14
|
+
'b'
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should return undefined if translation is not defined', () => {
|
|
19
|
+
equal(
|
|
20
|
+
getTranslationValue('activate', {} as Translation, {} as Translation),
|
|
21
|
+
undefined
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should use fallback if translation is not defined', () => {
|
|
26
|
+
equal(
|
|
27
|
+
getTranslationValue(
|
|
28
|
+
'activate',
|
|
29
|
+
{} as Translation,
|
|
30
|
+
{ activate: 'fb' } as Translation
|
|
31
|
+
),
|
|
32
|
+
'fb'
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should get the correct translation value of the translation object', () => {
|
|
37
|
+
const translation = {
|
|
38
|
+
a: {
|
|
39
|
+
b: {
|
|
40
|
+
c: 'c',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
equal(getObjectPropertyValue(translation, 'a.b.c'), 'c');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should use placeholder in translation', () => {
|
|
48
|
+
equal(replace('%0 with placeholder', 'test'), 'test with placeholder');
|
|
49
|
+
equal(
|
|
50
|
+
replace('%0 with %1', 'test', 'placeholder'),
|
|
51
|
+
'test with placeholder'
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
});
|