Skip to content

Translations in API routes (app directory) #368

Answered by amannn
chtibizoux asked this question in Q&A
Discussion options

You must be logged in to vote

resolveLocale is currently not intended to be exported. You can receive the locale in your Route Handler by accepting it either as a route param or search param to be called accordingly from the client side (e.g. /api/hello?locale=en or /en/api/hello).

If you want to resolve the locale based on the accept-language header, you can use the same code that we use in the middleware (it's really not much):

const languages = new Negotiator({
headers: {
'accept-language': requestHeaders.get('accept-language') || undefined
}
}).languages();
try {
locale = match(languages,

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@proccedure-caze
Comment options

@amannn
Comment options

@kamranayub
Comment options

@amannn
Comment options

@kamranayub
Comment options

Answer selected by chtibizoux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
enhancement New feature or request unconfirmed Needs triage.
4 participants
Converted from issue

This discussion was converted from issue #367 on June 29, 2023 15:25.