Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 089d87e

Browse files
committed
finished localization
1 parent a5c3bf3 commit 089d87e

18 files changed

+202
-83
lines changed

main.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from src.startup import Startup
55
from src.utilities.config.app_config import default_config
6+
from src.localization.localization import Localizer
67

78
kernel32 = ctypes.WinDLL('kernel32')
89
user32 = ctypes.WinDLL('user32')
@@ -19,7 +20,7 @@
1920
except:
2021
user32.ShowWindow(hWnd, 1)
2122
kernel32.SetConsoleMode(kernel32.GetStdHandle(-10), (0x4|0x80|0x20|0x2|0x10|0x1|0x40|0x100))
22-
color_print([("Red bold","the program encountered an error; please create an issue with the traceback below if this problem persists")])
23+
color_print([("Red bold",Localizer.get_localized_text("prints","errors","error_message"))])
2324
traceback.print_exc()
24-
input("press enter to exit...")
25+
input(Localizer.get_localized_text("prints","errors","exit"))
2526
os._exit(1)

src/content/content_loader.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import requests
22

3+
from ..localization.localization import Localizer
4+
35
class Loader:
46

57
@staticmethod
68
def fetch(endpoint="/"):
7-
data = requests.get(f"https://valorant-api.com/v1{endpoint}")
9+
data = requests.get(f"https://valorant-api.com/v1{endpoint}?language=all")
810
return data.json()
911

