Skip to content

Commit

Permalink
added missing strings (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakprabhakara authored Feb 21, 2024
1 parent df390d8 commit 682a583
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ jobs:
- run: npm install
- run: npm run check-lint
- run: npm run check-format
- run: npm run locale-check
- run: npm run test
- run: npm run build-ci
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
locale-check.js
node_modules
.next
out
98 changes: 98 additions & 0 deletions locale-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const fs = require('fs');
const path = require('path');
const regExp = /\bt\('(.*?)'/gm;
const altRegExp = /\bi18nKey="(.*?)"/gm;
// const authLayoutRegExp =
// /\bAuthLayout.*\bheading="(.*?)".*\bdescription="(.*?)"/gm;
const authHeadingRegExp = /\bheading="(.*?)"/gm;
const authDescriptionRegExp = /\bdescription="(.*?)"/gm;
const exceptionList = [
'email-verified',
'allow-only-work-email',
'verify-account-expired',
'confirm-your-email',
'exceeded-login-attempts',
'account-unlocked',
]

const allStrings = {};

const localeFile = require('./locales/en/common.json');

const files = fs.readdirSync('./', { recursive: true, withFileTypes: true });
//console.log('files:', files);

let error = false;

files.forEach((file) => {
if (file.isDirectory()) {
return;
}
if (file.path.includes('node_modules')) {
return;
}

if (['.ts', '.tsx'].includes(path.extname(file.name).toLowerCase())) {
const fileContent = fs.readFileSync(
path.join(file.path, file.name),
'utf8'
);

(fileContent.match(regExp) || []).forEach((match) => {
const id = match.replace("t('", '').replace("'", '');
// console.log('match:', match);
allStrings[id] = true;
if (!localeFile[id]) {
error = true;
console.error(
`Missing key: ${path.join(file.path, file.name)} - ${id}`
);
}
});

(fileContent.match(altRegExp) || []).forEach((match) => {
const id = match.replace('i18nKey="', '').replace('"', '');
// console.log('match:', match, id);
allStrings[id] = true;
if (!localeFile[id]) {
error = true;
console.error(
`Missing key: ${path.join(file.path, file.name)} - ${id}`
);
}
});

[authHeadingRegExp, authDescriptionRegExp].forEach((regExp) => {
const authGroups = fileContent.match(regExp) || [];
authGroups.forEach((match) => {
// console.log('match:', match);
const parts = match.replace('AuthLayout ', '');
parts.split(' ').forEach((part) => {
const id = part.startsWith('heading=')
? part.replace('heading="', '').replace('"', '')
: part.replace('description="', '').replace('"', '');
// console.log('part:', part, id);

allStrings[id] = true;
if (!localeFile[id]) {
error = true;
console.error(
`Missing key: ${path.join(file.path, file.name)} - ${id}`
);
}
});
});
});
}
});

Object.keys(localeFile).forEach((key) => {
if (!allStrings[key] && !exceptionList.includes(key)) {
error = true;
console.error(`Unused key: ${key}`);
}
});

if (error) {
process.exit(1);
}
21 changes: 5 additions & 16 deletions locales/en/common.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"device": "Device",
"status": "Status",
"created": "Created",
"response": "Response",
"no-more-results": "No more results",
"get-started": "Get Started",
"login": "Log in using an existing account",
"email-login-error": "Something went wrong while sending the email. Please try again later.",
Expand Down Expand Up @@ -30,7 +35,6 @@
"invitation-deleted": "Invitation deleted",
"send-invite": "Invite",
"invite-new-member": "Invite New Member",
"invite-member-message": "Invite team members to join your team.",
"accept-invitation": "Join the Team",
"create-team": "Create Team",
"remove-team": "Remove Team",
Expand All @@ -43,7 +47,6 @@
"accept-invite": "You can accept the invitation to join the team by clicking the button below.",
"invite-create-account": "To continue, you must either create a new account or login to an existing account.",
"no-active-team": "You do not have any active team.",
"provision": "Provision and de-provision users with your directory provider.",
"name": "Name",
"email": "Email",
"members": "Members",
Expand All @@ -61,7 +64,6 @@
"edit": "Edit",
"close": "Close",
"unknown-error": "Unknown Error",
"configure": "Configure",
"add-member": "Invite Member",
"add-webhook": "Add Webhook",
"webhook-created": "Webhook created successfully.",
Expand All @@ -79,9 +81,6 @@
"features": "Features",
"create-directory-connection": "Create Directory Connection",
"create-directory": "Create Directory",
"directory-sync-deleted": "Directory sync deleted successfully.",
"confirm-delete-directory-sync": "Confirm delete directory sync",
"delete-directory-sync-warning": "Deleting a directory sync will affect all apps that use its configuration. This action cannot be undone.",
"directory-sync-provider": "Directory Sync Provider",
"create-directory-message": "Automatically provision and de-provision users with your directory provider.",
"directory-sync-message": "Directory Sync Provider will ask you for the following information to configure your SCIM app.",
Expand All @@ -97,7 +96,6 @@
"account": "Account",
"password": "Password",
"settings": "Settings",
"directory-sync": "Directory Sync",
"audit-logs": "Audit Logs",
"webhooks": "Webhooks",
"team": "Team",
Expand Down Expand Up @@ -147,10 +145,7 @@
"assertion-signature": "Assertion Signature",
"signature-algorithm": "Signature Algorithm",
"assertion-encryption": "Assertion Encryption",
"token-not-found": "The verification token is invalid or has already been used.",
"email-verified": "Your email has been successfully verified. Thank you for confirming your account.",
"invalid-credentials": "Invalid login credentials",
"no-credentials": "No credentials found.",
"confirm-email": "Confirm your email address",
"confirm-email-description": "Please click the verification link sent to your email to activate your account. There is a chance it might have ended up in your Spam folder, please check there if you do not receive the email.",
"allow-only-work-email": "Please use your work email to create an account.",
Expand Down Expand Up @@ -199,12 +194,8 @@
"remove-current-browser-session-warning": "You are about to remove your current session. Once you do this, you will be logged out of the app.",
"session-removed": "Browser session removed.",
"remove-team-restricted": "Please contact our support if you want to remove this team. We will help you with that.",
"open-customer-portal": "Open Customer Portal",
"subscriptions": "Subscriptions",
"from": "From",
"to": "To",
"stripe-checkout-fallback-error": "Something went wrong while initiating checkout, please try again later.",
"error-occurred": "An error occurred",
"create-link": "Create Link",
"select-a-session-to-delete": "Please select a session to delete",
"api-keys": "API Keys",
Expand Down Expand Up @@ -233,8 +224,6 @@
"switch-theme": "Change Theme",
"logout": "Sign out",
"guides": "guides",
"refer_to_provider_instructions": "Refer to our <guideLink>guides</guideLink> for provider specific instructions.",
"sp_download_our_public_cert": "If you want to encrypt the assertion, you can <downloadLink>download our public certificate.</downloadLink> Otherwise select the Unencrypted option.",
"download": "Download",
"plan": "Plan",
"start-date": "Start Date",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage --env=jsdom",
"build-ci": "next build",
"sync-stripe": "node --env-file .env syncStripe.js"
"sync-stripe": "node --env-file .env syncStripe.js",
"locale-check": "node locale-check.js"
},
"dependencies": {
"@boxyhq/metrics": "0.2.6",
Expand Down

0 comments on commit 682a583

Please sign in to comment.