From 9969475fee2018b8df6752306a50577f15f59541 Mon Sep 17 00:00:00 2001 From: Konstantin Pastbin Date: Fri, 7 Jan 2022 16:25:24 +0300 Subject: [PATCH] [tools] Added android tag to harcoded categories and colors in strings.txt Also got rid of a single hardcoded NSLocalizedString usage instance. Needed-for: #587 Signed-off-by: Konstantin Pastbin --- data/strings/strings.txt | 56 +++++++++++++++---------------- tools/python/clean_strings_txt.py | 45 +++++++++++++++---------- 2 files changed, 55 insertions(+), 46 deletions(-) diff --git a/data/strings/strings.txt b/data/strings/strings.txt index 9b4d93fc6b..5f192f7ca6 100644 --- a/data/strings/strings.txt +++ b/data/strings/strings.txt @@ -2045,7 +2045,7 @@ [transport] comment = Search category - tags = ios + tags = android,ios en = Transport ar = نقل be = Транспарт @@ -2157,7 +2157,7 @@ [shopping] comment = Search category for clothes/shoes/gifts/jewellery/sport shops - tags = ios + tags = android,ios en = Shopping ar = التسوق be = Закупы @@ -2194,7 +2194,7 @@ [hotel] comment = Search category - tags = ios + tags = android,ios en = Hotel ar = فندق be = Гатэль @@ -2231,7 +2231,7 @@ [tourism] comment = Search category - tags = ios + tags = android,ios en = Sights ar = سياحة be = Славутасці @@ -2342,7 +2342,7 @@ [nightlife] comment = Search category for nightclubs/bars - tags = ios + tags = android,ios en = Nightlife ar = أنشطة ترفيه ليلية be = Начное жыццё @@ -2379,7 +2379,7 @@ [children] comment = Search category for water park/disneyland/playground/toys store - tags = ios + tags = android,ios en = Family holiday ar = عطلة عائلية be = Сямейны адпачынак @@ -2416,7 +2416,7 @@ [bank] comment = Search category - tags = ios + tags = android,ios en = Bank ar = بنك be = Банк @@ -2453,7 +2453,7 @@ [pharmacy] comment = Search category - tags = ios + tags = android,ios en = Pharmacy ar = صيدلية be = Аптэка @@ -2490,7 +2490,7 @@ [hospital] comment = Search category - tags = ios + tags = android,ios en = Hospital ar = مستشفى be = Лякарня @@ -2528,7 +2528,7 @@ [toilet] comment = Search category - tags = ios + tags = android,ios en = Toilet ar = حمام be = Прыбіральня @@ -2565,7 +2565,7 @@ [post] comment = Search category - tags = ios + tags = android,ios en = Post ar = بريد be = Пошта @@ -2602,7 +2602,7 @@ [police] comment = Search category - tags = ios + tags = android,ios en = Police ar = شرطة be = Паліцыя @@ -6008,7 +6008,7 @@ [red] comment = red color - tags = ios + tags = android,ios en = Red ar = أحمر be = Чырвоны @@ -6045,7 +6045,7 @@ [yellow] comment = yellow color - tags = ios + tags = android,ios en = Yellow ar = أصفر be = Жоўты @@ -6082,7 +6082,7 @@ [blue] comment = blue color - tags = ios + tags = android,ios en = Blue ar = أزرق be = Сіні @@ -6119,7 +6119,7 @@ [green] comment = green color - tags = ios + tags = android,ios en = Green ar = أخضر be = Зялёны @@ -6156,7 +6156,7 @@ [purple] comment = purple color - tags = ios + tags = android,ios en = Purple ar = أرجواني be = Пурпурны @@ -6193,7 +6193,7 @@ [orange] comment = orange color - tags = ios + tags = android,ios en = Orange ar = برتقالي be = Аранжавы @@ -6230,7 +6230,7 @@ [brown] comment = brown color - tags = ios + tags = android,ios en = Brown ar = بني be = Карычневы @@ -6267,7 +6267,7 @@ [pink] comment = pink color - tags = ios + tags = android,ios en = Pink ar = وردي be = Ружовы @@ -6304,7 +6304,7 @@ [deep_purple] comment = deep purple color - tags = ios + tags = android,ios en = Deep Purple ar = أرجواني داكن be = Цёмна-пурпурны @@ -6341,7 +6341,7 @@ [light_blue] comment = light blue color - tags = ios + tags = android,ios en = Light Blue ar = أزرق فاتح be = Блакітны @@ -6378,7 +6378,7 @@ [cyan] comment = cyan color - tags = ios + tags = android,ios en = Cyan ar = أزرق سماوي be = Сіне-зялёны @@ -6415,7 +6415,7 @@ [teal] comment = teal color - tags = ios + tags = android,ios en = Teal ar = أخضر فاتح be = Смарагдавы @@ -6452,7 +6452,7 @@ [lime] comment = lime color - tags = ios + tags = android,ios en = Lime ar = ليموني be = Лайм @@ -6489,7 +6489,7 @@ [deep_orange] comment = deep orange color - tags = ios + tags = android,ios en = Deep Orange ar = برتقالي داكن be = Цёмна-аранжавы @@ -6526,7 +6526,7 @@ [gray] comment = gray color - tags = ios + tags = android,ios en = Gray ar = رمادي be = Шэры @@ -6563,7 +6563,7 @@ [blue_gray] comment = blue gray color - tags = ios + tags = android,ios en = Blue Gray ar = رمادي أزرق be = Блакітна-шэры diff --git a/tools/python/clean_strings_txt.py b/tools/python/clean_strings_txt.py index 2636d3db5c..d4da12c05c 100755 --- a/tools/python/clean_strings_txt.py +++ b/tools/python/clean_strings_txt.py @@ -19,27 +19,25 @@ run this script with the -h option. OMIM_ROOT = "" -CORE_RE = re.compile(r'GetLocalizedString\(\"(.*?)\"\)') +CORE_RE = re.compile(r'GetLocalizedString\("(.*?)"\)') # max 2 matches in L(). Tried to make ()+ group, but no luck .. -IOS_RE = re.compile(r'L\(.*?\"(\w+)\".*?(?:\"(\w+)\")?\)') -IOS_XML_RE = re.compile(r"value=\"(.*?)\"") +IOS_RE = re.compile(r'L\(.*?"(\w+)".*?(?:"(\w+)")?\)') +IOS_NS_RE = re.compile(r'NSLocalizedString\(\s*?"(\w+)"') +IOS_XML_RE = re.compile(r'value=\"(.*?)\"') -ANDROID_JAVA_RE = re.compile(r"R\.string\.([\w_]*)") -ANDROID_JAVA_PLURAL_RE = re.compile(r"R\.plurals\.([\w_]*)") -ANDROID_XML_RE = re.compile(r"@string/(.*?)\W") +ANDROID_JAVA_RE = re.compile(r'R\.string\.([\w_]*)') +ANDROID_JAVA_PLURAL_RE = re.compile(r'R\.plurals\.([\w_]*)') +ANDROID_XML_RE = re.compile(r'@string/(.*?)\W') -IOS_CANDIDATES_RE = re.compile(r"(.*?):[^L\(]@\"([a-z0-9_]*?)\"") +IOS_CANDIDATES_RE = re.compile(r'(.*?):[^L\(]@"([a-z0-9_]*?)"') HARDCODED_CATEGORIES = None HARDCODED_COLORS = [ # titleForBookmarkColor "red", "blue", "purple", "yellow", "pink", "brown", "green", "orange", "deep_purple", "light_blue", - "cyan", "teal", "lime", "deep_orange", "gray", "blue_gray", - - # NSLocalizedString - "placepage_distance" + "cyan", "teal", "lime", "deep_orange", "gray", "blue_gray" ] @@ -59,12 +57,13 @@ def exec_shell(test, *flags): def grep_ios(): logging.info("Grepping iOS...") - grep = "grep -r -I 'L(\|localizedText\|localizedPlaceholder' {0}/iphone/*".format(OMIM_ROOT) + grep = "grep -r -I 'L(\|localizedText\|localizedPlaceholder\|NSLocalizedString(' {0}/iphone/*".format(OMIM_ROOT) ret = exec_shell(grep) + ret = filter_ios_grep(ret) logging.info("Found in iOS: {0}".format(len(ret))) + ret.update(get_hardcoded()) - return filter_ios_grep(ret) - + return ret def grep_android(): logging.info("Grepping android...") @@ -76,9 +75,12 @@ def grep_android(): ret.update(android_grep_wrapper(grep, ANDROID_XML_RE)) grep = "grep -r -I '@string/' {0}/android/AndroidManifest.xml".format(OMIM_ROOT) ret.update(android_grep_wrapper(grep, ANDROID_XML_RE)) - logging.info("Found in android: {0}".format(len(ret))) + ret = parenthesize(ret) - return parenthesize(ret) + logging.info("Found in android: {0}".format(len(ret))) + ret.update(get_hardcoded()) + + return ret def grep_core(): logging.info("Grepping core...") @@ -97,6 +99,11 @@ def grep_ios_candidates(): strs = strings_from_grepped(ret, IOS_CANDIDATES_RE) return strs +def get_hardcoded(): + ret = parenthesize(HARDCODED_CATEGORIES) + ret.update(parenthesize(HARDCODED_COLORS)) + logging.info("Hardcoded colors and categories: {0}".format(len(ret))) + return ret def android_grep_wrapper(grep, regex): grepped = exec_shell(grep) @@ -106,9 +113,8 @@ def android_grep_wrapper(grep, regex): def filter_ios_grep(strings): filtered = strings_from_grepped_tuple(strings, IOS_RE) filtered = parenthesize(process_ternary_operators(filtered)) + filtered.update(parenthesize(strings_from_grepped(strings, IOS_NS_RE))) filtered.update(parenthesize(strings_from_grepped(strings, IOS_XML_RE))) - filtered.update(parenthesize(HARDCODED_CATEGORIES)) - filtered.update(parenthesize(HARDCODED_COLORS)) return filtered @@ -349,6 +355,7 @@ def find_omim(): def read_hardcoded_categories(a_path): + logging.info("Loading harcoded categories from: {0}".format(a_path)) with open(a_path) as infile: return [s.strip() for s in infile if s] @@ -359,6 +366,8 @@ if __name__ == "__main__": OMIM_ROOT=args.omim_root + # TODO: switch to a single source of hardcoded categories, + # see https://github.com/organicmaps/organicmaps/issues/1795 HARDCODED_CATEGORIES = read_hardcoded_categories( args.hardcoded_categories )