Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
quasiyoke committed Jan 17, 2016
2 parents 41f2eaf + 83d8153 commit e2e9641
Show file tree
Hide file tree
Showing 19 changed files with 817 additions and 322 deletions.
5 changes: 2 additions & 3 deletions README.rst
Expand Up @@ -61,12 +61,11 @@ Roadmap
* 0.2 Storing data at MySQL
* 0.3 Partner's sex, language choosing
* 0.4 Translate interface to various languages
* 1.0 Stickers
* 1.0 Almost all messages types support except replies and forwards
* 1.1 Customizable greetings message
* 1.2 /oops -- return last partner!
* 1.3 Don't talk with recent partners
* 1.4 Instant bots messages
* 1.5 Replies
* 1.4 Replies

Contributing
------------
Expand Down
72 changes: 43 additions & 29 deletions randtalkbot/i18n.py
Expand Up @@ -12,33 +12,6 @@
from collections import OrderedDict
from os import path

SUPPORTED_LANGUAGES_NAMES_CHOICES = (
('en', 'English'),
('pt', 'Português'),
('it', 'Italiano'),
('ru', 'Русский'),
)
LANGUAGES_CODES_TO_NAMES = \
{item[0].lower(): item[1] for item in SUPPORTED_LANGUAGES_NAMES_CHOICES}
SUPPORTED_LANGUAGES_NAMES = list(zip(*SUPPORTED_LANGUAGES_NAMES_CHOICES))[1]
LANGUAGES_NAMES_TO_CODES = \
{item[1].lower(): item[0] for item in SUPPORTED_LANGUAGES_NAMES_CHOICES}

for language in pycountry.languages:
try:
LANGUAGES_NAMES_TO_CODES[language.name.lower()] = language.iso639_1_code
LANGUAGES_NAMES_TO_CODES[language.iso639_1_code] = language.iso639_1_code
# Not override previosly specified native name.
if language.iso639_1_code not in LANGUAGES_CODES_TO_NAMES:
LANGUAGES_CODES_TO_NAMES[language.iso639_1_code] = language.name
# If it has'n even simplest fields, that's not the languages we are interested in.
except AttributeError:
continue
try:
LANGUAGES_NAMES_TO_CODES[language.iso639_2T_code] = language.iso639_1_code
except AttributeError:
pass

class LanguageNotFoundError(Exception):
def __init__(self, name):
super(LanguageNotFoundError, self).__init__('Language \"{0}\" wasn\'t found.'.format(name))
Expand All @@ -62,7 +35,7 @@ def _get_language_code(name):
except KeyError:
raise LanguageNotFoundError(name)

def get_language_name(code):
def _get_language_name(code):
'''
@throws LanguageNotFoundError
'''
Expand All @@ -71,11 +44,21 @@ def get_language_name(code):
except KeyError:
raise LanguageNotFoundError(code)

def get_languages_names(codes):
'''
@throws LanguageNotFoundError
'''
names = map(_get_language_name, codes)
return ', '.join(names)

def get_languages_codes(names_str):
'''
@throws LanguageNotFoundError
'''
names = [name.strip() for name in names_str.split(',')]
names = names_str.strip().lower()
if names in SAME_LANGUAGE_NAMES:
return ['same']
names = [name.strip() for name in names.split(',')]
names = filter(bool, names)
names = map(_get_language_code, names)
names = _get_deduplicated(names)
Expand All @@ -102,3 +85,34 @@ def get_translations():
for filename in os.listdir(LOCALE_DIR):
if os.path.isdir(os.path.join(LOCALE_DIR, filename)):
yield get_translation([filename])

SUPPORTED_LANGUAGES_NAMES_CHOICES = (
('en', 'English'),
('pt', 'Português'),
('it', 'Italiano'),
('ru', 'Русский'),
)
LANGUAGES_CODES_TO_NAMES = \
{item[0].lower(): item[1] for item in SUPPORTED_LANGUAGES_NAMES_CHOICES}
SUPPORTED_LANGUAGES_NAMES = list(zip(*SUPPORTED_LANGUAGES_NAMES_CHOICES))[1]
LANGUAGES_NAMES_TO_CODES = \
{item[1].lower(): item[0] for item in SUPPORTED_LANGUAGES_NAMES_CHOICES}
SAME_LANGUAGE_NAMES = []
for translation in get_translations():
SAME_LANGUAGE_NAMES.append(translation('Leave the language unchanged').lower())
SAME_LANGUAGE_NAMES.append(translation('Leave the languages unchanged').lower())

