| | 1 | # -*- coding: utf-8 -*- |
| | 2 | # |
| | 3 | # Copyright (C) 2005 Sergio Talens-Oliag <sto@debian.org> |
| | 4 | # All rights reserved. |
| | 5 | # |
| | 6 | # This software is licensed as described in the file COPYING, which |
| | 7 | # you should have received as part of this distribution. The terms |
| | 8 | # are also available at http://trac.edgewall.com/license.html. |
| | 9 | # |
| | 10 | # This software consists of voluntary contributions made by many |
| | 11 | # individuals. For the exact contribution history, see the revision |
| | 12 | # history and logs, available at http://projects.edgewall.com/trac/. |
| | 13 | # |
| | 14 | # Author: Sergio Talens-Oliag <sto@debian.org> |
| | 15 | |
| | 16 | import gettext |
| | 17 | import locale |
| | 18 | import __builtin__ |
| | 19 | |
| | 20 | # ---------------- |
| | 21 | # Global variables |
| | 22 | # ---------------- |
| | 23 | # Translations dictionary |
| | 24 | _translations = {} |
| | 25 | # Standard translation |
| | 26 | _stdtr = gettext.translation('trac', fallback=True) |
| | 27 | # Current langcode |
| | 28 | _clang = None |
| | 29 | |
| | 30 | # --------- |
| | 31 | # Functions |
| | 32 | # --------- |
| | 33 | def updateLocale(): |
| | 34 | global _clang, _stdtr, _translations |
| | 35 | langcode = locale.getlocale(locale.LC_ALL)[0] |
| | 36 | if langcode == _clang: |
| | 37 | return |
| | 38 | _clang = langcode |
| | 39 | if langcode == None or langcode == "": |
| | 40 | __builtin__.__dict__['_'] = _stdtr.gettext |
| | 41 | else: |
| | 42 | if langcode not in _translations: |
| | 43 | _translations[langcode] = gettext.translation('trac', languages=[langcode], fallback=True) |
| | 44 | __builtin__.__dict__['_'] = _translations[langcode].gettext |
| | 45 | |
| | 46 | # ------------------ |
| | 47 | # First load actions |
| | 48 | # ------------------ |
| | 49 | |
| | 50 | # Install default translations |
| | 51 | __builtin__.__dict__['_'] = _stdtr.gettext |
| | 52 | # Call updateLocale |
| | 53 | updateLocale() |