@@ -700,35 +700,41 @@ def load_messages(themes, translations, default_lang, themes_dirs):
700
700
"""
701
701
messages = Functionary (dict , default_lang )
702
702
oldpath = list (sys .path )
703
+ found = {lang : False for lang in translations .keys ()}
704
+ last_exception = None
703
705
for theme_name in themes [::- 1 ]:
704
706
msg_folder = os .path .join (get_theme_path (theme_name ), 'messages' )
705
707
default_folder = os .path .join (get_theme_path_real ('base' , themes_dirs ), 'messages' )
706
708
sys .path .insert (0 , default_folder )
707
709
sys .path .insert (0 , msg_folder )
708
710
709
- english = __import__ ('messages_en' )
710
- # If we don't do the reload, the module is cached
711
- _reload (english )
712
- for lang in list (translations .keys ()):
713
- try :
714
- translation = __import__ ('messages_' + lang )
715
- # If we don't do the reload, the module is cached
716
- _reload (translation )
717
- if sorted (translation .MESSAGES .keys ()) != \
718
- sorted (english .MESSAGES .keys ()) and \
719
- lang not in language_incomplete_warned :
720
- language_incomplete_warned .append (lang )
721
- LOGGER .warn ("Incomplete translation for language "
722
- "'{0}'." .format (lang ))
723
- messages [lang ].update (english .MESSAGES )
724
- for k , v in translation .MESSAGES .items ():
725
- if v :
726
- messages [lang ][k ] = v
727
- del (translation )
728
- except ImportError as orig :
729
- raise LanguageNotFoundError (lang , orig )
730
- del (english )
731
- sys .path = oldpath
711
+ english = __import__ ('messages_en' )
712
+ # If we don't do the reload, the module is cached
713
+ _reload (english )
714
+ for lang in translations .keys ():
715
+ try :
716
+ translation = __import__ ('messages_' + lang )
717
+ # If we don't do the reload, the module is cached
718
+ _reload (translation )
719
+ found [lang ] = True
720
+ if sorted (translation .MESSAGES .keys ()) != \
721
+ sorted (english .MESSAGES .keys ()) and \
722
+ lang not in language_incomplete_warned :
723
+ language_incomplete_warned .append (lang )
724
+ LOGGER .warn ("Incomplete translation for language "
725
+ "'{0}'." .format (lang ))
726
+ messages [lang ].update (english .MESSAGES )
727
+ for k , v in translation .MESSAGES .items ():
728
+ if v :
729
+ messages [lang ][k ] = v
730
+ del (translation )
731
+ except ImportError as orig :
732
+ last_exception = orig
733
+ del (english )
734
+ sys .path = oldpath
735
+ if not all (found .values ()):
736
+ raise LanguageNotFoundError (lang , last_exception )
737
+
732
738
return messages
733
739
734
740
0 commit comments