Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

fix: auto translate label and shimmer polish (#16320)

Sivin Varghese9e916a2d7a5f
diff --git a/app/javascript/dashboard/components-next/message/Message.vue b/app/javascript/dashboard/components-next/message/Message.vue
index 6678b847b0a..28f2cd6d2a4 100644
--- a/app/javascript/dashboard/components-next/message/Message.vue
+++ b/app/javascript/dashboard/components-next/message/Message.vue
@@ -174,10 +174,9 @@ const displayedContent = computed(() =>
);
const isAutoTranslated = computed(() => {
- const { pending, sameLanguage } = translationState.value(props.id);
+ const { pending } = translationState.value(props.id);
return (
- !!autoTranslate.value.language &&
- (!!translationContent.value || pending || sameLanguage)
+ !!autoTranslate.value.language && (!!translationContent.value || pending)
);
});
diff --git a/app/javascript/dashboard/components-next/message/TranslationToggle.vue b/app/javascript/dashboard/components-next/message/TranslationToggle.vue
index 87d48aa3b70..2b33ddec024 100644
--- a/app/javascript/dashboard/components-next/message/TranslationToggle.vue
+++ b/app/javascript/dashboard/components-next/message/TranslationToggle.vue
@@ -17,18 +17,15 @@ defineEmits(['toggle']);
defineOptions({ inheritAttrs: false });
const { t } = useI18n();
-const { id, contentAttributes, messageType, contactSide, shouldGroupWithNext } =
- useMessageContext();
+const { id, contentAttributes, messageType, contactSide } = useMessageContext();
const { hasTranslations } = useTranslations(contentAttributes, contactSide);
const autoTranslate = useMapGetter('getAutoTranslate');
const translationState = useMapGetter('getMessageTranslationState');
const state = computed(() => translationState.value(id.value));
-// "Already in X" reads once per group, on its last message, like the timestamp.
const visible = computed(() => {
if (state.value.pending || state.value.failed) return true;
- if (state.value.sameLanguage) return !shouldGroupWithNext.value;
- return hasTranslations.value;
+ return hasTranslations.value && !state.value.sameLanguage;
});
const isOutgoing = computed(
() =>
@@ -81,7 +78,7 @@ const toggleLabel = computed(() => {
/>
<span
v-if="state.pending"
- class="bg-clip-text text-transparent bg-gradient-to-r from-n-slate-11 from-40% via-n-iris-9 to-n-slate-11 to-60% bg-[length:300%_100%] animate-text-shimmer motion-reduce:animate-none truncate"
+ class="bg-clip-text text-transparent bg-gradient-to-r from-n-iris-9 from-30% via-n-iris-12 to-n-iris-9 to-70% dark:from-n-slate-12 dark:from-40% dark:via-n-iris-9 dark:to-n-slate-12 dark:to-60% bg-[length:300%_100%] animate-text-shimmer motion-reduce:animate-none truncate"
>
{{
isOutgoing
@@ -98,13 +95,6 @@ const toggleLabel = computed(() => {
: $t('CONVERSATION.CONTACT_TRANSLATION_FAILED')
}}
</span>
- <span v-else-if="state.sameLanguage" class="truncate">
- {{
- $t('CONVERSATION.ALREADY_IN_LANGUAGE', {
- language: autoTranslate.agentLanguage,
- })
- }}
- </span>
<span
v-else
class="cursor-pointer hover:underline truncate"
diff --git a/app/javascript/dashboard/components-next/message/bubbles/Text/Index.vue b/app/javascript/dashboard/components-next/message/bubbles/Text/Index.vue
index 5ffe770025c..e95033cbde6 100644
--- a/app/javascript/dashboard/components-next/message/bubbles/Text/Index.vue
+++ b/app/javascript/dashboard/components-next/message/bubbles/Text/Index.vue
@@ -12,7 +12,7 @@ import { useMessageContext } from '../../provider.js';
import { useTranslations } from 'dashboard/composables/useTranslations';
const TEXT_SHIMMER_CLASS =
- 'bg-clip-text bg-gradient-to-r from-n-slate-11 from-35% via-n-iris-10 to-n-slate-11 to-65% bg-[length:300%_100%] animate-text-shimmer motion-reduce:animate-none [&_*]:!text-transparent [&_*]:!bg-transparent';
+ 'bg-clip-text bg-gradient-to-r from-n-iris-9 from-25% via-n-iris-12 to-n-iris-9 to-75% dark:from-n-slate-12 dark:from-35% dark:via-n-iris-10 dark:to-n-slate-12 dark:to-65% bg-[length:300%_100%] animate-text-shimmer motion-reduce:animate-none [&_*]:!text-transparent [&_*]:!bg-transparent';
const HEIGHT_MORPH = {
duration: 300,
easing: 'cubic-bezier(0.2, 0.8, 0.2, 1)',
diff --git a/app/javascript/dashboard/components-next/message/specs/TranslationToggle.spec.js b/app/javascript/dashboard/components-next/message/specs/TranslationToggle.spec.js
index 6021efd70a0..1569d154783 100644
--- a/app/javascript/dashboard/components-next/message/specs/TranslationToggle.spec.js
+++ b/app/javascript/dashboard/components-next/message/specs/TranslationToggle.spec.js
@@ -25,7 +25,6 @@ const mountToggle = ({
messageType = MESSAGE_TYPES.INCOMING,
contactSide = messageType === MESSAGE_TYPES.INCOMING,
hasTranslations = false,
- groupedWithNext = false,
language = 'French',
state = {},
showingOriginal = false,
@@ -48,7 +47,6 @@ const mountToggle = ({
contentAttributes: ref({}),
messageType: ref(messageType),
contactSide: ref(contactSide),
- shouldGroupWithNext: ref(groupedWithNext),
});
},
template: `<TranslationToggle :showing-original="${showingOriginal}" />`,
@@ -108,23 +106,13 @@ describe('TranslationToggle', () => {
expect(outgoing.text()).toContain('CONVERSATION.TRANSLATING_TO');
});
- it('says when a message is already in the agent language', () => {
+ it('shows nothing for a message already in the agent language', () => {
const wrapper = mountToggle({
hasTranslations: true,
state: { sameLanguage: true },
});
- expect(wrapper.text()).toContain('CONVERSATION.ALREADY_IN_LANGUAGE');
- expect(wrapper.text()).not.toContain('CONVERSATION.VIEW_ORIGINAL');
- });
-
- it('shows the same-language line only on the last message of a group', () => {
- const grouped = mountToggle({
- state: { sameLanguage: true },
- groupedWithNext: true,
- });
-
- expect(grouped.find('span').exists()).toBe(false);
+ expect(wrapper.find('span').exists()).toBe(false);
});
it('warns when a reply could not be translated', () => {
diff --git a/app/javascript/dashboard/i18n/locale/en/conversation.json b/app/javascript/dashboard/i18n/locale/en/conversation.json
index 24f95bbd655..d26d82a8325 100644
--- a/app/javascript/dashboard/i18n/locale/en/conversation.json
+++ b/app/javascript/dashboard/i18n/locale/en/conversation.json
@@ -25,7 +25,6 @@
"TRANSLATING_TO": "Translating to {language}…",
"VIEW_ORIGINAL_IN": "View original ({language})",
"VIEW_TRANSLATED_IN": "View translated ({language})",
- "ALREADY_IN_LANGUAGE": "Already in {language}",
"TRANSLATION_FAILED": "Could not translate, sent as typed",
"CONTACT_TRANSLATION_FAILED": "Could not translate",
"EMPTY_STATE": {
diff --git a/app/javascript/dashboard/store/modules/conversations/getters.js b/app/javascript/dashboard/store/modules/conversations/getters.js
index d3d3a171049..d7760b5582a 100644
--- a/app/javascript/dashboard/store/modules/conversations/getters.js
+++ b/app/javascript/dashboard/store/modules/conversations/getters.js
@@ -255,13 +255,6 @@ const getters = {
(message.status === MESSAGE_STATUS.PROGRESS &&
!message.private &&
!attributes.forwarded_message_id);
- // The own text stored as the translation marks a message already in the agent language; once a translated
- // thread switched to the agent language, its untranslated messages are in it too.
- const alreadyInAgentLanguage = translation
- ? translation === message.content
- : sameLanguage &&
- messages.some(item => item.content_attributes?.translations);
-
return {
pending:
enabled &&
@@ -270,8 +263,9 @@ const getters = {
!attributes.translation_failed &&
waiting,
failed: enabled && !!attributes.translation_failed,
+ // A message already in the agent language is stored with its own text as the translation.
sameLanguage:
- enabled && translatable && !foreign && alreadyInAgentLanguage,
+ enabled && translatable && !foreign && translation === message.content,
sourceLanguage: attributes.source_language
? languageName(attributes.source_language)
: language,
diff --git a/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js b/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js
index b6c7c0393f4..f3219d7bb31 100644
--- a/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js
+++ b/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js
@@ -1084,42 +1084,6 @@ describe('#getters', () => {
});
});
- it('treats untranslated messages of a translated thread that switched to the agent language as already in it', () => {
- const messages = [
- {
- id: 1,
- message_type: 0,
- content_type: 'text',
- content: 'ok thanks',
- content_attributes: {},
- },
- {
- id: 2,
- message_type: 0,
- content_type: 'text',
- content: 'Bonjour',
- content_attributes: { translations: { en: 'Hello' } },
- },
- ];
- const translationState = getters.getMessageTranslationState(
- { autoTranslating: {} },
- {
- getAutoTranslate: {
- enabled: true,
- locale: 'en',
- language: 'English',
- sameLanguage: true,
- },
- getSelectedChat: { messages },
- }
- );
-
- expect(translationState(1)).toMatchObject({
- pending: false,
- sameLanguage: true,
- });
- });
-
it('reports a reply the backend could not translate', () => {
const translationState = stateFor([
{