Add i18n support with English and Spanish translations

- Created i18n package with translator and middleware
- Added translation files for English (en.json) and Spanish (es.json)
- Updated all HTTP handlers to use i18n for error/success messages
- Added comprehensive test coverage for i18n (87%)
- Updated CI workflow to use Go 1.24
- All tests passing with 50.8% total coverage
This commit is contained in:
2025-11-29 12:27:26 +01:00
parent 90d5628a42
commit a2aa8b2a76
18 changed files with 933 additions and 120 deletions
+109
View File
@@ -0,0 +1,109 @@
{
"errors": {
"invalid_request_body": "Invalid request body",
"email_already_registered": "Email already registered",
"registration_closed": "Registration is currently closed",
"failed_register_user": "Failed to register user",
"invalid_credentials": "Invalid email or password",
"email_not_verified": "Please verify your email before logging in",
"failed_login": "Failed to login",
"failed_generate_token": "Failed to generate token",
"failed_create_refresh_token": "Failed to create refresh token",
"failed_save_refresh_token": "Failed to save refresh token",
"invalid_expired_refresh_token": "Invalid or expired refresh token",
"failed_refresh_token": "Failed to refresh token",
"refresh_token_not_found": "Refresh token not found",
"invalid_refresh_token": "Invalid refresh token",
"user_not_authenticated": "User not authenticated",
"failed_get_user": "Failed to get user",
"failed_get_habits": "Failed to get habits",
"failed_create_habit": "Failed to create habit",
"habit_not_found": "Habit not found",
"access_denied": "Access denied",
"failed_get_habit": "Failed to get habit",
"invalid_input": "Invalid input",
"failed_update_habit": "Failed to update habit",
"failed_archive_habit": "Failed to archive habit",
"failed_get_habit_entries": "Failed to get habit entries",
"invalid_date_format": "Invalid date format (use YYYY-MM-DD)",
"invalid_page_parameter": "Invalid 'page' parameter",
"invalid_limit_parameter": "Invalid 'limit' parameter (must be 1-100)",
"pagination_required": "Pagination required: provide 'limit' parameter or use date range ≤ 1 year",
"invalid_from_date_format": "Invalid 'from' date format (use YYYY-MM-DD)",
"invalid_to_date_format": "Invalid 'to' date format (use YYYY-MM-DD)",
"habit_already_marked": "Habit already marked for this date",
"failed_mark_habit": "Failed to mark habit",
"habit_entry_not_found": "Habit entry not found",
"failed_unmark_habit": "Failed to unmark habit",
"invalid_expired_verification_token": "Invalid or expired verification token",
"email_already_verified": "Email already verified",
"failed_verify_email": "Failed to verify email",
"invalid_email": "Invalid email",
"user_not_found": "User not found",
"failed_send_verification_email": "Failed to send verification email",
"email_not_verified_reset": "Please verify your email before resetting password",
"failed_send_reset_email": "Failed to send reset email",
"invalid_token_or_password": "Invalid or expired token, or password requirements not met",
"failed_reset_password": "Failed to reset password",
"failed_delete_user": "Failed to delete user",
"failed_get_stats": "Failed to get statistics"
},
"success": {
"registration_with_verification": "Registration successful. Please check your email to verify your account.",
"registration_without_verification": "Registration successful. You can now login.",
"logged_out": "Successfully logged out",
"email_verified": "Email verified successfully",
"verification_email_sent": "Verification email sent successfully",
"password_reset_email_sent": "Password reset email sent successfully",
"password_reset": "Password reset successfully",
"user_deleted": "User and all associated data deleted successfully"
},
"validation": {
"email_required": "email is required",
"email_invalid_format": "email must be a valid email address",
"email_too_long": "email must not exceed 254 characters",
"password_required": "password is required",
"password_min_length": "password must be at least 8 characters long",
"password_max_length": "password must not exceed 128 characters",
"password_uppercase": "password must contain at least one uppercase letter",
"password_lowercase": "password must contain at least one lowercase letter",
"password_digit": "password must contain at least one digit",
"password_special_char": "password must contain at least one special character (!@#$%^&*)",
"timezone_required": "timezone is required",
"timezone_invalid": "timezone is not a valid IANA timezone",
"name_required": "name is required",
"name_too_long": "name must not exceed 255 characters",
"type_invalid": "type must be one of: BOOLEAN, COUNTER, VALUE",
"frequency_invalid": "frequency must be one of: DAILY, WEEKLY, MONTHLY",
"specific_days_required": "specific_days is required for WEEKLY frequency",
"specific_days_invalid": "specific_days must contain values between 0-6 (0=Sunday, 6=Saturday)",
"specific_dates_required": "specific_dates is required for MONTHLY frequency",
"specific_dates_invalid": "specific_dates must contain values between 1-31",
"target_value_required": "target_value is required for VALUE type",
"target_value_positive": "target_value must be positive"
},
"emails": {
"verify_email_subject": "Verify your email address",
"verify_email_title": "Welcome! Please verify your email",
"verify_email_body": "Thank you for registering. Please click the link below to verify your email address:",
"verify_email_link": "Verify Email",
"verify_email_expiry": "This link will expire in 24 hours.",
"verify_email_ignore": "If you didn't create an account, you can safely ignore this email.",
"resend_verification_subject": "Verify your email address",
"resend_verification_title": "Verify your email address",
"resend_verification_body": "Please click the link below to verify your email address:",
"resend_verification_link": "Verify Email",
"resend_verification_expiry": "This link will expire in 24 hours.",
"resend_verification_ignore": "If you didn't request this, you can safely ignore this email.",
"password_reset_subject": "Password Reset Request",
"password_reset_title": "Password Reset Request",
"password_reset_body": "You have requested to reset your password. Please click the link below:",
"password_reset_link": "Reset Password",
"password_reset_expiry": "This link will expire in 1 hour.",
"password_reset_ignore": "If you didn't request this, you can safely ignore this email.",
"welcome_subject": "Welcome to Apocapoc!",
"welcome_title": "Welcome to Apocapoc!",
"welcome_body": "Your email has been verified successfully. You can now start using all features of Apocapoc.",
"welcome_enjoy": "Enjoy building better habits!"
}
}