Package translate :: Package lang :: Module fa

[hide private]
[frames] | no frames]

# Source Code for Module translate.lang.fa

     1  #!/usr/bin/env python
     2  # -*- coding: utf-8 -*-
     3  #
     4  # Copyright 2007, 2010 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 Persian language.
    23
    24  For more information, see U{http://en.wikipedia.org/wiki/Persian_language}
    25  """
    26
    27  from translate.lang import common
    28
    29  import re
    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«%s»" % (prefix, match.group(2))
    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 fa(common.Common):
    56      """This class represents Persian."""
    57
    58      listseperator = u"، "
    59
    60      puncdict = {
    61          u",": u"،",
    62          u";": u"؛",
    63          u"?": u"؟",
    64          #This causes problems with variables, so commented out for now:
    65          #u"%": u"٪",
    66      }
    67
    68      ignoretests = ["startcaps", "simplecaps"]
    69      #TODO: check persian numerics
    70      #TODO: zwj and zwnj?
    71
    72 -    def punctranslate(cls, text):
    73          """Implement "French" quotation marks."""
    74          text = super(cls, cls).punctranslate(text)
    75          return guillemets(text)
    76      punctranslate = classmethod(punctranslate)
    77