MCPcopy Index your code
hub / github.com/python/cpython / _expand_lang

Function _expand_lang

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

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…