Loading

Paste #pguqqq4ko

  1. diff -r 7f4f864f4e20 webtranslate/newgrf/language_file.py
  2. --- a/webtranslate/newgrf/language_file.py  Tue May 26 21:59:05 2015 +0200
  3. +++ b/webtranslate/newgrf/language_file.py  Wed May 27 19:30:19 2015 +0200
  4. @@ -420,7 +420,7 @@
  5.      @type plurals: C{list} of C{int}
  6.  
  7.      @ivar commands: String commands at each position.
  8. -    @type commands: C{list} of C{ParameterInfo}
  9. +    @type commands: C{list} of (L{ParameterInfo} or C{None})
  10.  
  11.      @ivar non_positionals: Mapping of commands without position to their count.
  12.      @type non_positionals: C{dict} of C{str} to C{int}
  13. @@ -612,10 +612,6 @@
  14.          Check sanity of the string commands and parameters.
  15.          """
  16.          ok = True
  17. -        for pos, cmd in enumerate(self.commands):
  18. -            if cmd is None:
  19. -                self.add_error(ErrorMessage(ERROR, None, "String parameter {} has no string command".format(pos)))
  20. -                ok = False
  21.          if ok:
  22.              for pos in self.plurals:
  23.                  if pos < 0 or pos >= len(self.commands):
  24. @@ -964,29 +960,38 @@
  25.      if base_info.has_error: return True # Cannot blame the translation when the base language is broken.
  26.      if lng_info.has_error: return False # Translation has more serious problems.
  27.  
  28. -    base_cmds = [cmd.get_translated_cmd() for cmd in base_info.commands]
  29. -    lng_cmds = [cmd.literal for cmd in lng_info.commands]
  30. +    if len(base_info.commands) > len(lng_info.commands):
  31. +        msg = 'String command for position {} (and further) is missing in the translation'
  32. +        msg = msg.format(len(lng_info.commands))
  33. +        lng_info.add_error(ErrorMessage(ERROR, None, msg))
  34. +        return False
  35. +    if len(base_info.commands) < len(lng_info.commands):
  36. +        msg = 'String command for position {} (and further) is not used in the base language'
  37. +        msg = msg.format(len(base_info.commands))
  38. +        lng_info.add_error(ErrorMessage(ERROR, None, msg))
  39. +        return False
  40.  
  41. -    if base_cmds != lng_cmds:
  42. -        if len(base_cmds) > len(lng_cmds):
  43. -            msg = 'String command for position {} (and further) is missing in the translation'
  44. -            msg = msg.format(len(lng_cmds))
  45. +    for i in range(len(base_info.commands)):
  46. +        base_name = None
  47. +        if base_info.commands[i] is not None:
  48. +            base_name = base_info.commands[i].get_translated_cmd()
  49. +
  50. +        lng_name = None
  51. +        if lng_info.commands[i] is not None:
  52. +            lng_name = lng_info.commands[i].literal
  53. +
  54. +        if base_name != lng_name:
  55. +            if base_name is None:
  56. +                msg = 'String command for position {} does not exist, the translation uses {}'
  57. +                msg = msg.format(i, '{' + lng_name + '}')
  58. +            elif lng_name is None:
  59. +                msg = 'String command for position {} ({}) is missing in translation'
  60. +                msg = msg.format(i, '{' + base_name + '}')
  61. +            else:
  62. +                msg = 'String command for position {} is wrong, base language uses {}, the translation uses {}'
  63. +                msg = msg.format(i, '{' + base_cmds[i] + '}', '{' + lng_cmds[i] + '}')
  64.              lng_info.add_error(ErrorMessage(ERROR, None, msg))
  65.              return False
  66. -        if len(base_cmds) < len(lng_cmds):
  67. -            msg = 'String command for position {} (and further) is not used in the base language'
  68. -            msg = msg.format(len(base_cmds))
  69. -            lng_info.add_error(ErrorMessage(ERROR, None, msg))
  70. -            return False
  71. -
  72. -        for i in range(len(base_cmds)):
  73. -            if base_cmds[i] != lng_cmds[i]:
  74. -                msg = 'String command for position {} is wrong, base language uses {}, the translation uses {}'
  75. -                msg = msg.format(i, '{' + base_cmds[i] + '}', '{' + lng_cmds[i] + '}')
  76. -                lng_info.add_error(ErrorMessage(ERROR, None, msg))
  77. -                return False
  78. -
  79. -        assert False # Never reached
  80.  
  81.      # Non-positional commands must match in count.
  82.      if base_info.non_positionals != lng_info.non_positionals:
  83.  

Comments