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