From 158a3f14ea083ae99d556242e20dddb228b829ad Mon Sep 17 00:00:00 2001 From: cihat Date: Fri, 31 Jan 2025 09:55:21 +0300 Subject: [PATCH] fix: use default.json --- Server/index.js | 1 + Server/locales/default.json | 145 +++++++++++++++++++++++++++ Server/nodemon.json | 12 +++ Server/service/translationService.js | 24 ++--- 4 files changed, 168 insertions(+), 14 deletions(-) create mode 100644 Server/locales/default.json create mode 100644 Server/nodemon.json diff --git a/Server/index.js b/Server/index.js index 8eefabf30..b5f2561c7 100644 --- a/Server/index.js +++ b/Server/index.js @@ -160,6 +160,7 @@ const startApp = async () => { } } + // Create and Register Primary services const networkService = new NetworkService(axios, ping, logger, http, Docker, net); const translationService = new TranslationService(logger, networkService); const stringService = new StringService(translationService); diff --git a/Server/locales/default.json b/Server/locales/default.json new file mode 100644 index 000000000..a438e5fc8 --- /dev/null +++ b/Server/locales/default.json @@ -0,0 +1,145 @@ +{ + "dontHaveAccount": "Don't have account", + "email": "E-mail", + "forgotPassword": "Forgot Password", + "password": "password", + "signUp": "Sign up", + "submit": "Submit", + "title": "Title", + "continue": "Continue", + "enterEmail": "Enter your email", + "authLoginTitle": "Log In", + "authLoginEnterPassword": "Enter your password", + "commonPassword": "Password", + "commonBack": "Back", + "authForgotPasswordTitle": "Forgot password?", + "authForgotPasswordResetPassword": "Reset password", + "createPassword": "Create your password", + "createAPassword": "Create a password", + "authRegisterAlreadyHaveAccount": "Already have an account?", + "commonAppName": "BlueWave Uptime", + "authLoginEnterEmail": "Enter your email", + "authRegisterTitle": "Create an account", + "authRegisterStepOneTitle": "Create your account", + "authRegisterStepOneDescription": "Enter your details to get started", + "authRegisterStepTwoTitle": "Set up your profile", + "authRegisterStepTwoDescription": "Tell us more about yourself", + "authRegisterStepThreeTitle": "Almost done!", + "authRegisterStepThreeDescription": "Review your information", + "authForgotPasswordDescription": "No worries, we'll send you reset instructions.", + "authForgotPasswordSendInstructions": "Send instructions", + "authForgotPasswordBackTo": "Back to", + "authCheckEmailTitle": "Check your email", + "authCheckEmailDescription": "We sent a password reset link to {{email}}", + "authCheckEmailResendEmail": "Resend email", + "authCheckEmailBackTo": "Back to", + "goBackTo": "Go back to", + "authCheckEmailDidntReceiveEmail": "Didn't receive the email?", + "authCheckEmailClickToResend": "Click to resend", + "authSetNewPasswordTitle": "Set new password", + "authSetNewPasswordDescription": "Your new password must be different from previously used passwords.", + "authSetNewPasswordNewPassword": "New password", + "authSetNewPasswordConfirmPassword": "Confirm password", + "confirmPassword": "Confirm your password", + "authSetNewPasswordResetPassword": "Reset password", + "authSetNewPasswordBackTo": "Back to", + "authPasswordMustBeAtLeast": "Must be at least", + "authPasswordCharactersLong": "8 characters long", + "authPasswordMustContainAtLeast": "Must contain at least", + "authPasswordSpecialCharacter": "one special character", + "authPasswordOneNumber": "one number", + "authPasswordUpperCharacter": "one upper character", + "authPasswordLowerCharacter": "one lower character", + "authPasswordConfirmAndPassword": "Confirm password and password", + "authPasswordMustMatch": "must match", + "friendlyError": "Something went wrong...", + "unknownError": "An unknown error occurred", + "unauthorized": "Unauthorized access", + "authAdminExists": "Admin already exists", + "authInviteNotFound": "Invite not found", + "unknownService": "Unknown service", + "noAuthToken": "No auth token provided", + "invalidAuthToken": "Invalid auth token", + "expiredAuthToken": "Token expired", + "noRefreshToken": "No refresh token provided", + "invalidRefreshToken": "Invalid refresh token", + "expiredRefreshToken": "Refresh token expired", + "requestNewAccessToken": "Request new access token", + "invalidPayload": "Invalid payload", + "verifyOwnerNotFound": "Document not found", + "verifyOwnerUnauthorized": "Unauthorized access", + "insufficientPermissions": "Insufficient permissions", + "dbUserExists": "User already exists", + "dbUserNotFound": "User not found", + "dbTokenNotFound": "Token not found", + "dbResetPasswordBadMatch": "New password must be different from old password", + "dbFindMonitorById": "Monitor with id ${monitorId} not found", + "dbDeleteChecks": "No checks found for monitor with id ${monitorId}", + "authIncorrectPassword": "Incorrect password", + "authUnauthorized": "Unauthorized access", + "monitorGetById": "Monitor not found", + "monitorGetByUserId": "No monitors found for user", + "jobQueueWorkerClose": "Error closing worker", + "jobQueueDeleteJob": "Job not found in queue", + "jobQueueObliterate": "Error obliterating queue", + "pingCannotResolve": "No response", + "statusPageNotFound": "Status page not found", + "statusPageUrlNotUnique": "Status page url must be unique", + "dockerFail": "Failed to fetch Docker container information", + "dockerNotFound": "Docker container not found", + "portFail": "Failed to connect to port", + "alertCreate": "Alert created successfully", + "alertGetByUser": "Got alerts successfully", + "alertGetByMonitor": "Got alerts by Monitor successfully", + "alertGetById": "Got alert by Id successfully", + "alertEdit": "Alert edited successfully", + "alertDelete": "Alert deleted successfully", + "authCreateUser": "User created successfully", + "authLoginUser": "User logged in successfully", + "authLogoutUser": "User logged out successfully", + "authUpdateUser": "User updated successfully", + "authCreateRecoveryToken": "Recovery token created successfully", + "authVerifyRecoveryToken": "Recovery token verified successfully", + "authResetPassword": "Password reset successfully", + "authAdminCheck": "Admin check completed successfully", + "authDeleteUser": "User deleted successfully", + "authTokenRefreshed": "Auth token is refreshed", + "authGetAllUsers": "Got all users successfully", + "inviteIssued": "Invite sent successfully", + "inviteVerified": "Invite verified successfully", + "checkCreate": "Check created successfully", + "checkGet": "Got checks successfully", + "checkDelete": "Checks deleted successfully", + "checkUpdateTtl": "Checks TTL updated successfully", + "monitorGetAll": "Got all monitors successfully", + "monitorStatsById": "Got monitor stats by Id successfully", + "monitorGetByIdSuccess": "Got monitor by Id successfully", + "monitorGetByTeamId": "Got monitors by Team Id successfully", + "monitorGetByUserIdSuccess": "Got monitor for ${userId} successfully", + "monitorCreate": "Monitor created successfully", + "monitorDelete": "Monitor deleted successfully", + "monitorEdit": "Monitor edited successfully", + "monitorCertificate": "Got monitor certificate successfully", + "monitorDemoAdded": "Successfully added demo monitors", + "queueGetMetrics": "Got metrics successfully", + "queueAddJob": "Job added successfully", + "queueObliterate": "Queue obliterated", + "jobQueueDeleteJobSuccess": "Job removed successfully", + "jobQueuePauseJob": "Job paused successfully", + "jobQueueResumeJob": "Job resumed successfully", + "maintenanceWindowGetById": "Got Maintenance Window by Id successfully", + "maintenanceWindowCreate": "Maintenance Window created successfully", + "maintenanceWindowGetByTeam": "Got Maintenance Windows by Team successfully", + "maintenanceWindowDelete": "Maintenance Window deleted successfully", + "maintenanceWindowEdit": "Maintenance Window edited successfully", + "pingSuccess": "Success", + "getAppSettings": "Got app settings successfully", + "updateAppSettings": "Updated app settings successfully", + "statusPageByUrl": "Got status page by url successfully", + "statusPageCreate": "Status page created successfully", + "newTermsAdded": "New terms added to POEditor", + "dockerSuccess": "Docker container status fetched successfully", + "portSuccess": "Port connected successfully", + "monitorPause": "Monitor paused successfully", + "monitorResume": "Monitor resumed successfully" +} \ No newline at end of file diff --git a/Server/nodemon.json b/Server/nodemon.json new file mode 100644 index 000000000..b43c80fc1 --- /dev/null +++ b/Server/nodemon.json @@ -0,0 +1,12 @@ +{ + "ignore": [ + "locales/*", + "*.log", + "node_modules/*" + ], + "watch": [ + "*.js", + "*.json" + ], + "ext": "js,json" +} \ No newline at end of file diff --git a/Server/service/translationService.js b/Server/service/translationService.js index 652df340c..5a7877d4e 100644 --- a/Server/service/translationService.js +++ b/Server/service/translationService.js @@ -95,20 +95,18 @@ class TranslationService { if (hasError || Object.keys(this.translations[this._language]).length === 0) { this.logger.error({ - message: 'Failed to fetch translations from POEditor, using locales_en.json', + message: 'Failed to fetch translations from POEditor, using default.json', service: 'TranslationService', method: 'loadTranslations' }); - - // Load translations from locales_en.json in utils directory - const utilsPath = path.join(process.cwd(), 'utils'); - const utilsFilePath = path.join(utilsPath, 'locales_en.json'); - if (fs.existsSync(utilsFilePath)) { - const content = fs.readFileSync(utilsFilePath, 'utf8'); + // Load translations from default.json in locales directory + const defaultFilePath = path.join(this.localesDir, 'default.json'); + if (fs.existsSync(defaultFilePath)) { + const content = fs.readFileSync(defaultFilePath, 'utf8'); this.translations['en'] = JSON.parse(content); } else { - throw new Error('locales_en.json file not found'); + throw new Error('default.json file not found in locales directory'); } } @@ -163,10 +161,9 @@ class TranslationService { fs.writeFileSync(filePath, JSON.stringify(translations, null, 2)); } - const utilsPath = path.join(process.cwd(), 'utils'); + const defaultFilePath = path.join(this.localesDir, 'default.json'); const enTranslations = this.translations['en'] || {}; - const utilsFilePath = path.join(utilsPath, 'locales_en.json'); - fs.writeFileSync(utilsFilePath, JSON.stringify(enTranslations, null, 2)); + fs.writeFileSync(defaultFilePath, JSON.stringify(enTranslations, null, 2)); this.logger.info({ message: 'Translations saved to files successfully', @@ -245,9 +242,8 @@ class TranslationService { async syncTermsWithPOEditor() { try { - const utilsPath = path.join(process.cwd(), 'utils'); - const utilsFilePath = path.join(utilsPath, 'locales_en.json'); - const enTranslations = JSON.parse(fs.readFileSync(utilsFilePath, 'utf8')); + const defaultFilePath = path.join(this.localesDir, 'default.json'); + const enTranslations = JSON.parse(fs.readFileSync(defaultFilePath, 'utf8')); const localTerms = Object.keys(enTranslations) .map(term => term);