Skip to content

Instantly share code, notes, and snippets.

@ManUtopiK
Created July 6, 2022 19:45
Show Gist options
  • Save ManUtopiK/d99993adf74f21cd9a103d2c2fa06c65 to your computer and use it in GitHub Desktop.
Save ManUtopiK/d99993adf74f21cd9a103d2c2fa06c65 to your computer and use it in GitHub Desktop.
uselocation.ts
import type { Ref } from 'vue';
export const useLang: () => Ref<string> = () => {
if (process.client) {
return ref(navigator.language);
}
const parseLangString: (languages: string) => string = (languages) => {
return languages.split(',')[0];
};
const nuxt = useNuxtApp();
const lang: string = parseLangString(
nuxt.ssrContext.event.req.headers['accept-language']
);
return ref(lang);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment