Trees | Indices | Help |
---|
|
1 # 2 # Copyright (c) 2008--2016 Red Hat, Inc. 3 # 4 # This software is licensed to you under the GNU General Public License, 5 # version 2 (GPLv2). There is NO WARRANTY for this software, express or 6 # implied, including the implied warranties of MERCHANTABILITY or FITNESS 7 # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 8 # along with this software; if not, see 9 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 10 # 11 # Red Hat trademarks are not licensed under GPLv2. No permission is 12 # granted to use or replicate Red Hat trademarks that are incorporated 13 # in this software or its documentation. 14 # 15 16 import os 17 import gettext 18 19 from spacewalk.common.usix import StringType 2022 # Defining our own class, since we'd like to save the language we use 23 # Determining the language is not very pretty - we parse the file name 24 # which is supposed to be something like 25 # .../<lang>/LC_MESSAGES/<domain>.po 26 3047 4832 gettext.GNUTranslations._parse(self, fp) 33 filename = fp.name 34 filename = os.path.normpath(filename) 35 # Extract the language 36 self.lang = filename.split('/')[-3]3739 # Return all languages 40 # pkilambi:bug#158561,170819,170821: the gettext object in python 2.2.3 has no attribute 41 #_fallback so add a check if __dict__ has key 42 # if not self._fallback or not hasattr(self._fallback, 'getlangs'): 43 if "_fallback" not in self.__dict__ or not self._fallback or not hasattr(self._fallback, 'getlangs'): 44 return [self.lang, 'C'] 45 # Recursive call 46 return [self.lang] + self._fallback.getlangs()50 _default_langs = ['en', 'en_US', 'C'] 51 # Wrapper class that allows us to change languages 5291 92 93 cat = i18n() 94 _ = cat.gettext 9554 self.domain = domain 55 self.localedir = localedir 56 self.langs = self._default_langs[:] 57 self.cat = None 58 self._set_catalog()5961 # Set the catalog object 62 self.cat = gettext.Catalog(self.domain, localedir=self.localedir, 63 languages=self.langs, fallback=1, class_=RHN_Translations)6466 # List of languages we support 67 # pylint: disable=E1103 68 if not hasattr(self.cat, "getlangs"): 69 return ["C"] 70 return self.cat.getlangs()7173 if isinstance(langs, StringType): 74 langs = [langs] 75 # Filter "C" - we will add it ourselves later anyway 76 langs = [l for l in langs if l != 'C'] 77 langs.extend(self._default_langs) 78 self.langs = langs 79 self._set_catalog()80 83 84 # reinitialize this catalog86 if domain: 87 self.domain = domain 88 if localedir: 89 self.localedir = localedir 90 self._set_catalog()
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Wed Mar 4 07:37:47 2020 | http://epydoc.sourceforge.net |