paul@1005 | 1 | #!/usr/bin/env python |
paul@1005 | 2 | |
paul@1005 | 3 | """ |
paul@1005 | 4 | Internationalisation support. |
paul@1005 | 5 | |
paul@1005 | 6 | Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk> |
paul@1005 | 7 | |
paul@1005 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@1005 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@1005 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@1005 | 11 | version. |
paul@1005 | 12 | |
paul@1005 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@1005 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@1005 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@1005 | 16 | details. |
paul@1005 | 17 | |
paul@1005 | 18 | You should have received a copy of the GNU General Public License along with |
paul@1005 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@1005 | 20 | """ |
paul@1005 | 21 | |
paul@1005 | 22 | from imiptools.config import LOCALE_DIR, TRANS_DOMAIN |
paul@1005 | 23 | from os.path import abspath, exists, join, split |
paul@1005 | 24 | import gettext |
paul@1005 | 25 | |
paul@1005 | 26 | def get_locale_dir(): |
paul@1005 | 27 | locale_dir = abspath(join(split(__file__)[0], "..", "locale")) |
paul@1005 | 28 | if exists(locale_dir): |
paul@1005 | 29 | return locale_dir |
paul@1005 | 30 | else: |
paul@1005 | 31 | return LOCALE_DIR |
paul@1005 | 32 | |
paul@1005 | 33 | def get_translator(languages): |
paul@1005 | 34 | return gettext.translation(TRANS_DOMAIN, get_locale_dir(), languages, |
paul@1005 | 35 | fallback=True).ugettext |
paul@1005 | 36 | |
paul@1005 | 37 | # vim: tabstop=4 expandtab shiftwidth=4 |