-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.py
219 lines (178 loc) · 9.44 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import csv
import json
def define_env(env):
languages = [
{"id": "zh-CN", "name": "Chinese, China"},
{"id": "zh-HK", "name": "Chinese, Hong Kong"},
{"id": "zh-TW", "name": "Chinese, Taiwan"},
{"id": "hr", "name": "Croatian"},
{"id": "cs", "name": "Czech"},
{"id": "fr", "name": "French"},
{"id": "de", "name": "German"},
{"id": "hu", "name": "Hungarian"},
{"id": "id", "name": "Indonesian"},
{"id": "it", "name": "Italian"},
{"id": "ja", "name": "Japanese"},
{"id": "ko", "name": "Korean"},
{"id": "lv", "name": "Latvian"},
{"id": "pl", "name": "Polish"},
{"id": "pt", "name": "Portuguese"},
{"id": "ro", "name": "Romanian"},
{"id": "ru", "name": "Russian"},
{"id": "es", "name": "Spanish"},
{"id": "tr", "name": "Turkish"},
{"id": "vi", "name": "Vietnamese"},
{"id": "uk", "name": "Ukrainian"},
{"id": "nl", "name": "Dutch"}
]
@env.macro
def translations(gitlocalize_id:int, available_translations:list):
yes = "✅"
no = "❌"
# We are adding the intro + header of the language table
result = f"""!!! note "We need your help!"
A vast majority of strings in BentoBox and its addons can be translated into virtually any language.
However, most of the translations that are provided with BentoBox or said addons are made by the community, on which we heavily rely.
We cannot review all the content of these translations nor guarantee its quality, hence why we highly appreciate any contributions.
* If your language is not available for this addon or if you would like to improve the existing translation,
please read the [translation guidelines](../../BentoBox/Translate-BentoBox-and-addons)
and [start translating](https://gitlocalize.com/repo/{gitlocalize_id})!
* If your language is not listed below, please contact us on [Discord](https://discord.bentobox.world)
and we will setup everything so that you can start translating!
| Available | Language | Language code | Progress |
| --- | ---------- | --- | ----------- |
| ✅ | English (United States) | `en-US` | 100% (Default) |
"""
for language in languages:
available = no
if language["id"] in available_translations:
available = yes
link = f"https://gitlocalize.com/repo/{gitlocalize_id}/{language['id']}/src/main/resources/locales"
badge = f"https://gitlocalize.com/repo/{gitlocalize_id}/{language['id']}/badge.svg"
result += f"| {available} | [{language['name']}]({link}) | `{language['id']}` |  |\n"
return result
@env.macro
def addon_description(addon_name:str, beta:bool=False):
result = ""
if beta:
result += f"""!!! warning
**{addon_name}** is currently in **Beta**.\n
Keep in mind that **you are more likely to encounter bugs** and **some features might not be stable**.\n\n"""
result += f"""!!! info "Useful links"
- [GitHub repository](https://github.com/BentoBoxWorld/{addon_name})
([Releases](https://github.com/BentoBoxWorld/{addon_name}/releases))
- [Issue tracker](https://github.com/BentoBoxWorld/{addon_name}/issues)
- [Development builds](https://ci.codemc.org/job/BentoBoxWorld/job/{addon_name})
([Latest stable build](https://ci.codemc.io/job/BentoBoxWorld/job/{addon_name}/lastStableBuild/))"""
return result
@env.macro
def placeholders_bundle(gamemode_name:str):
result = ""
source = ""
# Let's read the csv file
with open('data/placeholders.csv', newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
# Analyze the source
if (row['source'] != source):
if ("[gamemode]" in row['placeholder'] or gamemode_name in row['placeholder']):
# We are in a new "source" so we have to put the header
source = row['source']
result += f"""\n## {source} placeholders
| Placeholder | Description | {source} version
| ---------- | ---------- | ---------- |
"""
if ("[gamemode]" in row['placeholder'] or gamemode_name in row['placeholder']):
result += f"| `%{row['placeholder'].replace('[gamemode]',gamemode_name)}%` | {row['desc']} | {row['version']} |\n"
return result
# Adds placeholder table to the addon pages.
@env.macro
def placeholders_source(source:str):
result = f"""!!! tip "Tip"\n
`[gamemode]` is a prefix that differs depending on the gamemode you are running.\n
The prefix is the lowercased name of the gamemode, i.e. if you are using BSkyBlock, the prefix is `bskyblock`.\n\n
Properly translated placeholders for each gamemode can be found:\n
- [AcidIsland](/en/latest/gamemodes/AcidIsland/Placeholders)
- [AOneBlock](/en/latest/gamemodes/AOneBlock/Placeholders)
- [Boxed](/en/latest/gamemodes/Boxed/Placeholders)
- [BSkyBlock](/en/latest/gamemodes/BSkyBlock/Placeholders)
- [CaveBlock](/en/latest/gamemodes/CaveBlock/Placeholders)
- [SkyGrid](/en/latest/gamemodes/SkyGrid/Placeholders).\n
Please read the main [Placeholders page](/en/latest/BentoBox/Placeholders).\n\n"""
result += f"""\n
| Placeholder | Description | {source} version
| ---------- | ---------- | ---------- |
"""
# Let's read the csv file
with open('data/placeholders.csv', newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
# Analyze the source
if (row['source'] == source):
# We are in our plugin, populate rows
result += f"| `%{row['placeholder']}%` | {row['desc']} | {row['version']} |\n"
return result
# Creates a table of requested flags type.
@env.macro
def flags_bundle(type:str):
result = ""
source = ""
# Let's read the csv file
with open('data/flags.csv', newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
# Analyze the source
if (row['source'] != source):
# We are in a new "source" so we have to put the header
source = row['source']
if (row['type'] == type) or (type == "WORLD_DEFAULT_PROTECTION" and row['type'] == "PROTECTION"):
if (type == "PROTECTION"):
result += f"""\n## {source} {type.replace("_", " ").capitalize()} flags
| | Flag ID | Flag | Description | Default | Min Rank | Max Rank |
| - | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- |
"""
else:
result += f"""\n## {source} {type.replace("_", " ").capitalize()} flags
| | Flag ID | Flag | Description | Default |
| - | ---------- | ---------- | ---------- | ---------- |
"""
if (row['type'] == type) or (type == "WORLD_DEFAULT_PROTECTION" and row['type'] == "PROTECTION"):
if (type == "PROTECTION"):
result += f"| <span class='icon-minecraft {icon_css(row['icon'])}'></span> | {row['flag']} | {row['name']} | {row['description']} | {row['default']} | {row['min']} | {row['max']} |\n"
else:
result += f"| <span class='icon-minecraft {icon_css(row['icon'])}'></span> | {row['flag']} | {row['name']} | {row['description']} | {row['default']} |\n"
return result
# Creates a table of requested flags type.
@env.macro
def flags_source(source:str, type:str):
result = ""
# Let's read the csv file
with open('data/flags.csv', newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
# Analyze the source
if (row['source'] == source):
# We are in a new "source" so we have to put the header
if (row['type'] == type) or (type == "WORLD_DEFAULT_PROTECTION" and row['type'] == "PROTECTION"):
if (type == "PROTECTION"):
result += f"""\n## {source} {type.replace("_", " ").capitalize()} flags
| | Flag ID | Flag | Description | Default | Min Rank | Max Rank |
| - | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- |
"""
result += f"| <span class='icon-minecraft {icon_css(row['icon'])}'></span> | {row['flag']} | {row['name']} | {row['description']} | {row['default']} | {row['min']} | {row['max']} |\n"
else:
result += f"""\n## {source} {type.replace("_", " ").capitalize()} flags
| | Flag ID | Flag | Description | Default |
| - | ---------- | ---------- | ---------- | ---------- |
"""
result += f"| <span class='icon-minecraft {icon_css(row['icon'])}'></span> | {row['flag']} | {row['name']} | {row['description']} | {row['default']} |\n"
return result
# Creates a table of requested flags type.
@env.macro
def icon_css(icon:str):
with open("data/minecraft-block-and-entity.json", 'r') as j:
contents = json.loads(j.read())
for entry in contents:
if icon.lower() == entry['name']:
return entry['css']
return ""