|  | 
|  | 1 | +<template> | 
|  | 2 | +  <div> | 
|  | 3 | +    <h1>Test $loadPageTranslations Method</h1> | 
|  | 4 | + | 
|  | 5 | +    <div> | 
|  | 6 | +      <h2>Current Locale: {{ $getLocale() }}</h2> | 
|  | 7 | +      <h2>Route Name: {{ $getRouteName() }}</h2> | 
|  | 8 | +    </div> | 
|  | 9 | + | 
|  | 10 | +    <div> | 
|  | 11 | +      <h3>Translations before loading:</h3> | 
|  | 12 | +      <p>test_key: {{ $t('test_key') || 'NOT FOUND' }}</p> | 
|  | 13 | +      <p>dynamic_key: {{ $t('dynamic_key') || 'NOT FOUND' }}</p> | 
|  | 14 | +    </div> | 
|  | 15 | + | 
|  | 16 | +    <div> | 
|  | 17 | +      <button @click="loadTestTranslations"> | 
|  | 18 | +        Load Test Translations | 
|  | 19 | +      </button> | 
|  | 20 | +    </div> | 
|  | 21 | + | 
|  | 22 | +    <div v-if="translationsLoaded"> | 
|  | 23 | +      <h3>Translations after loading:</h3> | 
|  | 24 | +      <p>test_key: {{ $t('test_key') }}</p> | 
|  | 25 | +      <p>dynamic_key: {{ $t('dynamic_key') }}</p> | 
|  | 26 | +      <p>nested.key: {{ $t('nested.key') }}</p> | 
|  | 27 | +    </div> | 
|  | 28 | + | 
|  | 29 | +    <div> | 
|  | 30 | +      <h3>Check translation existence:</h3> | 
|  | 31 | +      <p>has test_key: {{ $has('test_key') }}</p> | 
|  | 32 | +      <p>has dynamic_key: {{ $has('dynamic_key') }}</p> | 
|  | 33 | +      <p>has nested.key: {{ $has('nested.key') }}</p> | 
|  | 34 | +    </div> | 
|  | 35 | +  </div> | 
|  | 36 | +</template> | 
|  | 37 | + | 
|  | 38 | +<script setup lang="ts"> | 
|  | 39 | +import { useNuxtApp } from '#imports' | 
|  | 40 | +
 | 
|  | 41 | +const { $getLocale, $getRouteName, $t, $has, $loadPageTranslations } = useNuxtApp() | 
|  | 42 | +
 | 
|  | 43 | +const translationsLoaded = ref(false) | 
|  | 44 | +
 | 
|  | 45 | +const loadTestTranslations = async () => { | 
|  | 46 | +  const currentLocale = $getLocale() | 
|  | 47 | +  const routeName = $getRouteName() | 
|  | 48 | +
 | 
|  | 49 | +  const testTranslations = { | 
|  | 50 | +    test_key: `Test key for ${currentLocale}`, | 
|  | 51 | +    dynamic_key: `Dynamic key loaded at ${new Date().toLocaleTimeString()}`, | 
|  | 52 | +    nested: { | 
|  | 53 | +      key: `Nested key for ${currentLocale}`, | 
|  | 54 | +    }, | 
|  | 55 | +  } | 
|  | 56 | +
 | 
|  | 57 | +  try { | 
|  | 58 | +    await $loadPageTranslations(currentLocale, routeName, testTranslations) | 
|  | 59 | +    translationsLoaded.value = true | 
|  | 60 | +    console.log('Translations loaded successfully:', testTranslations) | 
|  | 61 | +  } | 
|  | 62 | +  catch (error) { | 
|  | 63 | +    console.error('Error loading translations:', error) | 
|  | 64 | +  } | 
|  | 65 | +} | 
|  | 66 | +
 | 
|  | 67 | +// Check if method is available | 
|  | 68 | +onMounted(() => { | 
|  | 69 | +  console.log('$loadPageTranslations method is available:', typeof $loadPageTranslations === 'function') | 
|  | 70 | +}) | 
|  | 71 | +</script> | 
0 commit comments