-
Notifications
You must be signed in to change notification settings - Fork 8
/
GTranslateIO.vue
48 lines (40 loc) · 1.23 KB
/
GTranslateIO.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<script>
import Vue from "vue";
export default {
name: "gtranslate-io",
render() {
debugger
const isClient = typeof window !== "undefined";
if (isClient) {
var self = this;
const proto = window.location.protocol;
const path = window.location.pathname.split(this.$localePath).join("");
const host = location.host; // for the test
const url = `${proto}//${this.$lang}.${host}/${path}`;
debugger;
// gtranslate.io has ability to work via dns
fetch(url)
.then(response => {
if (!response.ok) {
return Promise.reject(new Error(response.statusText));
}
return response.text();
})
.then(text => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(text, "text/html");
const el = htmlDoc.getElementsByClassName("content")[0];
// debugger
const res = Vue.compile("<div>" + el.innerHTML + "</div>");
self.$options.render = res.render;
self.$options.staticRenderFns = res.staticRenderFns;
self.$forceUpdate();
})
.catch(err => {
debugger;
console.error(err);
});
}
}
};
</script>