| 230 | |
| 231 | |
| 232 | def _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 | |
| 274 | class NullTranslations: |