Spaces:
Sleeping
Sleeping
Keldos commited on
Commit ·
701dfa6
1
Parent(s): 677b142
feat: add js web locale method
Browse files- assets/custom.js +21 -0
assets/custom.js
CHANGED
|
@@ -29,6 +29,15 @@ var historyLoaded = false;
|
|
| 29 |
var ga = document.getElementsByTagName("gradio-app");
|
| 30 |
var targetNode = ga[0];
|
| 31 |
var isInIframe = (window.self !== window.top);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
// gradio 页面加载好了么??? 我能动你的元素了么??
|
| 34 |
function gradioLoaded(mutations) {
|
|
@@ -82,6 +91,17 @@ function gradioLoaded(mutations) {
|
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
function selectHistory() {
|
| 86 |
user_input_ta = user_input_tb.querySelector("textarea");
|
| 87 |
if (user_input_ta) {
|
|
@@ -516,6 +536,7 @@ function loadHistoryHtml() {
|
|
| 516 |
var fakeHistory = document.createElement('div');
|
| 517 |
fakeHistory.classList.add('history-message');
|
| 518 |
fakeHistory.innerHTML = tempDiv.innerHTML;
|
|
|
|
| 519 |
chatbotWrap.insertBefore(fakeHistory, chatbotWrap.firstChild);
|
| 520 |
// var fakeHistory = document.createElement('div');
|
| 521 |
// fakeHistory.classList.add('history-message');
|
|
|
|
| 29 |
var ga = document.getElementsByTagName("gradio-app");
|
| 30 |
var targetNode = ga[0];
|
| 31 |
var isInIframe = (window.self !== window.top);
|
| 32 |
+
var language = navigator.language.slice(0,2);
|
| 33 |
+
|
| 34 |
+
var forView_i18n = {
|
| 35 |
+
'zh': "仅供查看",
|
| 36 |
+
'en': "For viewing only",
|
| 37 |
+
'ja': "閲覧専用",
|
| 38 |
+
'fr': "Pour consultation seulement",
|
| 39 |
+
'es': "Solo para visualización",
|
| 40 |
+
};
|
| 41 |
|
| 42 |
// gradio 页面加载好了么??? 我能动你的元素了么??
|
| 43 |
function gradioLoaded(mutations) {
|
|
|
|
| 91 |
}
|
| 92 |
}
|
| 93 |
|
| 94 |
+
function webLocale() {
|
| 95 |
+
console.log("webLocale", language);
|
| 96 |
+
if (forView_i18n.hasOwnProperty(language)) {
|
| 97 |
+
var forView = forView_i18n[language];
|
| 98 |
+
var forViewStyle = document.createElement('style');
|
| 99 |
+
forViewStyle.innerHTML = '.wrap>.history-message>:last-child::after { content: "' + forView + '"!important; }';
|
| 100 |
+
document.head.appendChild(forViewStyle);
|
| 101 |
+
console.log("added forViewStyle", forView);
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
function selectHistory() {
|
| 106 |
user_input_ta = user_input_tb.querySelector("textarea");
|
| 107 |
if (user_input_ta) {
|
|
|
|
| 536 |
var fakeHistory = document.createElement('div');
|
| 537 |
fakeHistory.classList.add('history-message');
|
| 538 |
fakeHistory.innerHTML = tempDiv.innerHTML;
|
| 539 |
+
webLocale();
|
| 540 |
chatbotWrap.insertBefore(fakeHistory, chatbotWrap.firstChild);
|
| 541 |
// var fakeHistory = document.createElement('div');
|
| 542 |
// fakeHistory.classList.add('history-message');
|