Russian: use genitive case of names in certain strings

This commit is contained in:
Manuel Cortez 2016-07-07 10:20:03 -05:00
parent e22839168d
commit 5b655d7889
3 changed files with 41 additions and 16 deletions

View File

@ -259,7 +259,7 @@ class Controller(object):
b = self.search("home_timeline") b = self.search("home_timeline")
d = [] d = []
for i in self.session.db["users"]: for i in self.session.db["users"]:
d.append((i, self.session.get_user_name(i))) d.append((i, self.session.get_user_name(i, "nom")))
for i in self.session.db["groups"]: for i in self.session.db["groups"]:
d.append((-i, self.session.get_user_name(-i))) d.append((-i, self.session.get_user_name(-i)))
a = timeline.timelineDialog([i[1] for i in d]) a = timeline.timelineDialog([i[1] for i in d])
@ -277,15 +277,15 @@ class Controller(object):
if buffertype == "audio": if buffertype == "audio":
buffer = buffers.audioBuffer(parent=self.window.tb, name="{0}_audio".format(user_id,), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], owner_id=user_id) buffer = buffers.audioBuffer(parent=self.window.tb, name="{0}_audio".format(user_id,), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], owner_id=user_id)
# Translators: {0} will be replaced with an user. # Translators: {0} will be replaced with an user.
name_ = _(u"{0}'s audios").format(user,) name_ = _(u"{0}'s audios").format(self.session.get_user_name(user_id, "gen"),)
elif buffertype == "wall": elif buffertype == "wall":
buffer = buffers.feedBuffer(parent=self.window.tb, name="{0}_feed".format(user_id,), composefunc="compose_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=user_id) buffer = buffers.feedBuffer(parent=self.window.tb, name="{0}_feed".format(user_id,), composefunc="compose_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=user_id)
# Translators: {0} will be replaced with an user. # Translators: {0} will be replaced with an user.
name_ = _(u"{0}'s wall posts").format(user,) name_ = _(u"{0}'s wall posts").format(self.session.get_user_name(user_id, "gen"),)
elif buffertype == "friends": elif buffertype == "friends":
buffer = buffers.peopleBuffer(parent=self.window.tb, name="friends_{0}".format(user_id,), composefunc="compose_person", session=self.session, endpoint="get", parent_endpoint="friends", count=5000, fields="uid, first_name, last_name, last_seen", user_id=user_id) buffer = buffers.peopleBuffer(parent=self.window.tb, name="friends_{0}".format(user_id,), composefunc="compose_person", session=self.session, endpoint="get", parent_endpoint="friends", count=5000, fields="uid, first_name, last_name, last_seen", user_id=user_id)
# Translators: {0} will be replaced with an user. # Translators: {0} will be replaced with an user.
name_ = _(u"{0}'s friends").format(user,) name_ = _(u"{0}'s friends").format(self.session.get_user_name(user_id, "friends"),)
self.buffers.append(buffer) self.buffers.append(buffer)
call_threaded(self.complete_buffer_creation, buffer=buffer, name_=name_, position=self.window.search("timelines")) call_threaded(self.complete_buffer_creation, buffer=buffer, name_=name_, position=self.window.search("timelines"))

View File

@ -90,6 +90,9 @@ class postController(object):
comments_ = [] comments_ = []
for i in self.comments["items"]: for i in self.comments["items"]:
from_ = get_user(i["from_id"], self.comments["profiles"]) from_ = get_user(i["from_id"], self.comments["profiles"])
if i.has_key("reply_to_user"):
extra_info = get_user(i["reply_to_user"], self.comments["profiles"])
from_ = _(u"{0} Has replied to {1}").format(from_, extra_info)
if len(i["text"]) > 140: if len(i["text"]) > 140:
text = i["text"][:141] text = i["text"][:141]
else: else:
@ -154,7 +157,7 @@ class postController(object):
self.get_reposts() self.get_reposts()
self.get_comments() self.get_comments()
if self.post["comments"]["can_post"] == 0: if self.post["comments"]["can_post"] == 0:
self.dialog.disable("add_comment") self.dialog.disable("comment")
if self.post["likes"]["can_like"] == 0 and self.post["likes"]["user_likes"] == 0: if self.post["likes"]["can_like"] == 0 and self.post["likes"]["user_likes"] == 0:
self.dialog.disable("like") self.dialog.disable("like")
elif self.post["likes"]["user_likes"] == 1: elif self.post["likes"]["user_likes"] == 1:

View File

