1# 2# Copyright 2007 Zuza Software Foundation 3# 4# This file is part of translate. 5# 6# translate is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# translate is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program; if not, see <http://www.gnu.org/licenses/>. 18 19"""This module represents the Spanish language. 20 21.. note:: As it only has special case code for initial inverted punctuation, 22 it could also be used for Asturian, Galician, or Catalan. 23""" 24 25 26from translate.lang import common 27 28 29class es(common.Common): 30 """This class represents Spanish.""" 31 32 @classmethod 33 def punctranslate(cls, text): 34 """Implement some extra features for inverted punctuation.""" 35 text = super().punctranslate(text) 36 # If the first sentence ends with ? or !, prepend inverted ¿ or ¡ 37 firstmatch = cls.sentencere.match(text) 38 if firstmatch is None: 39 # only one sentence (if any) - use entire string 40 first = text 41 else: 42 first = firstmatch.group() 43 # remove trailing whitespace 44 first = first.strip() 45 # protect against incorrectly handling an empty string 46 if not first: 47 return text 48 if first[-1] == "?": 49 text = "¿" + text 50 elif first[-1] == "!": 51 text = "¡" + text 52 return text 53