MCPcopy Index your code
hub / github.com/RustPython/RustPython / _expand_lang

Function _expand_lang

Lib/gettext.py:231–270  ·  view source on GitHub ↗
(loc)

Source from the content-addressed store, hash-verified

229
230
231def _expand_lang(loc):
232 import locale
233 loc = locale.normalize(loc)
234 COMPONENT_CODESET = 1 << 0
235 COMPONENT_TERRITORY = 1 << 1
236 COMPONENT_MODIFIER = 1 << 2
237 # split up the locale into its base components
238 mask = 0
239 pos = loc.find('@')
240 if pos >= 0:
241 modifier = loc[pos:]
242 loc = loc[:pos]
243 mask |= COMPONENT_MODIFIER
244 else:
245 modifier = ''
246 pos = loc.find('.')
247 if pos >= 0:
248 codeset = loc[pos:]
249 loc = loc[:pos]
250 mask |= COMPONENT_CODESET
251 else:
252 codeset = ''
253 pos = loc.find('_')
254 if pos >= 0:
255 territory = loc[pos:]
256 loc = loc[:pos]
257 mask |= COMPONENT_TERRITORY
258 else:
259 territory = ''
260 language = loc
261 ret = []
262 for i in range(mask+1):
263 if not (i & ~mask): # if all components for this combo exist ...
264 val = language
265 if i & COMPONENT_TERRITORY: val += territory
266 if i & COMPONENT_CODESET: val += codeset
267 if i & COMPONENT_MODIFIER: val += modifier
268 ret.append(val)
269 ret.reverse()
270 return ret
271
272
273class NullTranslations:

Callers 1

findFunction · 0.85

Calls 4

normalizeMethod · 0.45
findMethod · 0.45
appendMethod · 0.45
reverseMethod · 0.45

Tested by

no test coverage detected