Commit 1d4329c2 authored by Michal Čihař's avatar Michal Čihař

Add support for per language specific chars

And include support for Danda in Bodo language.

Fixes #940
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent b6348fd9
......@@ -31,6 +31,8 @@ CHAR_NAMES = {
u'→': ugettext_lazy('Insert tab character'),
u'↵': ugettext_lazy('Insert new line'),
u'…': ugettext_lazy('Insert horizontal ellipsis'),
u'।': ugettext_lazy('Danda'),
u'॥': ugettext_lazy('Double danda'),
}
# Quotes definition for each language, based on CLDR data
......@@ -415,6 +417,10 @@ EM_DASH_LANGS = frozenset((
'sv', 'ta', 'th', 'to', 'tr', 'uz', 'vi', 'vo', 'yi', 'zh',
))
EXTRA_CHARS = {
'brx': (u'।', u'॥'),
}
def get_quote(code, data, name):
"""
......@@ -425,19 +431,26 @@ def get_quote(code, data, name):
return name, data['ALL']
def get_char_description(char):
"""Returns verbose description of a character."""
if char in CHAR_NAMES:
return CHAR_NAMES[char]
else:
return _('Insert character {0}').format(char)
def get_special_chars(language):
"""
Returns list of special characters.
"""
for char in SPECIAL_CHARS:
if char in CHAR_NAMES:
name = CHAR_NAMES[char]
else:
name = _('Insert character {0}').format(char)
yield name, char
yield get_char_description(char), char
code = language.code.replace('_', '-').split('-')[0]
if code in EXTRA_CHARS:
for char in EXTRA_CHARS[code]:
yield get_char_description(char), char
yield get_quote(code, DOUBLE_OPEN, _('Opening double quote'))
yield get_quote(code, DOUBLE_CLOSE, _('Closing double quote'))
yield get_quote(code, SINGLE_OPEN, _('Opening single quote'))
......
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2015 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Tests for special chars.
"""
from unittest import TestCase
from weblate.lang.models import Language
from weblate.trans.specialchars import get_special_chars
class SpecialCharsTest(TestCase):
def test_af(self):
chars = list(get_special_chars(Language(code='af')))
self.assertEqual(len(chars), 10)
def test_cs(self):
chars = list(get_special_chars(Language(code='cs')))
self.assertEqual(len(chars), 9)
def test_brx(self):
chars = list(get_special_chars(Language(code='brx')))
self.assertEqual(len(chars), 9)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment