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-2009 Zuza Software Foundation
     5  #
     6  # This file is part of the Translate Toolkit.
     7  #
     8  # This program 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  # This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
    20
    21  """This module represents French language.
    22
    23  For more information, see U{http://en.wikipedia.org/wiki/French_language}
    24  """
    25
    26  from translate.lang import common
    27  import re
    28
    29 -def guillemets(text):
    30      def convertquotation(match):
    31          prefix = match.group(1)
    32          # Let's see that we didn't perhaps match an XML tag property like
    33          # <a href="something">
    34          if prefix == u"=":
    35              return match.group(0)
    36          return u"%s« %s »" % (prefix, match.group(2))
    37
    38      # Check that there is an even number of double quotes, otherwise it is
    39      # probably not safe to convert them.
    40      if text.count(u'"') % 2 == 0:
    41          text = re.sub('(.|^)"([^"]+)"', convertquotation, text)
    42      singlecount = text.count(u"'")
    43      if singlecount:
    44          if singlecount % 2 == 0:
    45              text = re.sub("(.|^)'([^']+)'", convertquotation, text)
    46          if singlecount == text.count(u'`'):
    47              text = re.sub("(.|^)`([^']+)'", convertquotation, text)
    48      text = re.sub(u'(.|^)“([^”]+)”', convertquotation, text)
    49      return text
    50
    51 -class fr(common.Common):
    52      """This class represents French."""
    53
    54      validaccel = u"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" + u"éÉ"
    55
    56      # According to http://french.about.com/library/writing/bl-punctuation.htm,
    57      # in French, a space is required both before and after all two- (or more)
    58      # part punctuation marks and symbols, including : ; « » ! ? % $ # etc.
    59      puncdict = {}
    60      for c in u":;!?#":
    61          puncdict[c] = u" %s" % c
    62      # TODO: consider adding % and $, but think about the consequences of how
    63      # they could be part of variables
    64
    65 -    def punctranslate(cls, text):
    66          """Implement some extra features for quotation marks.
    67
    68          Known shortcomings:
    69              - % and $ are not touched yet for fear of variables
    70              - Double spaces might be introduced
    71          """
    72          text = super(cls, cls).punctranslate(text)
    73          # We might get problems where we got a space in URIs such as
    74          # http ://
    75          text = text.replace(u" ://", "://")
    76          return guillemets(text)
    77      punctranslate = classmethod(punctranslate)
    78