feat: add i18n support for backend API and Telegram bot (#797)

* feat: add i18n support for backend API and Telegram bot

- Add comprehensive i18n support for all backend API error messages (zh/en)
- Add /lang command for Telegram bot to set language preference
- Add bilingual command descriptions for Telegram bot
- Support per-user language preference stored in KV
- Global push uses DEFAULT_LANG, user push uses saved preference

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: improve Telegram bot language preference feature

- Add internationalized message for disabled language feature
- Fix hardcoded English message in /lang command
- Optimize getTgMessages calls (reduce from 3 to 1 call)
- Remove verbose comments for better code clarity
- Add TgLangFeatureDisabledMsg to i18n (zh/en)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Dream Hunter
2025-12-31 01:42:41 +08:00
committed by GitHub
parent 5e227d2b2d
commit 3ebe22115a
25 changed files with 762 additions and 276 deletions

View File

@@ -1,11 +1,13 @@
import { Context } from "hono";
import { getBooleanValue } from "../utils";
import i18n from "../i18n";
export default {
getAutoReply: async (c: Context<HonoCustomType>) => {
const msgs = i18n.getMessagesbyContext(c);
if (!getBooleanValue(c.env.ENABLE_AUTO_REPLY)) {
return c.text("Auto reply is disabled", 403)
return c.text(msgs.AutoReplyDisabledMsg, 403)
}
const { address } = c.get("jwtPayload")
const results = await c.env.DB.prepare(
@@ -23,17 +25,18 @@ export default {
})
},
saveAutoReply: async (c: Context<HonoCustomType>) => {
const msgs = i18n.getMessagesbyContext(c);
if (!getBooleanValue(c.env.ENABLE_AUTO_REPLY)) {
return c.text("Auto reply is disabled", 403)
return c.text(msgs.AutoReplyDisabledMsg, 403)
}
const { address } = c.get("jwtPayload");
const { auto_reply } = await c.req.json();
const { name, subject, source_prefix, message, enabled } = auto_reply;
if ((!subject || !message) && enabled) {
return c.text("Invalid subject or message", 400)
return c.text(msgs.InvalidAutoReplyMsg, 400)
}
else if (subject.length > 255 || message.length > 255) {
return c.text("Subject or message too long", 400)
return c.text(msgs.SubjectOrMessageTooLongMsg, 400)
}
const { success } = await c.env.DB.prepare(
`INSERT OR REPLACE INTO auto_reply_mails`
@@ -44,7 +47,7 @@ export default {
subject || '', message || '', enabled ? 1 : 0
).run();
if (!success) {
return c.text("Failed to auto_reply settings", 500)
return c.text(msgs.OperationFailedMsg, 500)
}
return c.json({
success: success