diff --git a/frontend/static/locales/collect_phrases.py b/frontend/static/locales/collect_phrases.py index 65ded7cf..9b585472 100644 --- a/frontend/static/locales/collect_phrases.py +++ b/frontend/static/locales/collect_phrases.py @@ -7,6 +7,7 @@ locale dictionary by matching existing translations. import json import os import re +from collections import OrderedDict from handcrafted import phrases @@ -16,33 +17,40 @@ match = r"(.*?[a-zA-Z].*?)" pattern = f"{prefix}{match}{suffix}" extensions = [".ts", ".tsx", ".js", "jsx"] -strings_dict = {} +strings_dict = OrderedDict() +src_path = "../../src" counter = 1 -# Look for all matching i18n keys -for root, dirs, files in os.walk("../../src"): +# Look for all matching i18n keys in src_path +for root, dirs, files in os.walk(src_path): + dirs.sort() + files.sort() for file in files: if file.endswith(tuple(extensions)): filepath = os.path.join(root, file) with open(filepath, "r", encoding="utf-8") as f: contents = f.read() - matches = re.findall(pattern, contents) + matches = sorted(re.findall(pattern, contents)) if len(matches) > 0: - strings_dict[f"#{counter}"] = f"Phrases in {filepath[10:]}" + rel_filepath_in_src = os.path.relpath(filepath, src_path) + strings_dict[f"#{counter}"] = f"Phrases in {rel_filepath_in_src}" counter += 1 - for match in matches: - strings_dict[match] = match + for match in matches: + strings_dict[match] = match + +all_phrases = OrderedDict() +all_phrases.update(strings_dict) +all_phrases.update(phrases) # Load existing locale dics and replace keys locales = [f for f in os.listdir(".") if f.endswith(".json")] -all_phrases = {**strings_dict, **phrases} for locale in locales: - new_phrases = {} + new_phrases = OrderedDict() with open(locale, "r", encoding="utf-8") as f: old_phrases = json.load(f) - for key in all_phrases: - # update dictionary with new keys on /src/ - if key in old_phrases: + for key in all_phrases.keys(): + # update dictionary with new keys on /src/, but ignore the counter of files keys + if key in old_phrases and not re.match(r"^#\d+$", key): new_phrases[key] = old_phrases[key] else: new_phrases[key] = all_phrases[key] diff --git a/frontend/static/locales/handcrafted.py b/frontend/static/locales/handcrafted.py index 35331a3d..e62072f6 100644 --- a/frontend/static/locales/handcrafted.py +++ b/frontend/static/locales/handcrafted.py @@ -1,36 +1,76 @@ +from collections import OrderedDict + # Some of the phrases that are directly returned by the coordinator API (bad requests) # or need the use of tags <>. -phrases = { - "desktop_unsafe_alert": "Some features are disabled for your protection (e.g. chat) and you will not be able to complete a trade without them. To protect your privacy and fully enable RoboSats, use <1>Tor Browser and visit the <3>Onion site.", - "phone_unsafe_alert": "You will not be able to complete a trade. Use <1>Tor Browser and visit the <3>Onion site.", - "rate_robosats": "What do you think of <1>RoboSats?", - "let_us_know_hot_to_improve": "Let us know how the platform could improve (<1>Telegram / <3>Github)", - "open_dispute": "To open a dispute you need to wait <1><1/>", - "Waiting for maker bond": "Waiting for maker bond", - "Public": "Public", - "Waiting for taker bond": "Waiting for taker bond", - "Cancelled": "Cancelled", - "Expired": "Expired", - "Waiting for trade collateral and buyer invoice": "Waiting for trade collateral and buyer invoice", - "Waiting only for seller trade collateral": "Waiting only for seller trade collateral", - "Waiting only for buyer invoice": "Waiting only for buyer invoice", - "Sending fiat - In chatroom": "Sending fiat - In chatroom", - "Fiat sent - In chatroom": "Fiat sent - In chatroom", - "In dispute": "In dispute", - "Collaboratively cancelled": "Collaboratively cancelled", - "Sending satoshis to buyer": "Sending satoshis to buyer", - "Sucessful trade": "Successful trade", - "Failed lightning network routing": "Failed lightning network routing", - "Wait for dispute resolution": "Wait for dispute resolution", - "Maker lost dispute": "Maker lost dispute", - "Taker lost dispute": "Taker lost dispute", - "Invoice expired. You did not confirm publishing the order in time. Make a new order.": "Invoice expired. You did not confirm publishing the order in time. Make a new order.", - "This order has been cancelled by the maker": "This order has been cancelled by the maker", - "Invoice expired. You did not confirm taking the order in time.": "Invoice expired. You did not confirm taking the order in time.", - "Invalid Order Id": "Invalid Order Id", - "Invoice expired. You did not confirm taking the order in time.": "Invoice expired. You did not confirm taking the order in time.", - "You must have a robot avatar to see the order details": "You must have a robot avatar to see the order details", - "This order has been cancelled collaborativelly": "This order has been cancelled collaboratively", - "This order is not available": "This order is not available", - "The Robotic Satoshis working in the warehouse did not understand you. Please, fill a Bug Issue in Github https://github.com/RoboSats/robosats/issues": "The Robotic Satoshis working in the warehouse did not understand you. Please, fill a Bug Issue in Github https://github.com/RoboSats/robosats/issues", -} +phrases = OrderedDict( + [ + ( + "desktop_unsafe_alert", + "Some features are disabled for your protection (e.g. chat) and you will not be able to complete a trade without them. To protect your privacy and fully enable RoboSats, use <1>Tor Browser and visit the <3>Onion site.", + ), + ( + "phone_unsafe_alert", + "You will not be able to complete a trade. Use <1>Tor Browser and visit the <3>Onion site.", + ), + ("rate_robosats", "What do you think of <1>RoboSats?"), + ( + "let_us_know_hot_to_improve", + "Let us know how the platform could improve (<1>Telegram / <3>Github)", + ), + ("open_dispute", "To open a dispute you need to wait <1><1/>"), + ("Waiting for maker bond", "Waiting for maker bond"), + ("Public", "Public"), + ("Waiting for taker bond", "Waiting for taker bond"), + ("Cancelled", "Cancelled"), + ("Expired", "Expired"), + ( + "Waiting for trade collateral and buyer invoice", + "Waiting for trade collateral and buyer invoice", + ), + ( + "Waiting only for seller trade collateral", + "Waiting only for seller trade collateral", + ), + ("Waiting only for buyer invoice", "Waiting only for buyer invoice"), + ("Sending fiat - In chatroom", "Sending fiat - In chatroom"), + ("Fiat sent - In chatroom", "Fiat sent - In chatroom"), + ("In dispute", "In dispute"), + ("Collaboratively cancelled", "Collaboratively cancelled"), + ("Sending satoshis to buyer", "Sending satoshis to buyer"), + ("Sucessful trade", "Successful trade"), + ("Failed lightning network routing", "Failed lightning network routing"), + ("Wait for dispute resolution", "Wait for dispute resolution"), + ("Maker lost dispute", "Maker lost dispute"), + ("Taker lost dispute", "Taker lost dispute"), + ( + "Invoice expired. You did not confirm publishing the order in time. Make a new order.", + "Invoice expired. You did not confirm publishing the order in time. Make a new order.", + ), + ( + "This order has been cancelled by the maker", + "This order has been cancelled by the maker", + ), + ( + "Invoice expired. You did not confirm taking the order in time.", + "Invoice expired. You did not confirm taking the order in time.", + ), + ("Invalid Order Id", "Invalid Order Id"), + ( + "Invoice expired. You did not confirm taking the order in time.", + "Invoice expired. You did not confirm taking the order in time.", + ), + ( + "You must have a robot avatar to see the order details", + "You must have a robot avatar to see the order details", + ), + ( + "This order has been cancelled collaborativelly", + "This order has been cancelled collaboratively", + ), + ("This order is not available", "This order is not available"), + ( + "The Robotic Satoshis working in the warehouse did not understand you. Please, fill a Bug Issue in Github https://github.com/RoboSats/robosats/issues", + "The Robotic Satoshis working in the warehouse did not understand you. Please, fill a Bug Issue in Github https://github.com/RoboSats/robosats/issues", + ), + ] +)