wip
This commit is contained in:
		
							parent
							
								
									e0f3c39b75
								
							
						
					
					
						commit
						c5b8ff0c1f
					
				|  | @ -0,0 +1,51 @@ | |||
| <!-- | ||||
| SPDX-FileCopyrightText: syuilo and misskey-project | ||||
| SPDX-License-Identifier: AGPL-3.0-only | ||||
| --> | ||||
| 
 | ||||
| <template> | ||||
| <render/> | ||||
| </template> | ||||
| 
 | ||||
| <script setup lang="ts" generic="T extends string | ParameterizedString"> | ||||
| import { computed, h } from 'vue'; | ||||
| import type { ParameterizedString } from '../../../../../locales/index.js'; | ||||
| 
 | ||||
| const props = withDefaults(defineProps<{ | ||||
| 	src: T; | ||||
| 	tag?: string; | ||||
| 	// eslint-disable-next-line vue/require-default-prop | ||||
| 	textTag?: string; | ||||
| }>(), { | ||||
| 	tag: 'span', | ||||
| }); | ||||
| 
 | ||||
| const slots = defineSlots<T extends ParameterizedString<infer R> ? { [K in R]: () => unknown } : NonNullable<unknown>>(); | ||||
| 
 | ||||
| const parsed = computed(() => { | ||||
| 	let str = props.src as string; | ||||
| 	const value: (string | { arg: string; })[] = []; | ||||
| 	for (;;) { | ||||
| 		const nextBracketOpen = str.indexOf('{'); | ||||
| 		const nextBracketClose = str.indexOf('}'); | ||||
| 
 | ||||
| 		if (nextBracketOpen === -1) { | ||||
| 			value.push(str); | ||||
| 			break; | ||||
| 		} else { | ||||
| 			if (nextBracketOpen > 0) value.push(str.substring(0, nextBracketOpen)); | ||||
| 			value.push({ | ||||
| 				arg: str.substring(nextBracketOpen + 1, nextBracketClose), | ||||
| 			}); | ||||
| 		} | ||||
| 
 | ||||
| 		str = str.substring(nextBracketClose + 1); | ||||
| 	} | ||||
| 
 | ||||
| 	return value; | ||||
| }); | ||||
| 
 | ||||
| const render = () => { | ||||
| 	return h(props.tag, parsed.value.map(x => typeof x === 'string' ? (props.textTag ? h(props.textTag, x) : x) : slots[x.arg]())); | ||||
| }; | ||||
| </script> | ||||
|  | @ -0,0 +1,18 @@ | |||
| /* | ||||
|  * SPDX-FileCopyrightText: syuilo and misskey-project | ||||
|  * SPDX-License-Identifier: AGPL-3.0-only | ||||
|  */ | ||||
| 
 | ||||
| const address = new URL(document.querySelector<HTMLMetaElement>('meta[property="instance_url"]')?.content || location.href); | ||||
| const siteName = document.querySelector<HTMLMetaElement>('meta[property="og:site_name"]')?.content; | ||||
| 
 | ||||
| export const host = address.host; | ||||
| export const hostname = address.hostname; | ||||
| export const url = address.origin; | ||||
| export const apiUrl = location.origin + '/api'; | ||||
| export const langs = _LANGS_; | ||||
| const preParseLocale = miLocalStorage.getItem('locale'); | ||||
| export const locale = preParseLocale ? JSON.parse(preParseLocale) : null; | ||||
| export const instanceName = siteName === 'Misskey' || siteName == null ? host : siteName; | ||||
| export const ui = miLocalStorage.getItem('ui'); | ||||
| export const debug = miLocalStorage.getItem('debug') === 'true'; | ||||
|  | @ -0,0 +1,15 @@ | |||
| /* | ||||
|  * SPDX-FileCopyrightText: syuilo and misskey-project | ||||
|  * SPDX-License-Identifier: AGPL-3.0-only | ||||
|  */ | ||||
| 
 | ||||
| import { markRaw } from 'vue'; | ||||
| import type { Locale } from '../../../locales/index.js'; | ||||
| import { locale } from '@/config.js'; | ||||
| import { I18n } from '@/scripts/i18n.js'; | ||||
| 
 | ||||
| export const i18n = markRaw(new I18n<Locale>(locale)); | ||||
| 
 | ||||
| export function updateI18n(newLocale: Locale) { | ||||
| 	i18n.locale = newLocale; | ||||
| } | ||||
		Loading…
	
		Reference in New Issue