| 264 | |
| 265 | |
| 266 | class NullTranslations: |
| 267 | def __init__(self, fp=None): |
| 268 | self._info = {} |
| 269 | self._charset = None |
| 270 | self._fallback = None |
| 271 | if fp is not None: |
| 272 | self._parse(fp) |
| 273 | |
| 274 | def _parse(self, fp): |
| 275 | pass |
| 276 | |
| 277 | def add_fallback(self, fallback): |
| 278 | if self._fallback: |
| 279 | self._fallback.add_fallback(fallback) |
| 280 | else: |
| 281 | self._fallback = fallback |
| 282 | |
| 283 | def gettext(self, message): |
| 284 | if self._fallback: |
| 285 | return self._fallback.gettext(message) |
| 286 | return message |
| 287 | |
| 288 | def ngettext(self, msgid1, msgid2, n): |
| 289 | if self._fallback: |
| 290 | return self._fallback.ngettext(msgid1, msgid2, n) |
| 291 | if n == 1: |
| 292 | return msgid1 |
| 293 | else: |
| 294 | return msgid2 |
| 295 | |
| 296 | def pgettext(self, context, message): |
| 297 | if self._fallback: |
| 298 | return self._fallback.pgettext(context, message) |
| 299 | return message |
| 300 | |
| 301 | def npgettext(self, context, msgid1, msgid2, n): |
| 302 | if self._fallback: |
| 303 | return self._fallback.npgettext(context, msgid1, msgid2, n) |
| 304 | if n == 1: |
| 305 | return msgid1 |
| 306 | else: |
| 307 | return msgid2 |
| 308 | |
| 309 | def info(self): |
| 310 | return self._info |
| 311 | |
| 312 | def charset(self): |
| 313 | return self._charset |
| 314 | |
| 315 | def install(self, names=None): |
| 316 | import builtins |
| 317 | builtins.__dict__['_'] = self.gettext |
| 318 | if names is not None: |
| 319 | allowed = {'gettext', 'ngettext', 'npgettext', 'pgettext'} |
| 320 | for name in allowed & set(names): |
| 321 | builtins.__dict__[name] = getattr(self, name) |
| 322 | |
| 323 | |