-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathapp-router-context.ts
More file actions
48 lines (42 loc) · 1.24 KB
/
app-router-context.ts
File metadata and controls
48 lines (42 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { getUIDataMerged } from '@/data-directory/lib/get-data'
import { type LanguageCode } from '@/languages/lib/languages'
import { translate } from '@/languages/lib/translation-utils'
import { extractLanguageFromPath } from '@/app/lib/language-utils'
import { type UIStrings } from '@/frame/components/context/MainContext'
export interface AppRouterContext {
currentLanguage: LanguageCode
currentVersion: string
sitename: string
site: {
data: {
ui: UIStrings
}
}
}
/**
* Create App Router context from pathname
*/
export function createAppRouterContext(
pathname: string = '/',
fallbackLanguage?: LanguageCode,
): AppRouterContext {
let language = extractLanguageFromPath(pathname)
// Use fallback if provided and URL doesn't specify language
if (language === 'en' && fallbackLanguage && fallbackLanguage !== 'en') {
language = fallbackLanguage
}
const version = 'free-pro-team@latest'
// Load UI data directly from data directory
const uiData = getUIDataMerged(language)
const siteName = translate(uiData, 'header.github_docs', 'GitHub Docs')
return {
currentLanguage: language,
currentVersion: version,
sitename: siteName,
site: {
data: {
ui: uiData,
},
},
}
}