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