Skip to content

Commit 1290db1

Browse files
committed
Update findUnusedPhrases script
1 parent f37cc7b commit 1290db1

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"preinstall": "npx npm-force-resolutions",
1111
"test": "tsc --noEmit -p .",
1212
"lint": "npx eslint . --ext .ts",
13+
"unusedPhrases": "npx ts-node scripts/findUnusedPhrases.ts",
1314
"find-eslint-comments": "grep -r --exclude-dir=node_modules 'eslint-disable' .",
1415
"force-update-master": "git fetch origin && git reset --hard origin/master"
1516
},

scripts/findUnusedPhrases.js renamed to scripts/findUnusedPhrases.ts

+34-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2023 Alexander Emanuelsson (alexemanuelol)
2+
Copyright (C) 2025 Alexander Emanuelsson (alexemanuelol)
33
44
This program is free software: you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -18,49 +18,61 @@
1818
1919
*/
2020

21-
/* eslint-disable */
21+
import * as fs from 'fs';
22+
import * as path from 'path';
2223

23-
const Path = require('path');
24-
const Fs = require('fs');
25-
26-
const root = Path.join(__dirname, '..');
27-
const enJsonPath = Path.join(root, 'languages/en.json');
28-
const allFiles = [];
24+
const root = path.join(__dirname, '..');
25+
const languageFilePath = path.join(root, 'src/languages/en.json');
26+
const allFiles: string[] = [];
2927

3028
const ignoredDirs = [
3129
'languages',
3230
'resources',
33-
'docs'
31+
'staticFiles',
32+
'node_modules',
33+
'templates'
3434
];
3535

36-
function recursiveSearchOfAllFiles(path) {
37-
Fs.readdirSync(path).forEach(file => {
38-
const filePath = Path.join(path, file);
36+
function recursiveSearchOfAllFiles(currentPath: string) {
37+
const files = fs.readdirSync(currentPath);
38+
39+
for (const file of files) {
40+
const filePath = path.join(currentPath, file);
41+
const stat = fs.lstatSync(filePath);
3942

40-
if (Fs.lstatSync(filePath).isDirectory()) {
41-
if (!ignoredDirs.includes(file)) {
43+
/* Only include files in src or the index.ts file */
44+
if (stat.isDirectory()) {
45+
const relativeDir = path.relative(root, filePath);
46+
if (!ignoredDirs.some(dir => relativeDir.includes(dir))) {
4247
recursiveSearchOfAllFiles(filePath);
4348
}
49+
} else {
50+
/* Include index.ts explicitly and all files in the src directory */
51+
if (file === 'index.ts' || filePath.includes(path.join(root, 'src'))) {
52+
allFiles.push(filePath);
53+
}
4454
}
45-
else {
46-
allFiles.push(filePath);
47-
}
48-
})
55+
}
4956
}
57+
5058
recursiveSearchOfAllFiles(root);
5159

52-
const phrases = JSON.parse(Fs.readFileSync(enJsonPath, 'utf8'));
60+
/* Read the phrases from the language file */
61+
const phrases = JSON.parse(fs.readFileSync(languageFilePath, 'utf8'));
5362
const phrasesKeys = Object.keys(phrases);
5463
const nbrOfPhrases = phrasesKeys.length;
5564

5665
let counter = 1;
57-
const unusedPhrases = [];
66+
const unusedPhrases: string[] = [];
67+
5868
for (const phrase of phrasesKeys) {
59-
console.log(`Phrase (${counter}/${nbrOfPhrases})`);
69+
console.log(`Checking phrase (${counter}/${nbrOfPhrases}): "${phrase}"`);
6070

6171
let used = false;
6272
for (const file of allFiles) {
63-
const data = Fs.readFileSync(file, { encoding: 'utf8', flag: 'r' });
73+
const data = fs.readFileSync(file, { encoding: 'utf8', flag: 'r' });
74+
75+
/* Check if the phrase is used in any of the three cases */
6476
if (data.includes(`'${phrase}'`) || data.includes(`"${phrase}"`) || data.includes(`\`${phrase}\``)) {
6577
used = true;
6678
break;

src/languages/en.json

-9
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
"autoSettingLabel": "AUTO SETTING: ",
2121
"autoSettingOffDesc": "Smart Switch work as normal.",
2222
"autoSettingOffLabel": "OFF",
23-
"botMuted": "Bot Muted",
2423
"buttonActiveServer": "ACTIVE SERVER",
2524
"buttonAfk": "AFK",
2625
"buttonView": "VIEW",
27-
"buttonChatFunctionality": "CHAT FUNCTIONALITY",
2826
"buttonCommandPrefix": "COMMAND PREFIX",
2927
"buttonConnect": "CONNECT",
3028
"buttonConnecting": "CONNECTING",
@@ -36,17 +34,14 @@
3634
"buttonEdit": "EDIT",
3735
"buttonEnabled": "ENABLED",
3836
"buttonInGame": "IN-GAME",
39-
"buttonMuted": "MUTED",
4037
"buttonOff": "OFF",
4138
"buttonOn": "ON",
4239
"buttonOnlyPaired": "ONLY PAIRED",
4340
"buttonReconnecting": "RECONNECTING",
4441
"buttonRecycle": "RECYCLE",
4542
"buttonTrademark": "TRADEMARK",
46-
"buttonUnmuted": "UNMUTED",
4743
"buttonVoice": "VOICE",
4844
"buttonWebsite": "WEBSITE",
49-
"chatFunctionality": "Chat Functionality",
5045
"commandPrefix": "Command Prefix",
5146
"commandPrefixEdit": "Edit Command Prefix",
5247
"credentialAppRequired": "rustplusplus version {version1} requires Credential application version {version2}.",
@@ -56,7 +51,6 @@
5651
"embedDescCredentialsExpired": "Your rustplusplus Credentials for steamId {steamId} that were issued {issueDate} have expired {expireDate}. The credentials were used in the server(s): {guilds}.",
5752
"embedTitleCredentialsExpired": "rustplusplus Credentials expired",
5853
"embedTitleListOfRoles": "List of configured roles",
59-
"enabled": "Enabled",
6054
"errorDescCredentialsForSteamIdNotFound": "Credentials for the steamId {steamId} could not be found.",
6155
"errorDescCredentialsNotPartOfGuild": "Credentials for the steamId {steamId} is not part of this server.",
6256
"errorDescInvalidSubcommand": "The subcommand '{subcommand}' is invalid or does not exist.",
@@ -97,7 +91,6 @@
9791
"eventNotificationSetting-vendingMachineDespawned": "Vending Machine Despawned",
9892
"eventNotificationSetting-vendingMachineSpawned": "Vending Machine Spawned",
9993
"expireAt": "Expire: {time}",
100-
"false": "False",
10194
"female": "Female",
10295
"guildChannelDisplayName-activity": "activity",
10396
"guildChannelDisplayName-commands": "commands",
@@ -202,8 +195,6 @@
202195
"storageMonitor": "Storage Monitor",
203196
"toolCupboard": "Tool Cupboard",
204197
"trademarkEdit": "Edit Trademark",
205-
"trademarkEnterNullForEmpty": "Enter \"null\" for empty trademark",
206-
"true": "True",
207198
"type": "Type",
208199
"unknown": "Unknown",
209200
"upkeep": "Upkeep",

0 commit comments

Comments
 (0)