iachat/lib
Sivin Varghese 72509f9e38
chore: Improve translation service with HTML and plain text support (#11305)
# Pull Request Template

## Description

This PR changes to translation to properly handle different content
types during translation.

### Changes

1. **Email translation with HTML support**
   - Properly detects and preserves HTML content from emails
   - Sets `mime_type` to 'text/html' when HTML content is present

2. **Email translation with plain text support**
   - Falls back to email text content when HTML is not available
- Sets `mime_type` to 'text/plain' when HTML is not available and
content type includes 'text/plain'

3. **Plain message with plain text support (Non email channels)**
   - Sets `mime_type` to 'text/plain' for non-email channels
- Fixes an issue where Markdown formatting was being lost due to
incorrect `mime_type`
   
**Note**: Translation for very long emails is not currently supported.

Fixes
https://linear.app/chatwoot/issue/CW-4244/translate-button-doesnt-work-in-email-channels

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)

## How Has This Been Tested?

**Loom video**

https://www.loom.com/share/8f8428ed2cfe415ea5cb6c547c070f00?sid=eab9fa11-05f8-4838-9181-334bee1023c4


## Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [x] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
2025-04-16 17:59:06 +05:30
..
action_view/template/handlers feat: Customisable Email Templates (#1095) 2020-08-06 15:21:06 +05:30
assets Initial Commit 2019-08-14 15:18:44 +05:30
custom_exceptions feat: validate query conditions (#10595) 2024-12-17 17:16:37 +05:30
events feat: Add notification.updated event (#8871) 2024-02-07 18:15:51 +05:30
filters fix: add priority in filter keys [CW-3177] (#9179) 2024-04-05 10:03:48 +05:30
integrations chore: Improve translation service with HTML and plain text support (#11305) 2025-04-16 17:59:06 +05:30
linear feat: Add issue status in linear issue search item (#9598) 2024-08-08 13:44:08 +05:30
redis fix: inconsistent OpenAI cache interface (#10009) 2024-08-22 23:04:14 +05:30
seeders fix: downcase email before finding (#8921) 2024-02-21 18:51:00 +05:30
tasks fix: ip-lookup database lazy loading for all environments (#8052) 2024-10-22 23:18:30 -07:00
webhooks fix: Handle all types of errors in API channel webhooks (#8307) 2023-11-07 12:54:49 +05:30
base_markdown_renderer.rb feat: support image height in markdown rendering of messages (#8177) 2023-11-02 13:51:54 -07:00
chatwoot_app.rb feat: add sitemap for help center (#9280) 2024-04-26 21:36:39 +05:30
chatwoot_captcha.rb feat: Add hCaptcha for public forms (#4017) 2022-02-18 20:02:50 +05:30
chatwoot_exception_tracker.rb fix: modify exception tracker to log even if sentry configured (#7563) 2023-07-21 11:58:49 +03:00
chatwoot_hub.rb feat: Provision captain accounts automatically (#10168) 2024-09-26 19:21:29 -07:00
chatwoot_markdown_renderer.rb feat: Adds backend support for rendering tables in articles (#9526) 2024-05-24 08:44:01 +05:30
config_loader.rb chore: Add display manifest to whitelabel settings (#8708) 2024-01-16 09:50:23 +04:00
csml_engine.rb feat: Add native support for CSML in agent_bot API (#4913) 2022-06-23 19:17:46 +05:30
current.rb Automation enhancement (#4087) 2022-03-21 13:12:27 +05:30
custom_markdown_renderer.rb feat: use nocookie version of youtube & vimeo for help center embeds (#11061) 2025-03-12 10:32:25 +05:30
dyte.rb feat: Upgrade Dyte apis to v2 (#10706) 2025-02-19 14:47:48 -08:00
exception_list.rb Fix: prevent IMAPBadResponse exception from sending the authorization mail (#7154) 2023-05-22 13:51:56 +05:30
global_config_service.rb chore: Update dependencies to the latest versions (#5033) 2022-07-15 09:51:59 +07:00
global_config.rb chore: Add display manifest to whitelabel settings (#8708) 2024-01-16 09:50:23 +04:00
limits.rb chore: Add validation to prevent message flooding (#9254) 2024-04-18 00:14:59 -07:00
linear.rb feat: Linear OAuth 2.0 (#10851) 2025-02-27 18:15:53 +05:30
microsoft_graph_auth.rb Revert "feat: Support Azure single-tenant application using the Graph… (#7436) 2023-06-29 16:50:18 -07:00
online_status_tracker.rb fix: Get online status from db when not present in cache [CW-3233] (#9477) 2024-05-15 21:23:19 -07:00
regex_helper.rb fix: flaky test whatsapp_cloud_service_spec.rb:17 (#5786) 2022-11-01 19:51:42 -07:00
url_helper.rb fix: Referer URL validation (#4309) 2022-03-30 14:36:22 +05:30
vapid_service.rb chore: Switch to web-push gem (#6390) 2023-02-03 18:55:22 +05:30