for language in pycountry.languages:
try:
LANGUAGES_NAMES_TO_CODES[language.name.lower()] = language.iso639_1_code
LANGUAGES_NAMES_TO_CODES[language.iso639_1_code] = language.iso639_1_code
# Not override previosly specified native name.
if language.iso639_1_code not in LANGUAGES_CODES_TO_NAMES:
LANGUAGES_CODES_TO_NAMES[language.iso639_1_code] = language.name
# If it has'n even simplest fields, that's not the languages we are interested in.
except AttributeError:
continue
try:
LANGUAGES_NAMES_TO_CODES[language.iso639_2T_code] = language.iso639_1_code
except AttributeError:
pass
Binary file modified randtalkbot/locale/en/LC_MESSAGES/randtalkbot.mo
Binary file not shown.
56 changes: 43 additions & 13 deletions randtalkbot/locale/en/LC_MESSAGES/randtalkbot.po
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: randtalkbot\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-16 19:04+0300\n"
"POT-Creation-Date: 2016-01-17 10:54+0300\n"
"PO-Revision-Date: 2016-01-16 10:10+0300\n"
"Last-Translator: Pyotr Ermishkin <quasiyoke@gmail.com>\n"
"Language-Team: English\n"
Expand Down Expand Up @@ -41,15 +41,15 @@ msgstr "Looking for partner was stopped"
msgid "Your partner has left chat. Feel free to /begin a new conversation."
msgstr "Your partner has left chat. 😿 Feel free to /begin a new conversation."

#: build/lib/randtalkbot/stranger.py:160 randtalkbot/stranger.py:160
#: build/lib/randtalkbot/stranger.py:160 randtalkbot/stranger.py:162
msgid "Looking for a stranger for you."
msgstr "Looking for a stranger for you 🤔"

#: build/lib/randtalkbot/stranger.py:169 randtalkbot/stranger.py:169
#: build/lib/randtalkbot/stranger.py:169 randtalkbot/stranger.py:171
msgid "Here's another stranger. Have fun!"
msgstr ""
msgstr "Here's another stranger. Have fun 🤗"

#: build/lib/randtalkbot/stranger.py:173 randtalkbot/stranger.py:173
#: build/lib/randtalkbot/stranger.py:173 randtalkbot/stranger.py:175
msgid "Your partner is here. Have a nice chat!"
msgstr "Your partner is here. Have a nice chat 🤗"

Expand Down Expand Up @@ -104,7 +104,7 @@ msgid "Messages of this type aren't supported."
msgstr "Messages of this type aren't supported 😞"

#: build/lib/randtalkbot/stranger_setup_wizard.py:48
#: randtalkbot/stranger_setup_wizard.py:48
#: randtalkbot/stranger_setup_wizard.py:49
msgid ""
"Thank you. Use /begin to start looking for a conversational partner, once "
"you're matched you can use /end to end the conversation."
Expand All @@ -113,28 +113,28 @@ msgstr ""
"once you're matched you can use /end to finish the conversation."

#: build/lib/randtalkbot/stranger_setup_wizard.py:73
#: randtalkbot/stranger_setup_wizard.py:73
#: randtalkbot/stranger_setup_wizard.py:74
#, python-brace-format
msgid "Language \"{0}\" wasn't found."
msgstr "Language “{0}” wasn't found. 😳 Try to specify language in English."

#: build/lib/randtalkbot/stranger_setup_wizard.py:78
#: randtalkbot/stranger_setup_wizard.py:78
#: randtalkbot/stranger_setup_wizard.py:79
msgid "Please specify at least one language."
msgstr "Please specify at least one language"

#: build/lib/randtalkbot/stranger_setup_wizard.py:91
#: build/lib/randtalkbot/stranger_setup_wizard.py:109
#: randtalkbot/stranger_setup_wizard.py:91
#: randtalkbot/stranger_setup_wizard.py:109
#: randtalkbot/stranger_setup_wizard.py:92
#: randtalkbot/stranger_setup_wizard.py:110
#, python-brace-format
msgid "Unknown sex: \"{0}\" -- is not a valid sex name."
msgstr ""
"Unknown sex: “{0}” — is not a valid sex name. Are you sure you aren't "
"mistaken? 😉"

