【问题标题】:Iframe translation – how do I create a dictionary with values and override text valuesiframe 翻译 – 如何创建带有值的字典并覆盖文本值
【发布时间】:2021-09-27 12:18:36
【问题描述】:

我正在尝试将 iframe(Goorgias 实时聊天)翻译成英语以外的其他语言(葡萄牙语、意大利语和西班牙语)。此 iframe 已在网上商店中实现。

有人告诉我准备一个包含 Weglot.translate 函数 (https://developers.weglot.com/javascript/javascript-functions) 值的字典,然后通过覆盖文本值将其传递给聊天。

<script>
var dict = {
    "introductionText": "How can we help?",
    "offlineIntroductionText": "We'll be back tomorrow",
    "actionPostbackError": "An error occurred while processing your action. Please try again.",
    "clickToRetry": "Message not delivered. Click to retry.",
    "conversationTimestampHeaderFormat": "MMMM D",
    "fetchHistory": "Load more",
    "fetchingHistory": "Retrieving history...",
    "invalidFileError": "Only images are supported. Choose a file with a supported extension (jpg, jpeg, png, gif, or bmp).",
    "messageError": "An error occurred while sending your message. Please try again.",
    "messageIndicatorTitlePlural": "({count}) New messages",
    "messageIndicatorTitleSingular": "({count}) New message",
    "messageRelativeTimeDay": "{value}d ago",
    "messageRelativeTimeHour": "{value}h ago",
    "messageRelativeTimeJustNow": "Just now",
    "messageRelativeTimeMinute": "{value}m ago",
    "messageTimestampFormat": "h:mm A",
    "messageSending": "Sending...",
    "messageDelivered": "Delivered",
    "tapToRetry": "Message not delivered. Tap to retry.",
    "unsupportedMessageType": "Unsupported message type.",
    "unsupportedActionType": "Unsupported action type.",
    "headerText": "Gorgias Team",
    "inputPlaceholder": "Type a message...",
    "emailCapturePlaceholder": "your@email.com",
    "emailCaptureInputLabel": "Get notified by email",
    "emailCaptureOnlineTriggerText": "Leave us your email and we will reply soon.",
    "emailCaptureOnlineThanksText": "Thanks! We'll email you at {email} if you leave.",
    "emailCaptureOfflineTriggerText": "We're away, leave us your email and we'll respond shortly.",
    "emailCaptureOfflineThanksText": "Thanks {email}! We'll get back to you shortly.",
    "emailCaptureRequiredEmailPlaceholder": "Leave your email",
    "emailCaptureRequiredMessagePlaceholder": "Write your message",
    "backLabelBackInAMinute": "Back in 1 minute",
    "backLabelBackInMinutes": "Back in {value} minutes",
    "backLabelBackInAnHour": "Back in 1 hour",
    "backLabelBackInHours": "Back in {value} hours",
    "backLabelBackInDays": "Back in {value} days",
    "backLabelBackTomorrow": "Back tomorrow",
    "campaignClickToReply": "Click to reply",
    "poweredByGorgias": "Powered by Gorgias",
    "send": "Send"
}

var gorgiasChatInterval = window.setInterval(function() {
    if (window.GorgiasChat && GorgiasChat.hasOwnProperty("updateTexts")) {
      window.clearInterval(gorgiasChatInterval); // this line breaks out of the loop - make sure it's not deleted.
      window.GORGIAS_CHAT_TEXTS = dict
      GorgiasChat.updateTexts(dict)
    }
}, 100);
</script>

(这是包含聊天文本的字典)

我该怎么写?

谢谢, 卡罗莱纳州

【问题讨论】:

  • 有什么问题?看起来你只是改变"introductionText": "Comment pouvons nous aider?",等等
  • 对,但是我需要的是根据网站的子域来改变内容。假设对于 fr.website.com,我们将有“introductionText”:“Comment pouvons nous aider?”对于 pt.website.com,我们会有 "introductionText": "Como posso ajudar?"等等。而且我需要根据我们所在的子域来更改 iframe 的内容。
  • 这是您问题中相当重要的缺失信息。
  • 为什么不使用built-in languages
  • 很遗憾,它不适用于不同的子域,只能用于不同的域。

标签: javascript dictionary iframe language-translation


【解决方案1】:

看看这个

const dicts = {
  "en": {
    "introductionText": "How can we help?",
    "offlineIntroductionText": "We'll be back tomorrow",
    "actionPostbackError": "An error occurred while processing your action. Please try again.",
    // ............
    "send": "Send"
  },
  "fr": {
    "introductionText": "Comment ....",
    "offlineIntroductionText": "Nous...",
    "actionPostbackError": "Un erreur ....",
    // ............
    "send": "Envoyer...."
  }
};
const url = new URL(location.href)
const lang = url.hostname.split(".")[0];
const dict = dicts[lang] || dicts["en"]; // take the english if no dict found for subdomain

console.log(dict)

/* here you have your gorgiasChatInterval code */

【讨论】:

  • 这里: const dict = dicts[lang] ||听写[“en”];我应该添加其他子域吗?
  • 没有。您将其他人添加到const dicts = { "en": {}, "fr": {}, "pt": {}},如果您需要另一个默认值,请将 dicts["en"] 更改为例如 dicts["pt"] - 如果您对 en 作为默认值感到满意,那么我的代码可以在您更改 @987654323 的情况下工作@
  • 我相信 iframe 没有响应代码——翻译没有发生。
  • 您删除了我的代码中的 cmets /**/,因为我没有 GorgiasChat 对吗?
  • 我确实删除了 cmets。还有什么我必须对 Gorgias 保密或我必须更改他们的代码的吗?
猜你喜欢
  • 1970-01-01
  • 2012-08-10
  • 2021-01-14
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
  • 2015-09-03
  • 2018-02-05
  • 1970-01-01
相关资源
最近更新 更多