You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Defines the order of lookups. The first lookup to return a full locale will be the final result.
56
+
57
+
Built-in lookups:
58
+
*`cookie`
59
+
*`query`
60
+
*`hostname`
61
+
*`accept-language`
62
+
*`map`
63
+
*`default`
64
+
65
+
Read below on how to add custom lookups.
66
+
67
+
*`allowed` Array
68
+
69
+
If provided, each lookup's results are validated against this whitelist.
70
+
71
+
> **Note:** since this validation happens after each lookup, values which will still pass through the next lookup (like when using `map`) need to also be whitelisted as in the example below. This will likely be addressed in a future version (see [#20](https://github.com/smhg/express-locale/issues/20)).
72
+
```javascript
73
+
// example
74
+
createLocaleMiddleware({
75
+
priority: ['accept-language', 'cookie', 'map'],
76
+
map: {
77
+
'en':'en-US',
78
+
'fr':'fr-CA'
79
+
},
80
+
allowed: ['en', 'fr', 'en-US', 'fr-CA']
81
+
});
82
+
```
83
+
84
+
*`requestProperty` String, default `'locale'`
85
+
86
+
The property on the request object (`req`) in which the locale is set.
87
+
88
+
*`cookie` Object, default `'{name: 'locale'}'`
89
+
90
+
The `name` of the cookie that contains the locale for the cookie lookup.
91
+
92
+
Use with [cookie-parser](https://github.com/expressjs/cookie-parser) middleware.
93
+
94
+
*`query` Object, default `'{name: 'locale'}'`
95
+
96
+
The `name` of the query string parameter that contains the locale for the query lookup.
97
+
98
+
*`hostname` Object
99
+
100
+
A mapping of hostnames to locales for the hostname lookup.
101
+
```javascript
102
+
// example
103
+
createLocaleMiddleware({
104
+
priority: ['hostname'],
105
+
map: {
106
+
'en.wikipedia.org':'en-US',
107
+
'nl.wikipedia.org':'nl-NL'
108
+
}
109
+
});
110
+
```
111
+
112
+
*`map` Object
113
+
114
+
Maps lookup results that return only a language to a full locale.
115
+
```javascript
116
+
// example
117
+
createLocaleMiddleware({
118
+
priority: ['accept-language', 'cookie', 'map'],
119
+
map: {
120
+
'en':'en-US',
121
+
'fr':'fr-CA'
122
+
}
123
+
});
124
+
```
125
+
126
+
*`default` String, default `'en-GB'`
127
+
128
+
The default locale for the default lookup.
129
+
130
+
*`lookups` Object
131
+
132
+
Add custom lookups or overwrite the default ones by using the `lookups` property.
0 commit comments