-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathindex.tsx
More file actions
170 lines (149 loc) · 4.55 KB
/
index.tsx
File metadata and controls
170 lines (149 loc) · 4.55 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import { ReactElement, ReactNode } from 'react'
import type { NextConfig } from 'next'
export interface TranslationQuery {
[name: string]: any
}
export type DataForStoreType = {
lang: string
namespaces: Record<string, I18nDictionary>
config: LoaderConfig
}
export type Translate = <T extends unknown = string>(
i18nKey: string | TemplateStringsArray,
query?: TranslationQuery | null,
options?: {
returnObjects?: boolean
fallback?: string | string[]
default?: T | string
ns?: string
}
) => T
export interface I18n {
t: Translate
lang: string
}
export interface I18nProviderProps {
lang?: string
namespaces?: Record<string, I18nDictionary>
children?: ReactNode
config?: I18nConfig
}
export interface TransProps {
i18nKey: string
components?: ReactElement[] | Record<string, ReactElement>
values?: TranslationQuery
fallback?: string | string[]
defaultTrans?: string
ns?: string
}
export type PageValue = string[] | ((context: object) => string[])
export type LocaleLoader = (
language: string | undefined,
namespace: string
) => Promise<I18nDictionary>
// Makes the specified properties within a Typescript interface optional
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
// Built-in i18n Next.js options
export type RawNextI18nConfig = Exclude<NextConfig['i18n'], null | undefined>
export type NextI18nConfig = Optional<
RawNextI18nConfig,
'locales' | 'defaultLocale'
>
export interface I18nConfig extends NextI18nConfig {
loadLocaleFrom?: LocaleLoader
localesToIgnore?: string[]
pages?: Record<string, PageValue>
logger?: I18nLogger
loggerEnvironment?: 'node' | 'browser' | 'both'
staticsHoc?: Function
extensionsRgx?: string
loader?: boolean
logBuild?: boolean
revalidate?: number
pagesInDir?: string
interpolation?: {
format?: Function
prefix?: string
suffix?: string
}
keySeparator?: string | false
nsSeparator?: string | false
defaultNS?: string
allowEmptyStrings?: boolean
}
export interface LoaderConfig extends I18nConfig {
locale?: string
router?: { locale: string }
pathname?: string
skipInitialProps?: boolean
loaderName?: string
isLoader?: boolean
[key: string]: any
}
export interface LoggerProps {
namespace: string | undefined
i18nKey: string
isKeyConflictWithKeySeparator?: boolean
}
export interface I18nLogger {
(context: LoggerProps): void
}
export interface I18nDictionary {
[key: string]: string | I18nDictionary
}
export interface DynamicNamespacesProps {
dynamic?: LocaleLoader
namespaces?: string[]
fallback?: ReactNode
children?: ReactNode
}
declare global {
// For NodeJS 16+
// eslint-disable-next-line no-var
var i18nConfig: LoaderConfig
// eslint-disable-next-line no-var
var __NEXT_TRANSLATE__: {
namespaces: Record<string, I18nDictionary>
lang: string
pathname?: string
}
namespace NodeJS {
interface Global {
i18nConfig: LoaderConfig
__NEXT_TRANSLATE__: {
namespaces: Record<string, I18nDictionary>
lang: string
}
}
}
interface Window {
i18nConfig: LoaderConfig
__NEXT_TRANSLATE__: {
namespaces: Record<string, I18nDictionary>
lang: string
}
}
}
// TODO: Remove this in future versions > 2.0.0
function nextTranslate(nextConfig: NextConfig = {}): NextConfig {
console.log(`
#########################################################################
# #
# next-translate plugin in 2.0.0 is replaced by #
# next-translate-plugin package: #
# #
# > yarn add next-translate-plugin -D #
# or: #
# > npm install next-translate-plugin --save-dev #
# #
# replace in next.config.js file: #
# const nextTranslate = require('next-translate') #
# to: #
# const nextTranslate = require('next-translate-plugin') #
# #
#########################################################################
`)
return nextConfig
}
module.exports = nextTranslate
export default nextTranslate