Package translate :: Package lang :: Module fr
[hide private]
[frames] | no frames]

Source Code for Module translate.lang.fr

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  #  
 4  # Copyright 2007 Zuza Software Foundation 
 5  #  
 6  # This file is part of translate. 
 7  # 
 8  # translate is free software; you can redistribute it and/or modify 
 9  # it under the terms of the GNU General Public License as published by 
10  # the Free Software Foundation; either version 2 of the License, or 
11  # (at your option) any later version. 
12  #  
13  # translate is distributed in the hope that it will be useful, 
14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  # GNU General Public License for more details. 
17  # 
18  # You should have received a copy of the GNU General Public License 
19  # along with translate; if not, write to the Free Software 
20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
21   
22  """This module represents French language. 
23   
24  For more information, see U{http://en.wikipedia.org/wiki/French_language} 
25  """ 
26   
27  from translate.lang import common 
28  import re 
29   
30 -def guillemets(text):
31 def convertquotation(match): 32 prefix = match.group(1) 33 # Let's see that we didn't perhaps match an XML tag property like 34 # <a href="something"> 35 if prefix == u"=": 36 return match.group(0) 37 return u"%s« %s »" % (prefix, match.group(2))
38 39 # Check that there is an even number of double quotes, otherwise it is 40 # probably not safe to convert them. 41 if text.count(u'"') % 2 == 0: 42 text = re.sub('(.|^)"([^"]+)"', convertquotation, text) 43 singlecount = text.count(u"'") 44 if singlecount: 45 if singlecount % 2 == 0: 46 text = re.sub("(.|^)'([^']+)'", convertquotation, text) 47 if singlecount == text.count(u'`'): 48 text = re.sub("(.|^)`([^']+)'", convertquotation, text) 49 text = re.sub(u'(.|^)“([^”]+)”', convertquotation, text) 50 return text 51
52 -class fr(common.Common):
53 """This class represents French.""" 54 55 # According to http://french.about.com/library/writing/bl-punctuation.htm, 56 # in French, a space is required both before and after all two- (or more) 57 # part punctuation marks and symbols, including : ; « » ! ? % $ # etc. 58 puncdict = {} 59 for c in u":;!?#": 60 puncdict[c] = u" %s" % c 61 # TODO: consider adding % and $, but think about the consequences of how 62 # they could be part of variables 63
64 - def punctranslate(cls, text):
65 """Implement some extra features for quotation marks. 66 67 Known shortcomings: 68 - % and $ are not touched yet for fear of variables 69 - Double spaces might be introduced 70 """ 71 text = super(cls, cls).punctranslate(text) 72 # We might get problems where we got a space in URIs such as 73 # http :// 74 text = text.replace(u" ://", "://") 75 return guillemets(text)
76 punctranslate = classmethod(punctranslate)
77