1   
  2   
  3   
  4  from translate.convert import oo2po 
  5  from translate.convert import po2oo 
  6  from translate.convert import test_convert 
  7  from translate.misc import wStringIO 
  8  from translate.storage import po 
  9  from translate.storage.poheader import poheader 
 10  from translate.storage import oo 
 11  import os 
 12   
 14      target_filetype = po.pofile 
 15      conversion_module = oo2po 
 16      conversion_class = oo2po.oo2po 
 17   
 18 -    def convert(self, oosource, sourcelanguage='en-US', targetlanguage='af-ZA'): 
  19          """helper that converts oo source to po source without requiring files""" 
 20          inputoo = oo.oofile(oosource) 
 21          convertor = self.conversion_class(sourcelanguage, targetlanguage) 
 22          outputpo = convertor.convertstore(inputoo) 
 23          return outputpo 
  24   
 34   
 36          """Convert the supplied string as part of an OpenOffice.org GSI file to po and back. 
 37           
 38          Return the string once it has been through all the conversions.""" 
 39   
 40          ootemplate = r'helpcontent2     %s      0       help    par_id3150670 35                                0       en-US   %s                              2002-02-02 02:02:02' 
 41   
 42          oosource = ootemplate % (filename, entitystring) 
 43          ooinputfile = wStringIO.StringIO(oosource) 
 44          ootemplatefile = wStringIO.StringIO(oosource) 
 45          pooutputfile = wStringIO.StringIO() 
 46   
 47          self.conversion_module.convertoo(ooinputfile, pooutputfile, ootemplatefile, targetlanguage='en-US') 
 48          posource = pooutputfile.getvalue() 
 49   
 50          poinputfile = wStringIO.StringIO(posource) 
 51          ootemplatefile = wStringIO.StringIO(oosource) 
 52          oooutputfile = wStringIO.StringIO() 
 53          po2oo.convertoo(poinputfile, oooutputfile, ootemplatefile, targetlanguage="en-US") 
 54          ooresult = oooutputfile.getvalue() 
 55          print "original oo:\n", oosource, "po version:\n", posource, "output oo:\n", ooresult 
 56          return ooresult.split('\t')[10] 
  57   
 61   
 63          """checks that a simple oo entry converts properly to a po entry""" 
 64          oosource = r'svx        source\dialog\numpages.src      0       string  RID_SVXPAGE_NUM_OPTIONS STR_BULLET                      0       en-US   Character                               20050924 09:13:58' 
 65          pofile = self.convert(oosource) 
 66          pounit = self.singleelement(pofile) 
 67          assert pounit.source == "Character" 
 68          assert pounit.target == "" 
  69   
 71          """checks that a simple oo entry converts escapes properly to a po entry""" 
 72          oosource = r"wizards    source\formwizard\dbwizres.src  0       string  RID_DB_FORM_WIZARD_START + 19                           0       en-US   Newline \n Newline Tab \t Tab CR \r CR                          20050924 09:13:58" 
 73          pofile = self.convert(oosource) 
 74          pounit = self.singleelement(pofile) 
 75          poelementsrc = str(pounit) 
 76          print poelementsrc 
 77          assert "Newline \n Newline" in pounit.source  
 78          assert "Tab \t Tab" in pounit.source  
 79          assert "CR \r CR" in pounit.source  
  80   
 82          self.check_roundtrip('strings.src', r'The given command is not a SELECT statement.\nOnly queries are allowed.') 
 83          self.check_roundtrip('source\ui\dlg\AutoControls_tmpl.hrc', r';\t59\t,\t44\t:\t58\t{Tab}\t9\t{Space}\t32') 
 84          self.check_roundtrip('inc_openoffice\windows\msi_languages\Nsis.ulf', r'The installation files must be unpacked and copied to your hard disk in preparation for the installation. After that, the %PRODUCTNAME installation will start automatically.\r\n\r\nClick \'Next\' to continue.') 
 85          self.check_roundtrip('file.xhp', r'\<asdf\>') 
 86          self.check_roundtrip('file.xhp', r'\<asdf prop=\"value\"\>') 
 87          self.check_roundtrip('file.xhp', r'\<asdf prop=\"value\"\>marked up text\</asdf\>') 
 88          self.check_roundtrip('file.xhp', r'\<asdf prop=\"value>>\"\>') 
 89          self.check_roundtrip('file.xhp', r'''\<asdf prop=\"value>>\"\>'Next'>> or "<<Previous"\</asdf\>''') 
 90          self.check_roundtrip('address_auto.xhp', r'''example, \<item type=\"literal\"\>'Harry\\'s Bar'.\</item\>''') 
  91   
 99   
101          """checks that a helpcontent2 entry converts escapes properly to a po entry""" 
102          oosource = r"helpcontent2       source\text\smath\guide\parentheses.xhp 0       help    par_id3150344   4                       0       en-US   size *2 \\langle x \\rangle                             2002-02-02 02:02:02" 
103          pofile = self.convert(oosource) 
104          pounit = self.singleelement(pofile) 
105          poelementsrc = str(pounit) 
106          print poelementsrc 
107          assert pounit.source == r'size *2 \langle x \rangle' 
 108   