#: build/lib/randtalkbot/stranger_setup_wizard.py:124
#: randtalkbot/stranger_setup_wizard.py:124
#: randtalkbot/stranger_setup_wizard.py:135
msgid ""
"Enumerate the languages you speak like this: \"English, Italian\" -- in "
"descending order of your speaking convenience or just pick one at special "
Expand All @@ -145,7 +145,7 @@ msgstr ""
"keyboard."

#: build/lib/randtalkbot/stranger_setup_wizard.py:133
#: randtalkbot/stranger_setup_wizard.py:133
#: randtalkbot/stranger_setup_wizard.py:158
msgid ""
"Set up your sex. If you pick \"Not Specified\" you can't choose your "
"partner's sex."
Expand All @@ -154,6 +154,36 @@ msgstr ""
"sex."

#: build/lib/randtalkbot/stranger_setup_wizard.py:139
#: randtalkbot/stranger_setup_wizard.py:139
#: randtalkbot/stranger_setup_wizard.py:164
msgid "Choose your partner's sex"
msgstr "Choose your partner's sex"

#: randtalkbot/stranger_setup_wizard.py:140
msgid "Leave the language unchanged"
msgstr "Leave the language unchanged"

#: randtalkbot/stranger_setup_wizard.py:141
#, python-brace-format
msgid ""
"Your current language is {0}. Enumerate the languages you speak like this: "
"\"English, Italian\" -- in descending order of your speaking convenience or "
"just pick one at special keyboard."
msgstr ""
"Your current language is {0}. Enumerate the languages you speak like this: "
"“English, Italian” — in descending order of your speaking convenience or just pick one "
"at special keyboard."

#: randtalkbot/stranger_setup_wizard.py:145
msgid "Leave the languages unchanged"
msgstr "Leave the languages unchanged"

#: randtalkbot/stranger_setup_wizard.py:146
#, python-brace-format
msgid ""
"Your current languages are: {0}. Enumerate the languages you speak the same "
"way -- in descending order of your speaking convenience or just pick one at "
"special keyboard."
msgstr ""
"Your current languages are: {0}. Enumerate the languages you speak the same way, "
"in descending order of your speaking convenience or just pick one "
"at special keyboard."
Binary file modified randtalkbot/locale/ru/LC_MESSAGES/randtalkbot.mo
Binary file not shown.
64 changes: 51 additions & 13 deletions randtalkbot/locale/ru/LC_MESSAGES/randtalkbot.po
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: randtalkbot\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-16 19:04+0300\n"
"POT-Creation-Date: 2016-01-17 10:54+0300\n"
"PO-Revision-Date: 2016-01-16 10:10+0300\n"
"Last-Translator: Pyotr Ermishkin <quasiyoke@gmail.com>\n"
"Language-Team: Russian\n"
Expand Down Expand Up @@ -42,15 +42,15 @@ msgid "Your partner has left chat. Feel free to /begin a new conversation."
msgstr ""
"Собеседник покинул чат. 😿 Чтобы начать новый разговор, скомандуйте /begin."

#: build/lib/randtalkbot/stranger.py:160 randtalkbot/stranger.py:160
#: build/lib/randtalkbot/stranger.py:160 randtalkbot/stranger.py:162
msgid "Looking for a stranger for you."
msgstr "Идет подбор партнера 🤔"

#: build/lib/randtalkbot/stranger.py:169 randtalkbot/stranger.py:169
#: build/lib/randtalkbot/stranger.py:169 randtalkbot/stranger.py:171
msgid "Here's another stranger. Have fun!"
msgstr ""
msgstr "Подобран новый собеедник. Общайтесь на здоровье 🤗"

#: build/lib/randtalkbot/stranger.py:173 randtalkbot/stranger.py:173
#: build/lib/randtalkbot/stranger.py:173 randtalkbot/stranger.py:175
msgid "Your partner is here. Have a nice chat!"
msgstr "Собеседник найден. Приятного общения 🤗"

Expand Down Expand Up @@ -105,7 +105,7 @@ msgid "Messages of this type aren't supported."
msgstr "Сообщения такого типа не поддерживаются 😞"

