mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-09 14:03:20 +09:00
1 parent
7fd7553d0e
commit
04981004d0
2 files changed
+17
-15
No files matched your search
@@ -15,12 +15,13 @@
|
||||
|
||||
import React, { useContext, useState, useEffect, createContext } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import root from 'window-or-global'
|
||||
import { Select } from '@material-ui/core'
|
||||
import { sprintf } from 'sprintf-js'
|
||||
import { DEFAULT_LANGUAGE, LANGUAGES_URL } from 'client/constants'
|
||||
|
||||
const TranslateContext = createContext()
|
||||
let languageScript = document?.createElement('script')
|
||||
let languageScript = root.document?.createElement('script')
|
||||
|
||||
const GenerateScript = (
|
||||
language = DEFAULT_LANGUAGE,
|
||||
@@ -28,14 +29,14 @@ const GenerateScript = (
|
||||
setHash = () => undefined
|
||||
) => {
|
||||
try {
|
||||
const script = window.document.createElement('script')
|
||||
const script = root.document.createElement('script')
|
||||
script.src = `${LANGUAGES_URL}/${language}.js`
|
||||
script.async = true
|
||||
script.onload = () => {
|
||||
setLang(language)
|
||||
setHash(window.locale)
|
||||
setHash(root.locale)
|
||||
}
|
||||
window.document.body.appendChild(script)
|
||||
root.document.body.appendChild(script)
|
||||
languageScript = script
|
||||
} catch (error) {
|
||||
console.warn('Error while generating script language')
|
||||
@@ -43,7 +44,7 @@ const GenerateScript = (
|
||||
}
|
||||
|
||||
const RemoveScript = () => {
|
||||
window.document.body.removeChild(languageScript)
|
||||
root.document.body.removeChild(languageScript)
|
||||
}
|
||||
|
||||
const TranslateProvider = ({ children }) => {
|
||||
@@ -104,7 +105,7 @@ const Tr = (str = '') => {
|
||||
|
||||
const SelectTranslate = () => {
|
||||
const context = useContext(TranslateContext)
|
||||
const languages = Array.isArray(window?.langs) ? window?.langs : []
|
||||
const languages = Array.isArray(root?.langs) ? root?.langs : []
|
||||
|
||||
const handleChange = (e, changeLang) => {
|
||||
if (e?.target?.value && typeof changeLang === 'function') {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import axios from 'axios'
|
||||
import root from 'window-or-global'
|
||||
|
||||
import { JWT_NAME } from 'client/constants'
|
||||
import { messageTerminal } from 'server/utils/general'
|
||||
@@ -23,7 +24,7 @@ import { defaultAppName } from 'server/utils/constants/defaults'
|
||||
const defaultData = {
|
||||
data: {},
|
||||
json: true,
|
||||
baseURL: window?.location?.origin?.concat(`/${defaultAppName}`) ?? '',
|
||||
baseURL: root?.location?.origin?.concat(`/${defaultAppName}`) ?? '',
|
||||
method: 'GET',
|
||||
authenticate: true,
|
||||
onUploadProgress: null,
|
||||
@@ -33,8 +34,8 @@ const defaultData = {
|
||||
export const storage = (name = '', data = '', keepData = false) => {
|
||||
if (name && data) {
|
||||
keepData
|
||||
? window?.localStorage?.setItem(name, data)
|
||||
: window?.sessionStorage?.setItem(name, data)
|
||||
? root?.localStorage?.setItem(name, data)
|
||||
: root?.sessionStorage?.setItem(name, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,16 +43,16 @@ export const removeStoreData = (items = []) => {
|
||||
const itemsToRemove = !Array.isArray(items) ? [items] : items
|
||||
|
||||
itemsToRemove.forEach(item => {
|
||||
window?.localStorage?.removeItem(item)
|
||||
window?.sessionStorage?.removeItem(item)
|
||||
root?.localStorage?.removeItem(item)
|
||||
root?.sessionStorage?.removeItem(item)
|
||||
})
|
||||
}
|
||||
|
||||
export const findStorageData = (name = '') => {
|
||||
if (name && window?.localStorage.getItem(name)) {
|
||||
return window.localStorage.getItem(name)
|
||||
} else if (name && window?.sessionStorage.getItem(name)) {
|
||||
return window.sessionStorage.getItem(name)
|
||||
if (name && root?.localStorage.getItem(name)) {
|
||||
return root.localStorage.getItem(name)
|
||||
} else if (name && root?.sessionStorage.getItem(name)) {
|
||||
return root.sessionStorage.getItem(name)
|
||||
} else return false
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user