1012
@staticmethod
@@ -33,7 +35,6 @@ def load_all_content(client):
3335
"TeamSpectate": "Observer",
3436
"TeamOneCoaches": "Defender Coach",
3537
"TeamTwoCoaches": "Attacker Coach",
36-
"Red": ""
3738
},
3839
"team_image_aliases": {
3940
"TeamOne": "team_defender",
@@ -63,27 +64,31 @@ def load_all_content(client):
6364
for agent in agents:
6465
content_data["agents"].append({
6566
"uuid": agent["uuid"],
66-
"display_name": agent["displayName"],
67+
"display_name": agent["displayName"]["en-US"],
68+
"display_name_localized": agent["displayName"][Localizer.locale],
6769
"internal_name": agent["developerName"]
6870
})
6971

7072
for game_map in maps:
7173
content_data["maps"].append({
7274
"uuid": game_map["uuid"],
73-
"display_name": game_map["displayName"],
75+
"display_name": game_map["displayName"]["en-US"],
76+
"display_name_localized": game_map["displayName"][Localizer.locale],
7477
"path": game_map["mapUrl"],
7578
"internal_name": game_map["mapUrl"].split("/")[-1]
7679
})
7780

7881
for mode in modes:
7982
content_data["modes"].append({
8083
"uuid": mode["uuid"],
81-
"display_name": mode["displayName"],
84+
"display_name": mode["displayName"]["en-US"],
85+
"display_name_localized": mode["displayName"][Localizer.locale],
8286
})
8387

8488
for tier in comp_tiers:
8589
content_data["comp_tiers"].append({
86-
"display_name": tier["tierName"],
90+
"display_name": tier["tierName"]["en-US"],
91+
"display_name_localized": tier["tierName"][Localizer.locale],
8792
"id": tier["tier"],
8893
})
8994

src/localization/locales.py

+91-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Locales = {
2-
"en-us": {
2+
"en-US": {
33
"config": {
44
"version": "version",
55
"region": "region",
@@ -24,27 +24,97 @@
2424
"rank": "rank",
2525
"map": "map",
2626
},
27-
"config_modification": {
28-
"select_option": "select a configuration option",
29-
"config_saved": "config saved! restart the program for changes to take effect.",
30-
"set_prompt": "set value for"
27+
"prints": {
28+
"config_modification": {
29+
"select_option": "select a configuration option",
30+
"config_saved": "config saved! restart the program for changes to take effect.",
31+
"set_prompt": "set value for"
32+
},
33+
"startup": {
34+
"wait_for_rpc": "waiting for rpc client",
35+
"discord_not_detected": "discord not detected! starting game without presence...",
36+
"starting_valorant": "starting VALORANT",
37+
"startup_successful": "program startup successful, hiding window in 5 seconds",
38+
"waiting_for_presence": "waiting for presence...",
39+
"waiting_for_valorant": "waiting for VALORANT...",
40+
"autodetect_region": "attempting to autodetect region",
41+
"autodetected_region": "autodetected region:",
42+
},
43+
"presence": {
44+
"presence_running": "presence running!",
45+
},
46+
"systray": {
47+
"hiding_window": "hiding window",
48+
},
49+
"errors": {
50+
"error_message": "the program encountered an error: please create an issue with the traceback below if this problem persists",
51+
"exit": "press enter to exit...",
52+
},
53+
"version_checker": {
54+
"update_available": "an update is available! download it at",
55+
"checker_error": "unable to check for updates!",
56+
}
3157
},
32-
"startup": {
33-
"wait_for_rpc": "waiting for rpc client",
34-
"discord_not_detected": "discord not detected! starting game without presence...",
35-
"starting_valorant": "starting VALORANT",
36-
"startup_successful": "program startup successful, hiding window in 5 seconds",
37-
"waiting_for_presence": "waiting for presence...",
38-
"waiting_for_valorant": "waiting for VALORANT...",
39-
"autodetect_region": "attempting to autodetect region",
40-
"autodetected_region": "autodetected region:",
58+
"presences": {
59+
"party_states": {
60+
"open": "Open Party",
61+
"solo": "Solo",
62+
"in_party": "In a Party",
63+
},
64+
"client_states": {
65+
"away": "Away",
66+
"menu": "Menu",
67+
"custom_setup": "Custom Setup",
68+
"queue": "Queue",
69+
"pregame": "Pregame",
70+
},
71+
"team_names": {
72+
"TeamOne": "Defender",
73+
"TeamTwo": "Attacker",
74+
"TeamSpectate": "Observer",
75+
"TeamOneCoaches": "Defender Coach",
76+
"TeamTwoCoaches": "Attacker Coach",
77+
},
78+
"modes": {
79+
"newmap": "New Map",
80+
"competitive": "Competitive",
81+
"unrated": "Unrated",
82+
"spikerush": "Spike Rush",
83+
"deathmatch": "Deathmatch",
84+
"ggteam": "Escalation",
85+
"onefa": "Replication",
86+
"custom": "Custom",
87+
"snowball": "Snowball Fight",
88+
"": "Custom",
89+
},
90+
"pregame": {
91+
"selecting": "Selecting",
92+
"locked": "Locked",
93+
},
94+
"leveling":{
95+
"level": "Level",
96+
},
97+
"startup": {
98+
"loading": "Loading",
99+
"view_github": "View on GitHub",
100+
}
41101
},
42-
43-
},
44-
"en-uk": {
45-
# wo'oh bo'oh innit? on a chewsday?
46-
},
47-
"br": {
48-
49102
},
103+
"ar-AE": {},
104+
"de-DE": {},
105+
"es-ES": {},
106+
"es-MX": {},
107+
"fr-FR": {},
108+
"id-ID": {},
109+
"it-IT": {},
110+
"ja-JP": {},
111+
"ko-KR": {},
112+
"pl-PL": {},
113+
"pt-BR": {},
114+
"ru-RU": {},
115+
"th-TH": {},
116+
"tr-TR": {},
117+
"vi-VN": {},
118+
"zh-CN": {},
119+
"zh-TW": {},
50120
}

src/localization/localization.py

+28-11
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,40 @@
33

44
class Localizer:
55

6-
locale = "en-us"
6+
locale = "en-US"
77
config = None
88

99
@staticmethod
10-
def get_localized_text(section,key):
11-
localized = Locales[Localizer.locale].get(key)
12-
if localized is not None:
13-
return Locales[Localizer.locale][section][key]
14-
return Locales["en-us"][section][key]
10+
def get_localized_text(*keys):
11+
12+
def get_default(*keys):
13+
localized = Locales["en-US"]
14+
for key in keys:
15+
localized = localized.get(key)
16+
return localized
17+
18+
try:
19+
localized = Locales[Localizer.locale]
20+
for key in keys:
21+
if localized is None:
22+
get_default(*keys)
23+
localized = localized.get(key)
24+
if localized is not None:
25+
return localized
26+
except:
27+
return get_default(*keys)
28+
1529

1630
@staticmethod
1731
def get_config_key(key):
18-
for k,value in Locales[Localizer.locale]["config"].items():
19-
#print(f"{k}/{value}")
20-
if k == key:
21-
return value
22-
return key
32+
try:
33+
for k,value in Locales[Localizer.locale]["config"].items():
34+
#print(f"{k}/{value}")
35+
if k == key:
36+
return value
37+
return key
38+
except:
39+
return key
2340

2441
@staticmethod
2542
def unlocalize_key(key):

src/presence/presence.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from ..utilities.config.app_config import Config
77
from ..content.content_loader import Loader
8+
from ..localization.localization import Localizer
89
from .presences import (ingame,menu,startup,pregame)
910

1011
kernel32 = ctypes.WinDLL('kernel32')
@@ -26,7 +27,7 @@ def __init__(self):
2627
def main_loop(self):
2728
try:
2829
self.content_data = Loader.load_all_content(self.client)
29-
color_print([("LimeGreen bold", "presence running!")])
30+
color_print([("LimeGreen bold", Localizer.get_localized_text("prints","presence","presence_running"))])
3031
while True:
3132
presence_data = self.client.fetch_presence()
3233
if presence_data is not None:
@@ -40,9 +41,9 @@ def main_loop(self):
4041
except Exception as e:
4142
user32.ShowWindow(hWnd, 1)
4243
kernel32.SetConsoleMode(kernel32.GetStdHandle(-10), (0x4|0x80|0x20|0x2|0x10|0x1|0x40|0x100))
43-
color_print([("Red bold","the program encountered an error: please create an issue with the traceback below if this problem persists")])
44+
color_print([("Red bold",Localizer.get_localized_text("prints","errors","error_message"))])
4445
traceback.print_exc()
45-
input("press enter to exit...")
46+
input(Localizer.get_localized_text("prints","errors","exit"))
4647
os._exit(1)
4748

4849
def update_presence(self,ptype,data=None):

src/presence/presence_utilities.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import iso8601
22
from ..utilities.logging import Logger
3+
from ..localization.localization import Localizer
34
debug = Logger.debug
45

56
class Utilities:
67

78
@staticmethod
89
def build_party_state(data):
9-
party_state = "Solo"
10+
party_state = Localizer.get_localized_text("presences","party_states","solo")
1011
if data["partySize"] > 1:
11-
party_state = "In a Party"
12+
party_state = Localizer.get_localized_text("presences","party_states","in_party")
1213
elif data["partyAccessibility"] == "OPEN":
13-
party_state = "Open Party"
14+
party_state = Localizer.get_localized_text("presences","party_states","open")
1415

1516
party_size = [data["partySize"],data["maxPartySize"]] if data["partySize"] > 1 or data["partyAccessibility"] == "OPEN" else None
1617
if party_size is not None:
@@ -40,30 +41,31 @@ def fetch_rank_data(client,content_data):
4041
if tier["id"] == mmr["CompetitiveTier"]:
4142
rank_data = tier
4243
rank_image = f"rank_{rank_data['id']}"
43-
rank_text = f"{rank_data['display_name']} - {mmr['RankedRating']}RR"
44+
rank_text = f"{rank_data['display_name_localized']} - {mmr['RankedRating']}RR"
4445

4546
return rank_image, rank_text
4647

4748
@staticmethod
4849
def fetch_map_data(data,content_data):
4950
for gmap in content_data["maps"]:
5051
if gmap["path"] == data["matchMap"]:
51-
return gmap["display_name"]
52+
return gmap["display_name"], gmap["display_name_localized"]
5253
return ""
5354

5455
@staticmethod
5556
def fetch_agent_data(uuid,content_data):
5657
for agent in content_data["agents"]:
5758
if agent["uuid"] == uuid:
5859
agent_image = f"agent_{agent['display_name'].lower().replace('/','')}"
59-
agent_name = agent['display_name']
60+
agent_name = agent['display_name_localized']
6061
return agent_image, agent_name
61-
return "rank_0","A Secret Agent"
62+
return "rank_0","?"
6263

6364
@staticmethod
6465
def fetch_mode_data(data, content_data):
6566
image = f"mode_{data['queueId'] if data['queueId'] in content_data['modes_with_icons'] else 'discovery'}"
6667
mode_name = content_data['queue_aliases'][data['queueId']] if data["queueId"] in content_data["queue_aliases"].keys() else "Custom"
68+
mode_name = Utilities.localize_content_name(mode_name, "presences", "modes", data["queueId"])
6769
return image,mode_name
6870

6971
@staticmethod
@@ -72,10 +74,17 @@ def get_content_preferences(client,pref,presence,player_data,content_data):
7274
return Utilities.fetch_rank_data(client,content_data)
7375
if pref == "map":
7476
gmap = Utilities.fetch_map_data(presence,content_data)
75-
return f"splash_{gmap.lower()}",gmap
77+
return f"splash_{gmap[0].lower()}",gmap[1]
7678
if pref == "agent":
7779
return Utilities.fetch_agent_data(player_data["CharacterID"],content_data)
7880

81+
@staticmethod
82+
def localize_content_name(default,*keys):
83+
localized = Localizer.get_localized_text(*keys)
84+
if localized is not None:
85+
return localized
86+
return default
87+
7988
@staticmethod
8089
def get_join_state(client,config,presence=None):
8190
'''

src/presence/presences/ingame_presences/range.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def __init__(self,rpc,client,data,match_id,content_data,config):
1414
self.puuid = self.client.puuid
1515

1616
self.start_time = time.time()
17-
self.map_name = "Range"
17+
self.map_name = Utilities.localize_content_name("Range","presences","maps","range")
1818
self.map_image = "splash_range"
19-
self.mode_name = "Range"
19+
self.mode_name = Utilities.localize_content_name("Range","presences","maps","range")
2020
self.small_image = "mode_unrated"
2121
self.small_text = None
2222

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from ....localization.localization import Localizer
2+
from ...presence_utilities import Utilities
3+
14
def presence(rpc,client=None,data=None,content_data=None,config=None):
5+
_, mode_name = Utilities.fetch_mode_data(data,content_data)
26
rpc.update(
3-
state="Away",
4-
details=f"Menu - {content_data['queue_aliases'][data['queueId']] if data['queueId'] != '' else 'Custom Setup'}",
7+
state=f"{mode_name}",
8+
details=f"{Localizer.get_localized_text('presences','client_states','away')}",
59
large_image="game_icon_yellow",
610
large_text="VALORANT",
711
)

0 commit comments

Comments
 (0)