Skip to main content

useAsgardeoI18n()

useAsgardeoI18n() returns the translation function and language settings of the WSO2 Identity Platform Nuxt SDK (@asgardeo/nuxt) UI.

Overview​

useAsgardeoI18n() is the useI18n() composable of @asgardeo/vue. The module auto-imports it as useAsgardeoI18n so that it doesn't collide with useI18n() from @nuxtjs/i18n.

<AsgardeoRoot> configures it with the preferences.i18n module option. See Module configuration.

note

Call useAsgardeoI18n() only in components that render inside <AsgardeoRoot>. Otherwise, it throws an error.

Usage​

<script setup lang="ts">
const { t, currentLanguage, setLanguage } = useAsgardeoI18n();
</script>

<template>
<p>{{ t('signin.heading') }} ({{ currentLanguage }})</p>
<button @click="setLanguage('fr-FR')">Français</button>
</template>

API​

PropertyTypeDescription
t(key, params?)(key: string, params?: Record<string, string | number>) => stringTranslates a key, with optional named parameters.
currentLanguageReadonly<Ref<string>>The current language code, for example 'en-US'.
fallbackLanguagestringThe language used when a translation is missing.
bundlesReadonly<Ref<Record<string, I18nBundle>>>All available translation bundles.
setLanguage(language)(language: string) => voidChanges the current language.
injectBundles(bundles)(bundles: Record<string, I18nBundle>) => voidAdds translation bundles. Injected bundles override the defaults, and bundles from preferences.i18n.bundles override injected bundles.

Was this page helpful?