mirror of https://github.com/wg-easy/wg-easy
13 changed files with 47 additions and 39 deletions
@ -1,24 +1,18 @@ |
|||||
// https://i18n.nuxtjs.org/docs/guide/server-side-translations
|
|
||||
// Detect based on query, cookie, header
|
|
||||
export default defineI18nLocaleDetector((event, config) => { |
export default defineI18nLocaleDetector((event, config) => { |
||||
// try to get locale from query
|
const query = tryQueryLocale(event, { lang: '' }); |
||||
const query = tryQueryLocale(event, { lang: '' }); // disable locale default value with `lang` option
|
|
||||
if (query) { |
if (query) { |
||||
return query.toString(); |
return query.toString(); |
||||
} |
} |
||||
|
|
||||
// try to get locale from cookie
|
const cookie = tryCookieLocale(event, { lang: '', name: 'i18n_locale' }); |
||||
const cookie = tryCookieLocale(event, { lang: '', name: 'i18n_locale' }); // disable locale default value with `lang` option
|
|
||||
if (cookie) { |
if (cookie) { |
||||
return cookie.toString(); |
return cookie.toString(); |
||||
} |
} |
||||
|
|
||||
// try to get locale from header (`accept-header`)
|
const header = tryHeaderLocale(event, { lang: '' }); |
||||
const header = tryHeaderLocale(event, { lang: '' }); // disable locale default value with `lang` option
|
|
||||
if (header) { |
if (header) { |
||||
return header.toString(); |
return header.toString(); |
||||
} |
} |
||||
|
|
||||
// If the locale cannot be resolved up to this point, it is resolved with the value `defaultLocale` of the locale config passed to the function
|
|
||||
return config.defaultLocale; |
return config.defaultLocale; |
||||
}); |
}); |
||||
|
|||||
@ -1,4 +1,4 @@ |
|||||
export default defineEventHandler(async (event) => { |
export default defineEventHandler((event) => { |
||||
setHeader(event, 'Content-Type', 'application/json'); |
setHeader(event, 'Content-Type', 'application/json'); |
||||
return Database.getLang(); |
return Database.getLang(); |
||||
}); |
}); |
||||
|
|||||
Loading…
Reference in new issue