<template>
<div class="app">
<header>
<h1>{{ appTitle }}</h1>
<select v-model="currentLanguage" @change="changeLanguage">
<option v-for="lang in languages" :key="lang.code" :value="lang.code">
{{ lang.name }}
</option>
</select>
</header>
<main>
<h2>{{ welcomeMessage }}</h2>
<p>{{ description }}</p>
<button>{{ ctaButton }}</button>
</main>
</div>
</template>
<script setup>
import { ref, onMounted, watch } from 'vue';
import StringBoot from '@stringboot/web-sdk';
const appTitle = ref('');
const welcomeMessage = ref('');
const description = ref('');
const ctaButton = ref('');
const currentLanguage = ref('en');
const languages = ref([]);
onMounted(async () => {
// Initialize StringBoot
await StringBoot.initialize({
apiToken: import.meta.env.VITE_STRINGBOOT_TOKEN,
baseUrl: 'https://api.stringboot.com',
defaultLanguage: 'en'
});
// Load available languages
languages.value = await StringBoot.getAvailableLanguages();
// Load initial strings
await loadStrings();
});
async function loadStrings() {
appTitle.value = await StringBoot.get('app_title');
welcomeMessage.value = await StringBoot.get('welcome_message');
description.value = await StringBoot.get('description');
ctaButton.value = await StringBoot.get('cta_button');
}
async function changeLanguage() {
await StringBoot.changeLanguage(currentLanguage.value);
await loadStrings();
}
// Watch for language changes
watch(currentLanguage, async (newLang) => {
await StringBoot.changeLanguage(newLang);
await loadStrings();
});
</script>