@@ -831,23 +831,35 @@ def _translate(context, sourceText, *args):
831831 # The first argument is disambiguation[str]
832832 # The last argument is n[int]
833833 # The middle argument can be encoding[QtCore.QCoreApplication.Encoding]
834+ try :
835+ app = Qt .QtCore .QCoreApplication
836+ except AttributeError :
837+ raise NotImplementedError (
838+ "Missing QCoreApplication implementation for {}" .format (
839+ Qt .__binding__
840+ )
841+ )
842+
843+ def get_arg (index ):
844+ try :
845+ return args [index ]
846+ except IndexError :
847+ pass
848+
849+ n = - 1
850+ encoding = None
851+
834852 if len (args ) == 3 :
835853 disambiguation , encoding , n = args
836- elif len (args ) == 2 :
837- disambiguation , n = args
838- encoding = None
839854 else :
840- raise TypeError (
841- "Expected 4 or 5 arguments, got {0}." .format (len (args ) + 2 ))
855+ disambiguation = get_arg (0 )
856+ n_or_encoding = get_arg (1 )
857+
858+ if isinstance (n_or_encoding , int ):
859+ n = n_or_encoding
860+ else :
861+ encoding = n_or_encoding
842862
843- if hasattr (Qt .QtCore , "QCoreApplication" ):
844- app = getattr (Qt .QtCore , "QCoreApplication" )
845- else :
846- raise NotImplementedError (
847- "Missing QCoreApplication implementation for {binding}" .format (
848- binding = Qt .__binding__ ,
849- )
850- )
851863 if Qt .__binding__ in ("PySide2" , "PyQt5" ):
852864 sanitized_args = [context , sourceText , disambiguation , n ]
853865 else :
@@ -856,8 +868,9 @@ def _translate(context, sourceText, *args):
856868 sourceText ,
857869 disambiguation ,
858870 encoding or app .CodecForTr ,
859- n
871+ n ,
860872 ]
873+
861874 return app .translate (* sanitized_args )
862875
863876
0 commit comments