|
| 1 | +# Please do not run this unless you are Slimeist (techno-sam), the author of the script (or he has explained it to you) |
| 2 | + |
| 3 | +import os |
| 4 | +import json |
| 5 | + |
| 6 | +prefix = "block.railways." |
| 7 | + |
| 8 | +CAPITALIZE_FIRST_ONLY = False |
| 9 | +NON_CAPITALIZED_WORDS = { |
| 10 | + "ve" |
| 11 | +} |
| 12 | + |
| 13 | +colors: dict[str, str] = { |
| 14 | + "black": "siyah", |
| 15 | + "blue": "mavi", |
| 16 | + "brown": "kahverengi", |
| 17 | + "gray": "gri", |
| 18 | + "green": "yeşil", |
| 19 | + "light_blue": "açık mavi", |
| 20 | + "light_gray": "açık gri", |
| 21 | + "lime": "açık yeşil", |
| 22 | + "magenta": "eflatun", |
| 23 | + "orange": "turuncu", |
| 24 | + "pink": "pembe", |
| 25 | + "purple": "mor", |
| 26 | + "red": "kırmızı", |
| 27 | + "white": "beyaz", |
| 28 | + "yellow": "sarı", |
| 29 | + "": "" |
| 30 | +} |
| 31 | + |
| 32 | +color_keys = colors.keys() |
| 33 | + |
| 34 | +wrapping_names: dict[str, str] = { |
| 35 | + "brass": "pirinç", |
| 36 | + "copper": "bakır", |
| 37 | + "iron": "demir" |
| 38 | +} |
| 39 | + |
| 40 | +type_names = { |
| 41 | + "slashed": "kesik", |
| 42 | + "riveted": "perçinlenmiş", |
| 43 | + "plated": "kaplanmış" |
| 44 | +} |
| 45 | + |
| 46 | + |
| 47 | +def capitalize(s: str) -> str: |
| 48 | + s = s.lower() |
| 49 | + if len(s) > 0 and s.lower() not in NON_CAPITALIZED_WORDS: |
| 50 | + return s[0].upper() + s[1:] |
| 51 | + else: |
| 52 | + return s |
| 53 | + |
| 54 | + |
| 55 | +def join_with_title_case(*parts: str | tuple[str, bool]) -> str: |
| 56 | + new_parts = [] |
| 57 | + for p in parts: |
| 58 | + if type(p) == str: |
| 59 | + new_parts.append(p) |
| 60 | + elif type(p) == tuple: |
| 61 | + if p[1]: |
| 62 | + new_parts.append(p[0]) |
| 63 | + else: |
| 64 | + raise ValueError(f"Invalid type {type(p)}") |
| 65 | + new_parts = [p for p in new_parts if p != ""] |
| 66 | + new_parts = " ".join(new_parts).split(" ") |
| 67 | + if CAPITALIZE_FIRST_ONLY: |
| 68 | + new_parts[0] = capitalize(new_parts[0]) |
| 69 | + else: |
| 70 | + new_parts = [capitalize(p) for p in new_parts if p != ""] |
| 71 | + return " ".join(new_parts) |
| 72 | + |
| 73 | + |
| 74 | +def mk_boiler(wrapping: str | None) -> callable: |
| 75 | + def f(color: str) -> str: |
| 76 | + return join_with_title_case(colors[color], wrapping_names.get(wrapping, ""), ("sarılmış", wrapping is not None), "lokomotif kazanı") |
| 77 | + return f |
| 78 | + |
| 79 | + |
| 80 | +def mk_locometal(wrapping: str | None, flat: bool, typ: str | None) -> callable: |
| 81 | + """ |
| 82 | + :param wrapping: None, brass, copper, iron |
| 83 | + :param flat: true/false |
| 84 | + :param typ: slashed, riveted, plated |
| 85 | + :return: |
| 86 | + """ |
| 87 | + def f(color: str) -> str: |
| 88 | + return join_with_title_case(("Düz ve", flat), |
| 89 | + wrapping_names.get(wrapping, ""), ("sarılmış", wrapping is not None), |
| 90 | + (type_names.get(typ, ""), typ is not None), |
| 91 | + colors[color], |
| 92 | + "lokometal") |
| 93 | + return f |
| 94 | + |
| 95 | + |
| 96 | +def mk_pillar() -> callable: |
| 97 | + def f(color: str) -> str: |
| 98 | + return join_with_title_case(colors[color], "lokometal sütunu") |
| 99 | + return f |
| 100 | + |
| 101 | + |
| 102 | +def mk_smokebox() -> callable: |
| 103 | + def f(color: str) -> str: |
| 104 | + return join_with_title_case(colors[color], "lokomotif bacası") |
| 105 | + return f |
| 106 | + |
| 107 | + |
| 108 | +translations: dict[str, callable] = { |
| 109 | + "slashed_locometal": mk_locometal(None, False, "slashed"), |
| 110 | + "riveted_locometal": mk_locometal(None, False, "riveted"), |
| 111 | + "locometal_pillar": mk_pillar(), |
| 112 | + "locometal_smokebox": mk_smokebox(), |
| 113 | + "plated_locometal": mk_locometal(None, False, "plated"), |
| 114 | + "flat_slashed_locometal": mk_locometal(None, True, "slashed"), |
| 115 | + "flat_riveted_locometal": mk_locometal(None, True, "riveted"), |
| 116 | + |
| 117 | + "brass_wrapped_locometal": mk_locometal("brass", False, None), |
| 118 | + "iron_wrapped_locometal": mk_locometal("iron", False, None), |
| 119 | + "copper_wrapped_locometal": mk_locometal("copper", False, None), |
| 120 | + |
| 121 | + "locometal_boiler": mk_boiler(None), |
| 122 | + "brass_wrapped_locometal_boiler": mk_boiler("brass"), |
| 123 | + "copper_wrapped_locometal_boiler": mk_boiler("copper"), |
| 124 | + "iron_wrapped_locometal_boiler": mk_boiler("iron"), |
| 125 | +} |
| 126 | + |
| 127 | + |
| 128 | +with open("../common/src/generated/resources/assets/railways/lang/en_us.json", "r") as f: |
| 129 | + source_strings = json.load(f) |
| 130 | +source_strings: dict[str, str] |
| 131 | + |
| 132 | +lang = "tr_tr" |
| 133 | + |
| 134 | +with open(f"../common/src/main/resources/assets/railways/lang/{lang}.json", "r") as f: |
| 135 | + existing_translated_strings = json.load(f) |
| 136 | +existing_translated_strings: dict[str, str] |
| 137 | + |
| 138 | +new_translated_strings: dict[str, str] = {} |
| 139 | + |
| 140 | +#for string in source_strings: |
| 141 | +# if sum(1 for exc in exclude if exc in string) != 0: |
| 142 | +# continue |
| 143 | +# if not string.startswith(prefix): |
| 144 | +# continue |
| 145 | +# if string not in existing_translated_strings: |
| 146 | +# continue |
| 147 | +# |
| 148 | +# for suffix, format_string in conversions.items(): |
| 149 | +# new_string = string + suffix |
| 150 | +# if new_string in existing_translated_strings: |
| 151 | +# continue |
| 152 | +# if new_string not in source_strings: |
| 153 | +# # print("OOPS", new_string) |
| 154 | +# continue |
| 155 | +# new_translated_strings[new_string] = format_string.format(existing_translated_strings[string]) |
| 156 | +for string, formatter in translations.items(): |
| 157 | + string = "<COLOR>_" + string |
| 158 | + for color_name in color_keys: |
| 159 | + s = prefix + string.replace("<COLOR>", color_name).removeprefix("_").removesuffix("_") |
| 160 | + if s not in source_strings: |
| 161 | + print("OOPS", s) |
| 162 | + continue |
| 163 | + if s in existing_translated_strings: |
| 164 | + print("Already translated", s) |
| 165 | + continue |
| 166 | + new_translated_strings[s] = formatter(color_name) |
| 167 | + |
| 168 | +print(f"New translations for {lang}") |
| 169 | +for k, v in new_translated_strings.items(): |
| 170 | + print(f" {k}: {v}") |
| 171 | + |
| 172 | +# quit() |
| 173 | +all_strings = existing_translated_strings.copy() |
| 174 | +all_strings.update(new_translated_strings) |
| 175 | +with open(f"../common/src/main/resources/assets/railways/lang/{lang}.json", "w") as f: |
| 176 | + json.dump(all_strings, f, indent=2, ensure_ascii=False) |
0 commit comments