1   
  2   
  3   
  4  from translate.convert import php2po 
  5  from translate.convert import test_convert 
  6  from translate.misc import wStringIO 
  7  from translate.storage import po 
  8  from translate.storage import php 
  9   
 11 -    def php2po(self, phpsource, phptemplate=None): 
  12          """helper that converts .phperties source to po source without requiring files""" 
 13          inputfile = wStringIO.StringIO(phpsource) 
 14          inputphp = php.phpfile(inputfile) 
 15          convertor = php2po.php2po() 
 16          if phptemplate: 
 17            templatefile = wStringIO.StringIO(phptemplate) 
 18            templatephp = php.phpfile(templatefile) 
 19            outputpo = convertor.mergestore(templatephp, inputphp) 
 20          else: 
 21            outputpo = convertor.convertstore(inputphp) 
 22          return outputpo 
  23   
 31   
 38   
 44   
 46          """checks that a simple php entry converts properly to a po entry""" 
 47          phpsource = """$_LANG['simple'] = 'entry';""" 
 48          pofile = self.php2po(phpsource) 
 49          pounit = self.singleelement(pofile) 
 50          assert pounit.source == "entry" 
 51          assert pounit.target == "" 
  52   
 61   
 71   
 73          """checks that multiline enties can be parsed""" 
 74          phpsource = r"""$lang['5093'] = 'Unable to connect to your IMAP server. You may have exceeded the maximum number  
 75  of connections to this server. If so, use the Advanced IMAP Server Settings dialog to  
 76  reduce the number of cached connections.';""" 
 77          pofile = self.php2po(phpsource) 
 78          print repr(pofile.units[1].target) 
 79          assert self.countelements(pofile) == 1 
  80   
 88           
 89   
 91          """checks that empty definitions survives into po file""" 
 92          phpsource = '''/* comment */\n$lang['credit'] = '';''' 
 93          pofile = self.php2po(phpsource) 
 94          pounit = self.singleelement(pofile) 
 95          assert pounit.getlocations() == ["$lang['credit']"] 
 96          assert pounit.getcontext() == "$lang['credit']" 
 97          assert "#. comment" in str(pofile) 
 98          assert pounit.source == "" 
  99   
101          """checks that if we translate an empty definition it makes it into the PO""" 
102          phptemplate = '''$lang['credit'] = '';''' 
103          phpsource = '''$lang['credit'] = 'Translators Names';''' 
104          pofile = self.php2po(phpsource, phptemplate) 
105          pounit = self.singleelement(pofile) 
106          assert pounit.getlocations() == ["$lang['credit']"] 
107          assert pounit.source == "" 
108          assert pounit.target == "Translators Names" 
 109   
111          """check that we can carry newlines that appear in the entry value into the PO""" 
112          phpsource = r'''$lang['name'] = 'value1\nvalue2';''' 
113          pofile = self.php2po(phpsource) 
114          unit = self.singleelement(pofile) 
115          assert unit.source == "value1\nvalue2" 
 116   
118          """checks that if we have spaces in the name we create a good PO with no spaces""" 
119          phptemplate = '''$lang[ 'credit' ] = 'Something';''' 
120          phpsource = '''$lang[ 'credit' ] = ''n Ding';''' 
121          pofile = self.php2po(phpsource, phptemplate) 
122          pounit = self.singleelement(pofile) 
123          assert pounit.getlocations() == ["$lang['credit']"] 
 126      """Tests running actual php2po commands on files""" 
127      convertmodule = php2po 
128      defaultoptions = {"progress": "none"} 
129   
 136