@ -74,7 +74,7 @@ def compose_person(status, session):
def compose_new(status, session): def compose_new(status, session):
""" This method is used to compose an item of the news feed.""" """ This method is used to compose an item of the news feed."""
user = session.get_user_name(status["source_id"]) user = session.get_user_name(status["source_id"], case_name="nom")
if status.has_key("copy_history"): if status.has_key("copy_history"):
user = _(u"{0} has shared the {1}'s post").format(user, session.get_user_name(status["copy_history"][0]["owner_id"])) user = _(u"{0} has shared the {1}'s post").format(user, session.get_user_name(status["copy_history"][0]["owner_id"]))
message = "" message = ""
@ -100,7 +100,7 @@ def compose_new(status, session):
elif status["type"] == "friend": elif status["type"] == "friend":
msg_users = u"" msg_users = u""
for i in status["friends"]["items"]: for i in status["friends"]["items"]:
msg_users = msg_users + u"{0}, ".format(session.get_user_name(i["user_id"])) msg_users = msg_users + u"{0}, ".format(session.get_user_name(i["user_id"], "nom"))
message = _(u"{0} hadded friends: {1}").format(user, msg_users) message = _(u"{0} hadded friends: {1}").format(user, msg_users)
elif status["type"] == "video": elif status["type"] == "video":
if status["video"]["count"] == 1: if status["video"]["count"] == 1:
@ -123,14 +123,14 @@ def clean_audio(audio):
return audio return audio
def compose_message(message, session): def compose_message(message, session):
user = session.get_user_name(message["from_id"]) user = session.get_user_name(message["from_id"], "nom")
original_date = arrow.get(message["date"]) original_date = arrow.get(message["date"])
created_at = original_date.format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage()) created_at = original_date.format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage())
body = message["body"] body = message["body"]
return [u"{2}, {0} {1}".format(body, created_at, user)] return [u"{2}, {0} {1}".format(body, created_at, user)]
def compose_status(status, session): def compose_status(status, session):
user = session.get_user_name(status["from_id"]) user = session.get_user_name(status["from_id"], "nom")
if status.has_key("copy_history"): if status.has_key("copy_history"):
user = _(u"{0} has shared the {1}'s post").format(user, session.get_user_name(status["copy_history"][0]["owner_id"])) user = _(u"{0} has shared the {1}'s post").format(user, session.get_user_name(status["copy_history"][0]["owner_id"]))
message = "" message = ""
@ -270,8 +270,10 @@ class vkSession(object):
if type(data) == dict: if type(data) == dict:
num = self.order_buffer(name, data["items"], show_nextpage) num = self.order_buffer(name, data["items"], show_nextpage)
if len(data["items"]) > 0 and data["items"][0].has_key("first_name"): if len(data["items"]) > 0 and data["items"][0].has_key("first_name"):
data2 = {"profiles": [], "groups": []}
for i in data["items"]: for i in data["items"]:
self.db["users"][i["id"]] = u"{0} {1}".format(i["first_name"], i["last_name"]) data2["profiles"].append(i)
self.process_usernames(data2)
if data.has_key("profiles") and data.has_key("groups"): if data.has_key("profiles") and data.has_key("groups"):
self.process_usernames(data) self.process_usernames(data)
else: else:
@ -284,15 +286,20 @@ class vkSession(object):
num = self.order_buffer(name, data["items"], False) num = self.order_buffer(name, data["items"], False)
return num return num
def get_user_name(self, user_id): def get_user_name(self, user_id, case_name="gen"):
if user_id > 0: if user_id > 0:
if self.db["users"].has_key(user_id): if self.db["users"].has_key(user_id):
return self.db["users"][user_id] # print self.db["users"][user_id]
if self.db["users"][user_id].has_key(case_name):
return self.db["users"][user_id][case_name]
else:
print self.db["users"][user_id], self.db["users"][user_id].keys()
return self.db["users"][user_id]["nom"]
else: else:
return "no specified user" return "no specified user"
else: else:
if self.db["groups"].has_key(abs(user_id)): if self.db["groups"].has_key(abs(user_id)):
return self.db["groups"][abs(user_id)] return self.db["groups"][abs(user_id)]["nom"]
else: else:
return "no specified community" return "no specified community"
@ -308,14 +315,29 @@ class vkSession(object):
self.db["groups"][i["id"]] = i["name"] self.db["groups"][i["id"]] = i["name"]
def process_usernames(self, data): def process_usernames(self, data):
""" processes user IDS and saves them in a local storage system.
Every function wich needs to convert from an ID to user or community name will have to call the get_user_name function in this session object.
Every function that needs to save a set ot user ids for a future use needs to pass a data dictionary with a profiles key being a list of user objects.
For russian, it gets the genitive case of every name for future use."""
log.debug("Adding usernames to the local database...") log.debug("Adding usernames to the local database...")
ids = ""
for i in data["profiles"]: for i in data["profiles"]:
self.db["users"][i["id"]] = u"{0} {1}".format(i["first_name"], i["last_name"]) if self.db["users"].has_key(i["id"]) == False:
self.db["users"][i["id"]] = dict(nom=u"{0} {1}".format(i["first_name"], i["last_name"]))
ids = ids + "{0},".format(i["id"],)
gids = ""
for i in data["groups"]: for i in data["groups"]:
self.db["groups"][i["id"]] = i["name"] self.db["groups"][i["id"]] = dict(nom=i["name"])
gids = "{0},".format(i["id"],)
if not "ru" in languageHandler.getLanguage():
return
users = self.vk.client.users.get(user_ids=ids, fields="first_name, last_name", name_case="gen")
for i in users:
if self.db["users"].has_key(i["id"]):
self.db["users"][i["id"]]["gen"] = u"{0} {1}".format(i["first_name"], i["last_name"])
def get_my_data(self): def get_my_data(self):
log.debug("Getting user identifier...") log.debug("Getting user identifier...")
user = self.vk.client.users.get(fields="uid, first_name, last_name") user = self.vk.client.users.get(fields="uid, first_name, last_name")
self.user_id = user[0]["id"] self.user_id = user[0]["id"]
self.db["users"][self.user_id] = u"{0} {1}".format(user[0]["first_name"], user[0]["last_name"]) # self.db["users"][self.user_id] = u"{0} {1}".format(user[0]["first_name"], user[0]["last_name"])