110          """tests the we have the correct url for reporting msgid bugs""" 
111          oosource = r"wizards    source\formwizard\dbwizres.src  0       string  RID_DB_FORM_WIZARD_START + 19                           0       en-US   Newline \n Newline Tab \t Tab CR \r CR                          20050924 09:13:58" 
112          bug_url = '''http://qa.openoffice.org/issues/enter_bug.cgi''' + ('''?subcomponent=ui&comment=&short_desc=Localization issue in file: &component=l10n&form_name=enter_issue''').replace(" ", "%20").replace(":", "%3A") 
113          pofile = self.convert(oosource) 
114          assert pofile.units[0].isheader() 
115          assert pofile.parseheader()["Report-Msgid-Bugs-To"] == bug_url 
 116   
 155   
157      """Tests running actual oo2po commands on files""" 
158      convertmodule = oo2po 
159   
169   
171          """Ensures that the filename is preserved.""" 
172          oosource = r'svx        source\dialog\numpages.src      0       string  RID_SVXPAGE_NUM_OPTIONS STR_BULLET                      0       en-US   Character                               20050924 09:13:58' 
173          self.create_testfile("snippet.sdf", oosource) 
174          oofile = oo.oofile(self.open_testfile("snippet.sdf")) 
175          assert oofile.filename.endswith("snippet.sdf") 
176          oofile.parse(oosource) 
177          assert oofile.filename.endswith("snippet.sdf") 
 178   
180          """tests the simplest possible conversion to a pot file""" 
181          oosource = r'svx        source\dialog\numpages.src      0       string  RID_SVXPAGE_NUM_OPTIONS STR_BULLET                      0       en-US   Character                               20050924 09:13:58' 
182          self.create_testfile("simple.oo", oosource) 
183          self.run_command("simple.oo", "simple.pot", pot=True, nonrecursiveinput=True) 
184          pofile = self.target_filetype(self.open_testfile("simple.pot")) 
185          poelement = self.singleelement(pofile) 
186          assert poelement.source == "Character" 
187          assert poelement.target == "" 
 188   
190          """tests the simplest possible conversion to a po file""" 
191          oosource1 = r'svx       source\dialog\numpages.src      0       string  RID_SVXPAGE_NUM_OPTIONS STR_BULLET                      0       en-US   Character                               20050924 09:13:58' 
192          oosource2 = r'svx       source\dialog\numpages.src      0       string  RID_SVXPAGE_NUM_OPTIONS STR_BULLET                      0       ku      Karakter                                20050924 09:13:58' 
193          self.create_testfile("simple.oo", oosource1 + "\n" + oosource2) 
194          self.run_command("simple.oo", "simple.po", lang="ku", nonrecursiveinput=True) 
195          pofile = self.target_filetype(self.open_testfile("simple.po")) 
196          poelement = self.singleelement(pofile) 
197          assert poelement.source == "Character" 
198          assert poelement.target == "Karakter" 
 199   
201          """tests the --multifile=onefile option and make sure it doesn't produce a directory""" 
202          oosource = r'svx        source\dialog\numpages.src      0       string  RID_SVXPAGE_NUM_OPTIONS STR_BULLET                      0       en-US   Character                               20050924 09:13:58' 
203          self.create_testfile("simple.oo", oosource) 
204          self.run_command("simple.oo", "simple.pot", pot=True, multifile="onefile") 
205          assert os.path.isfile(self.get_testfilename("simple.pot")) 
 206   
208          """test that removing of duplicates works correctly (bug 171)""" 
209          oosource = r''' 
210  sd      source\ui\animations\SlideTransitionPane.src    0       checkbox        DLG_SLIDE_TRANSITION_PANE       CB_AUTO_PREVIEW HID_SD_SLIDETRANSITIONPANE_CB_AUTO_PREVIEW              1       en-US   Automatic preview                               20060725 03:26:42 
211  sd      source\ui\animations\AnimationSchemesPane.src   0       checkbox        DLG_ANIMATION_SCHEMES_PANE      CB_AUTO_PREVIEW HID_SD_ANIMATIONSCHEMESPANE_CB_AUTO_PREVIEW             1       en-US   Automatic preview                               20060725 03:26:42 
212  sd      source\ui\animations\CustomAnimationCreateDialog.src    0       checkbox        RID_TP_CUSTOMANIMATION_ENTRANCE CBX_PREVIEW                     143     en-US   Automatic preview                               20060725 03:26:42 
213  sd      source\ui\animations\CustomAnimationCreateDialog.src    0       checkbox        RID_TP_CUSTOMANIMATION_ENTRANCE CBX_PREVIEW                     143     fr      Aperçu automatique                             20060725 03:26:42 
214  sd      source\ui\animations\CustomAnimationSchemesPane.src     0       checkbox        DLG_CUSTOMANIMATION_SCHEMES_PANE        4                       0       en-US   Automatic preview                               20060725 03:26:42 
215  sd      source\ui\animations\CustomAnimationSchemesPane.src     0       checkbox        DLG_CUSTOMANIMATION_SCHEMES_PANE        4                       0       fr      Aperçu automatique                             20060725 03:26:42 
216  ''' 
217          self.create_testfile("simple.oo", oosource) 
218          self.run_command("simple.oo", "simple.po", language="fr", multifile="onefile", error="traceback", duplicates="merge") 
219          pofile = self.target_filetype(self.open_testfile("simple.po")) 
220          assert len(pofile.units) == 2 
221          assert pofile.units[1].target == u"Aperçu automatique" 
  222