for git v1.5.2 (and below): chdir to the directory of the target file before executin...
[translate_toolkit.git] / lang / fr.py
blobd531b53766dd043a2ff87dc907852a10ff46cc94
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright 2007 Zuza Software Foundation
5 #
6 # This file is part of translate.
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.
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.
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
22 """This module represents French language.
24 For more information, see U{http://en.wikipedia.org/wiki/French_language}
25 """
27 from translate.lang import common
28 import re
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))
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 return text
51 class fr(common.Common):
52 """This class represents French."""
54 # According to http://french.about.com/library/writing/bl-punctuation.htm,
55 # in French, a space is required both before and after all two- (or more)
56 # part punctuation marks and symbols, including : ; « » ! ? % $ # etc.
57 puncdict = {}
58 for c in u":;!?#":
59 puncdict[c] = u" %s" % c
60 # TODO: consider adding % and $, but think about the consequences of how
61 # they could be part of variables
63 def punctranslate(cls, text):
64 """Implement some extra features for quotation marks.
66 Known shortcomings:
67 - % and $ are not touched yet for fear of variables
68 - Double spaces might be introduced
69 """
70 text = super(cls, cls).punctranslate(text)
71 return guillemets(text)
72 punctranslate = classmethod(punctranslate)