Translate iframe
You have an iframe in your page and you need to translate it.

Pre-required

You need to have the iframe control to put Weglot snippet on the iframe.
If you cannot put the snippet in the iframe, please contact us, we surely have another solutions for you.

Setup

The parent window (main page) got the Weglot snippet to initialize it and there is a switcher on this page.
1) You have to put the same snippet in your iframe page, with the hide_switcher extra option to true, because you don't want another switcher in your iframe:
1
<script src="https://cdn.weglot.com/weglot.min.js"></script>
2
<script>
3
// In your iframe
4
Weglot.initialize({
5
api_key: "wg_xxxx",
6
hide_switcher: true // You already have a switcher in parent window
7
});
8
</script>
Copied!
2) Add translate_iframes option with all CSS selectors in an array to select translated iframe in your page.
1
<script src="https://cdn.weglot.com/weglot.min.js"></script>
2
<script>
3
// In your parent window
4
Weglot.initialize({
5
api_key: "wg_xxxx",
6
translate_iframes: ["#iframe-id", ".my-little-iframe"]
7
});
8
</script>
9
Copied!
Now, the parent window can communicate with your iframe, mainly to switch language when user select a new one.

Tips

    You can add iframes selectors option all over your website, if selector is wrong or iframe doesn't exist, it doesn't matter
    Visiting a page with a translated iframe on it will count two visits on your dashboard (parent + iframe)
Last modified 2mo ago
Copy link