12
This commit is contained in:
@@ -34,37 +34,46 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useSettingsStore } from 'stores/settings'
|
||||
|
||||
const fileText = ref<string>('')
|
||||
const isLoading = ref<boolean>(true)
|
||||
const error = ref<boolean>(false)
|
||||
const settingsStore = useSettingsStore()
|
||||
const lang = ref<string>('EN')
|
||||
|
||||
const props = defineProps<{
|
||||
type: 'terms_of_use' | 'privacy'
|
||||
}>()
|
||||
|
||||
function parseLocale(locale: string): string {
|
||||
return locale.split(/[-_]/)[0] ?? ''
|
||||
const settingsStore = useSettingsStore()
|
||||
const fileText = ref<string | null>('')
|
||||
const isLoading = ref(true)
|
||||
const DEFAULT_LANG = 'ru'
|
||||
|
||||
const baseDocName = props.type === 'terms_of_use'
|
||||
? 'Terms_of_use'
|
||||
: 'Privacy'
|
||||
|
||||
const parseLocale = (locale: string) => locale.split(/[-_]/)[0] || DEFAULT_LANG
|
||||
|
||||
const fetchDocument = async (language: string) => {
|
||||
try {
|
||||
const response = await fetch(`/admin/doc/${baseDocName}_${language}.txt`)
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
||||
return await response.text()
|
||||
} catch (error) {
|
||||
console.error(`Failed to load ${language} version:`, error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const baseDocName =
|
||||
props.type ==='terms_of_use' ? 'Terms_of_use' : 'Privacy'
|
||||
|
||||
onMounted(async () => {
|
||||
const locale = settingsStore.settings.locale
|
||||
lang.value = parseLocale(locale)
|
||||
try {
|
||||
const response = await fetch('/admin/doc/' + baseDocName + '_' + lang.value +'.txt')
|
||||
const lang = parseLocale(settingsStore.settings.locale)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`)
|
||||
fileText.value = await fetchDocument(lang)
|
||||
|
||||
if (!fileText.value && lang !== DEFAULT_LANG) {
|
||||
fileText.value = await fetchDocument(DEFAULT_LANG)
|
||||
}
|
||||
|
||||
fileText.value = await response.text()
|
||||
} catch (err) {
|
||||
console.error('File load error:', err)
|
||||
error.value = true
|
||||
if (!fileText.value) throw new Error('All loading attempts failed')
|
||||
|
||||
} catch (error) {
|
||||
console.error('Document loading failed:', error)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user