96def get_google_info(params: "OnlineParams", eng_traits: EngineTraits) -> dict[str, t.Any]:
97 """Composing various (language) properties for the google engines (:ref:`google
98 API`).
99
100 This function is called by the various google engines (:ref:`google web
101 engine`, :ref:`google images engine`, :ref:`google news engine` and
102 :ref:`google videos engine`).
103
104 :param dict param: Request parameters of the engine. At least
105 a ``searxng_locale`` key should be in the dictionary.
106
107 :param eng_traits: Engine's traits fetched from google preferences
108 (:py:obj:`searx.enginelib.traits.EngineTraits`)
109
110 :rtype: dict
111 :returns:
112 Py-Dictionary with the key/value pairs:
113
114 language:
115 The language code that is used by google (e.g. ``lang_en`` or
116 ``lang_zh-TW``)
117
118 country:
119 The country code that is used by google (e.g. ``US`` or ``TW``)
120
121 locale:
122 A instance of :py:obj:`babel.core.Locale` build from the
123 ``searxng_locale`` value.
124
125 subdomain:
126 Google subdomain :py:obj:`google_domains` that fits to the country
127 code.
128
129 params:
130 Py-Dictionary with additional request arguments (can be passed to
131 :py:func:`urllib.parse.urlencode`).
132
133 - ``hl`` parameter: specifies the interface language of user interface.
134 - ``lr`` parameter: restricts search results to documents written in
135 a particular language.
136 - ``cr`` parameter: restricts search results to documents
137 originating in a particular country.
138 - ``ie`` parameter: sets the character encoding scheme that should
139 be used to interpret the query string ('utf8').
140 - ``oe`` parameter: sets the character encoding scheme that should
141 be used to decode the XML result ('utf8').
142
143 headers:
144 Py-Dictionary with additional HTTP headers (can be passed to
145 request's headers)
146
147 - ``Accept: '*/*``
148
149 """
150
151 ret_val: dict[str, t.Any] = {
152 'language': None,
153 'country': None,
154 'subdomain': None,
155 'params': {},
156 'headers': {},
157 'cookies': {},
158 'locale': None,
159 }
160
161 sxng_locale = params.get('searxng_locale', 'all')
162 try:
163 locale = babel.Locale.parse(sxng_locale, sep='-')
164 except babel.core.UnknownLocaleError:
165 locale = None
166
167 eng_lang = eng_traits.get_language(sxng_locale, 'lang_en')
168 lang_code = eng_lang.split('_')[-1]
169 country = eng_traits.get_region(sxng_locale, eng_traits.all_locale)
170
171
172
173
174
175
176
177
178
179 ret_val['language'] = eng_lang
180 ret_val['country'] = country
181 ret_val['locale'] = locale
182 ret_val['subdomain'] = eng_traits.custom['supported_domains'].get(country.upper(), 'www.google.com')
183
184
185
186
187
188
189
190
191
192
193
194 ret_val['params']['hl'] = f'{lang_code}-{country}'
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210 ret_val['params']['lr'] = eng_lang
211 if sxng_locale == 'all':
212 ret_val['params']['lr'] = ''
213
214
215
216
217
218
219
220
221 ret_val['params']['cr'] = ''
222 if len(sxng_locale.split('-')) > 1:
223 ret_val['params']['cr'] = 'country' + country
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244 ret_val['params']['ie'] = 'utf8'
245
246
247
248
249
250
251 ret_val['params']['oe'] = 'utf8'
252
253
254
255
256
257
258
259
260
261
262
263
264 ret_val['headers']['Accept'] = '*/*'
265
266
267
268
269
270 ret_val['cookies']['CONSENT'] = "YES+"
271
272 return ret_val
273
274