#: build/lib/randtalkbot/stranger_setup_wizard.py:48
#: randtalkbot/stranger_setup_wizard.py:48
#: randtalkbot/stranger_setup_wizard.py:49
msgid ""
"Thank you. Use /begin to start looking for a conversational partner, once "
"you're matched you can use /end to end the conversation."
Expand All @@ -115,7 +115,7 @@ msgstr ""
"выполнив /end."

#: build/lib/randtalkbot/stranger_setup_wizard.py:73
#: randtalkbot/stranger_setup_wizard.py:73
#: randtalkbot/stranger_setup_wizard.py:74
#, python-brace-format
msgid "Language \"{0}\" wasn't found."
msgstr ""
Expand All @@ -125,7 +125,7 @@ msgstr ""
"Language “{0}” wasn't found. Try to specify language in English."

#: build/lib/randtalkbot/stranger_setup_wizard.py:78
#: randtalkbot/stranger_setup_wizard.py:78
#: randtalkbot/stranger_setup_wizard.py:79
msgid "Please specify at least one language."
msgstr ""
"Укажите пожалуйста хоть один язык\n"
Expand All @@ -134,14 +134,14 @@ msgstr ""

#: build/lib/randtalkbot/stranger_setup_wizard.py:91
#: build/lib/randtalkbot/stranger_setup_wizard.py:109
#: randtalkbot/stranger_setup_wizard.py:91
#: randtalkbot/stranger_setup_wizard.py:109
#: randtalkbot/stranger_setup_wizard.py:92
#: randtalkbot/stranger_setup_wizard.py:110
#, python-brace-format
msgid "Unknown sex: \"{0}\" -- is not a valid sex name."
msgstr "Непонятный пол: «{0}». Здесь точно нет никакой ошибки? 😉"

#: build/lib/randtalkbot/stranger_setup_wizard.py:124
#: randtalkbot/stranger_setup_wizard.py:124
#: randtalkbot/stranger_setup_wizard.py:135
msgid ""
"Enumerate the languages you speak like this: \"English, Italian\" -- in "
"descending order of your speaking convenience or just pick one at special "
Expand All @@ -156,7 +156,7 @@ msgstr ""
"keyboard."

#: build/lib/randtalkbot/stranger_setup_wizard.py:133
#: randtalkbot/stranger_setup_wizard.py:133
#: randtalkbot/stranger_setup_wizard.py:158
msgid ""
"Set up your sex. If you pick \"Not Specified\" you can't choose your "
"partner's sex."
Expand All @@ -165,6 +165,44 @@ msgstr ""
"указано»."

#: build/lib/randtalkbot/stranger_setup_wizard.py:139
#: randtalkbot/stranger_setup_wizard.py:139
#: randtalkbot/stranger_setup_wizard.py:164
msgid "Choose your partner's sex"
msgstr "Выберите пол собеседника"

#: randtalkbot/stranger_setup_wizard.py:140
msgid "Leave the language unchanged"
msgstr "Не менять язык"

#: randtalkbot/stranger_setup_wizard.py:141
#, python-brace-format
msgid ""
"Your current language is {0}. Enumerate the languages you speak like this: "
"\"English, Italian\" -- in descending order of your speaking convenience or "
"just pick one at special keyboard."
msgstr ""
"Сейчас установлен {0} язык. Перечислите языки, которыми вы владеете, в таком формате: "
"«English, Italian» — в порядке убывания уровня ваших знаний или просто выберите ваш язык на "
"специальной «клавиатуре».\n"
"\n"
"Your current language is {0}. Enumerate the languages you speak like this: "
"“English, Italian” — in descending order of your speaking convenience or just pick one "
"at special keyboard."

#: randtalkbot/stranger_setup_wizard.py:145
msgid "Leave the languages unchanged"
msgstr "Не менять языки"

#: randtalkbot/stranger_setup_wizard.py:146
#, python-brace-format
msgid ""
"Your current languages are: {0}. Enumerate the languages you speak the same "
"way -- in descending order of your speaking convenience or just pick one at "
"special keyboard."
msgstr ""
"Сейчас выбраны следующие языки: {0}. Перечислите языки, которыми вы владеете, "
"в таком же формате, в порядке убывания уровня ваших знаний или просто выберите "
"ваш язык на специальной «клавиатуре».\n"
"\n"
"Your current languages are: {0}. Enumerate the languages you speak the same way, "
"in descending order of your speaking convenience or just pick one "
"at special keyboard."

0 comments on commit e2e9641

Please sign in to comment.