nuxt-google-translate
Version:
A simple Nuxt module that integrates the Google Translate widget into your Nuxt.js application, allowing seamless multilingual support without requiring an API key.
74 lines (65 loc) • 1.66 kB
TypeScript
/**
* Configuration options for the Nuxt Google Translate module
*/
export interface GoogleTranslateOptions {
/**
* The default language for the translation
* @default 'en'
*/
defaultLanguage: string
/**
* Array of supported language codes
* @default ['ar', 'cs', 'da', 'en', 'fi', 'fr', 'gu', 'hi', 'id', 'it', 'ja', 'ko', 'sk', 'sv', 'th', 'tr', 'uk', 'vi']
*/
supportedLanguages: string[]
}
/**
* Configuration for Google Translate Element
*/
export interface GoogleTranslateConfig {
pageLanguage: string
includedLanguages?: string
layout: string
autoDisplay: boolean
}
/**
* Interface for the Google Translate functionality provided by the plugin
*/
export interface GoogleTranslatePlugin {
/**
* The currently active language
*/
activeLanguage: Ref<string>
/**
* Array of supported language codes
*/
supportedLanguages: readonly string[]
/**
* Function to set the active language
* @param lang - The language code to set
*/
setLanguage: (lang: string) => void
/**
* Indicates whether the Google Translate script has been loaded
*/
isLoaded: Ref<boolean>
}
/**
* Augment the runtime config to include GoogleTranslateOptions
*/
declare module '@nuxt/schema' {
interface RuntimeConfig {
googleTranslate?: GoogleTranslateOptions
}
interface PublicRuntimeConfig {
googleTranslate?: GoogleTranslateOptions
}
}
/**
* Augment the Nuxt app to include the Google Translate plugin
*/
declare module '#app' {
interface NuxtApp {
$googleTranslate: GoogleTranslatePlugin
}
}