1   
  2   
  3   
  4  from translate.convert import ts2po 
  5  from translate.convert import test_convert 
  6  from translate.misc import wStringIO 
  7   
  9 -    def ts2po(self, tssource): 
  16   
 18          """tests blank conversion""" 
 19          tssource = '''<!DOCTYPE TS><TS> 
 20  <context> 
 21      <name>MainWindowBase</name> 
 22      <message> 
 23          <source>Project:</source> 
 24          <translation type="unfinished"></translation> 
 25      </message> 
 26  </context> 
 27  </TS> 
 28  ''' 
 29          pofile = self.ts2po(tssource) 
 30          assert len(pofile.units) == 2 
 31          assert pofile.units[1].source == "Project:" 
 32          assert pofile.units[1].target == "" 
 33          assert pofile.units[1].getlocations()[0].startswith("MainWindowBase") 
 34          assert not pofile.units[1].isfuzzy() 
  35           
 37          """tests basic conversion""" 
 38          tssource = '''<!DOCTYPE TS><TS> 
 39  <context> 
 40      <name>AboutDialog</name> 
 41      <message> 
 42          <source>&About</source> 
 43          <translation>&Giới thiệu</translation> 
 44      </message> 
 45  </context> 
 46  </TS> 
 47  ''' 
 48          pofile = self.ts2po(tssource) 
 49          assert len(pofile.units) == 2 
 50          assert pofile.units[1].source == "&About" 
 51          assert pofile.units[1].target == u"&Giới thiệu" 
 52          assert pofile.units[1].getlocations()[0].startswith("AboutDialog") 
  53   
 55          """tests unfinished conversion""" 
 56          tssource = '''<!DOCTYPE TS><TS> 
 57  <context> 
 58      <name>MainWindowBase</name> 
 59      <message> 
 60          <source>Project:</source> 
 61          <translation type="unfinished">Projek vergardering</translation> 
 62      </message> 
 63  </context> 
 64  </TS> 
 65  ''' 
 66          pofile = self.ts2po(tssource) 
 67          assert len(pofile.units) == 2 
 68          assert pofile.units[1].source == "Project:" 
 69          assert pofile.units[1].target == "Projek vergardering" 
 70          assert pofile.units[1].getlocations()[0].startswith("MainWindowBase") 
 71          assert pofile.units[1].isfuzzy() 
  72   
 74          """tests multiline message conversion""" 
 75          tssource = '''<!DOCTYPE TS><TS> 
 76  <context> 
 77      <name>@default</name> 
 78      <message> 
 79          <source>Source with 
 80  new line</source> 
 81          <translation>Test with 
 82  new line</translation> 
 83      </message> 
 84  </context> 
 85  </TS>  
 86  ''' 
 87          pofile = self.ts2po(tssource) 
 88          assert len(pofile.units) == 2 
 89          assert pofile.units[1].source == "Source with\nnew line" 
 90          assert pofile.units[1].target == "Test with\nnew line" 
 91          assert pofile.units[1].getlocations()[0].startswith("@default") 
  92   
 94          """test the handling of obsolete TS entries""" 
 95          tssource = '''<!DOCTYPE TS><TS> 
 96  <context> 
 97      <name>Obsoleted</name> 
 98      <message> 
 99          <source>Failed</source> 
100          <translation type="obsolete">Mislukt</translation> 
101      </message> 
102  </context> 
103  </TS> 
104  ''' 
105          pofile = self.ts2po(tssource) 
106          assert pofile.units[1].getnotes("developer") == "(obsolete)" 
107           
108          assert "_ OBSOLETE" not in pofile.units[1].getnotes() 
 111      """Tests running actual ts2po commands on files""" 
112      convertmodule = ts2po 
113   
 118