(context: GitBookAnyContext)
| 36 | * Create the translation context for a space to use in the server components. |
| 37 | */ |
| 38 | export function getSpaceLanguage(context: GitBookAnyContext): TranslationLanguage { |
| 39 | const fallback = languages[DEFAULT_LOCALE]; |
| 40 | |
| 41 | const locale = getSpaceLocale(context); |
| 42 | |
| 43 | let language = fallback; |
| 44 | // @ts-ignore |
| 45 | if (locale !== DEFAULT_LOCALE && languages[locale]) { |
| 46 | // @ts-ignore |
| 47 | language = languages[locale]; |
| 48 | } |
| 49 | |
| 50 | return { |
| 51 | ...fallback, |
| 52 | ...language, |
| 53 | }; |
| 54 | } |
| 55 | |
| 56 | function checkIsValidLocale(locale: string): locale is TranslationLocale { |
| 57 | return locale in languages; |
no test coverage detected