def check_available_translations(self, locale):
"""
Test a locale for having a translation available
locale -- string with standard language code, locale code, or name
"""
if not self.localedir:
return None
#Note that this isn't a typo for self.language; self.languages
#is cached so we don't have to query the file system every
#time this function is called.
if not hasattr(self, 'languages'):
self.languages = self.get_available_translations()
if not locale:
return None
if locale[:5] in self.languages:
return locale[:5]
#US English is the outlier, all other English locales want real English:
if locale[:2] == 'en' and locale[:5] != 'en_US':
return 'en_GB'
if locale[:2] in self.languages:
return locale[:2]
return None
评论列表
文章目录