def get_translations(self, locale):
locale = self.normalize_locale(locale)<EOL>if locale in self.translations:<EOL><INDENT>return self.translations[locale]<EOL><DEDENT>translations = {}<EOL>for path in self.dirs:<EOL><INDENT>file = os.path.join(path, '<STR_LIT>'.format(locale))<EOL>if not os.path.isfile(file):<EOL><INDENT>continue<EOL><DEDENT>loader = SourceFileLoader(locale, file)<EOL>locale_dict = loader.load_module()<EOL>if not hasattr(locale_dict, '<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>language = getattr(locale_dict, '<STR_LIT>')<EOL>if translations:<EOL><INDENT>translations = language<EOL><DEDENT>else:<EOL><INDENT>merged = dict(translations.items() | language.items())<EOL>translations = merged<EOL><DEDENT><DEDENT>if translations:<EOL><INDENT>self.translations[locale] = translations<EOL>return translations<EOL><DEDENT>err = '<STR_LIT>'<EOL>raise NoTranslations(err.format(locale))<EOL>
Get translation dictionary
Returns a dictionary for locale or raises an exception if such can't
be located. If a dictionary for locale was previously loaded returns
that, otherwise goes through registered locations and merges any
found custom dictionaries with defaults.

:param locale:          str, locale to load translations
:return:                dict, translations dictionary