22
33import polib
44from django .test import SimpleTestCase
5- from django .utils .translation import activate , gettext as _
5+ from django .utils .translation import activate
6+ from django .utils .translation import gettext as _
67
78
89class TestTranslations (SimpleTestCase ):
9- LOCALE_DIR = os .path .abspath (os .path .join (os .path .dirname (__file__ ), '../rest_framework_simplejwt/locale' ))
10+ LOCALE_DIR = os .path .abspath (
11+ os .path .join (os .path .dirname (__file__ ), "../rest_framework_simplejwt/locale" )
12+ )
1013 MESSAGES = {
1114 "Authorization header must contain two space-delimited values" : {
1215 "fa" : "هدر اعتبارسنجی باید شامل دو مقدار جدا شده با فاصله باشد" ,
@@ -860,9 +863,29 @@ class TestTranslations(SimpleTestCase):
860863 },
861864 }
862865 LANGUAGES = {
863- 'fa' , 'fa_IR' , 'ar' , 'de' , 'fr' , 'tr' , 'cs' , 'es' , 'es_AR' , 'es_CL' ,
864- 'it_IT' , 'nl_NL' , 'pl_PL' , 'pt_BR' , 'ru_RU' , 'uk_UA' , 'zh_Hans' , 'ko_KR' ,
865- 'id_ID' , 'he_IL' , 'ro' , 'sl' , 'sv' ,
866+ "fa" ,
867+ "fa_IR" ,
868+ "ar" ,
869+ "de" ,
870+ "fr" ,
871+ "tr" ,
872+ "cs" ,
873+ "es" ,
874+ "es_AR" ,
875+ "es_CL" ,
876+ "it_IT" ,
877+ "nl_NL" ,
878+ "pl_PL" ,
879+ "pt_BR" ,
880+ "ru_RU" ,
881+ "uk_UA" ,
882+ "zh_Hans" ,
883+ "ko_KR" ,
884+ "id_ID" ,
885+ "he_IL" ,
886+ "ro" ,
887+ "sl" ,
888+ "sv" ,
866889 }
867890
868891 def test_translations (self ):
@@ -878,7 +901,9 @@ def test_translations(self):
878901 translated = _ (msg_key )
879902 expected = translations .get (lang )
880903 if expected is None :
881- errors .append (f"Missing translation for '{ msg_key } ' in { lang } (not found in MESSAGES)" )
904+ errors .append (
905+ f"Missing translation for '{ msg_key } ' in { lang } (not found in MESSAGES)"
906+ )
882907 elif translated != expected :
883908 errors .append (
884909 f'Translation mismatch for "{ msg_key } " in "{ lang } ": '
@@ -895,11 +920,13 @@ def test_po_files_have_all_key_messages(self):
895920 key_messages = set (self .MESSAGES .keys ())
896921 for lang in os .listdir (self .LOCALE_DIR ):
897922 lang_dir = os .path .join (self .LOCALE_DIR , lang )
898- po_path = os .path .join (lang_dir , ' LC_MESSAGES' , ' django.po' )
923+ po_path = os .path .join (lang_dir , " LC_MESSAGES" , " django.po" )
899924 if not os .path .exists (po_path ):
900- self .fail (f"Missing .po file for language '{ lang } ' at expected path: { po_path } " )
925+ self .fail (
926+ f"Missing .po file for language '{ lang } ' at expected path: { po_path } "
927+ )
901928 po = polib .pofile (po_path )
902- po_messages = set ( entry .msgid for entry in po )
929+ po_messages = { entry .msgid for entry in po }
903930 missing_keys = key_messages - po_messages
904931 extra_keys = po_messages - key_messages
905932
@@ -966,17 +993,21 @@ def test_po_file_translations_present(self):
966993 )
967994 continue
968995 lang_dir = os .path .join (self .LOCALE_DIR , lang )
969- po_path = os .path .join (lang_dir , ' LC_MESSAGES' , ' django.po' )
996+ po_path = os .path .join (lang_dir , " LC_MESSAGES" , " django.po" )
970997 if not os .path .exists (po_path ):
971- errors .append (f"Missing .po file for language '{ lang } ' at expected path: { po_path } " )
998+ errors .append (
999+ f"Missing .po file for language '{ lang } ' at expected path: { po_path } "
1000+ )
9721001 continue
9731002 po = polib .pofile (po_path )
9741003 activate (lang )
9751004 for entry in po :
9761005 if entry .msgid and not entry .obsolete :
9771006 expected_translation = self .MESSAGES .get (entry .msgid , {}).get (lang )
9781007 if expected_translation is None :
979- errors .append (f"Missing translation for '{ entry .msgid } ' in { lang } (not found in MESSAGES)" )
1008+ errors .append (
1009+ f"Missing translation for '{ entry .msgid } ' in { lang } (not found in MESSAGES)"
1010+ )
9801011 elif _ (entry .msgid ) != expected_translation :
9811012 errors .append (
9821013 f"Translation mismatch for '{ entry .msgid } ' in { lang } : "
0 commit comments