Skip to content

Commit

Permalink
chore: fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilb committed Jan 5, 2025
1 parent 6616ac4 commit 9d79419
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tools/localization/localeTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def generate_js_object(data):
js_object += "}"
return js_object

def escape_new_lines(value):
"""
Escapes new lines, from "\n" to "\\n".
"""
return value.replace("\n", "\\n")


def extract_vars(text):
# Use a regular expression to find all strings inside curly braces
Expand Down Expand Up @@ -127,13 +133,13 @@ def generate_type_object(locales):
if localized_string:
to_append = ""
to_append += token
to_append += f": \"{localized_string.replace("\n", "\\n")}\""
to_append += f": \"{escape_new_lines(localized_string)}\""
all_locales_strings.append(to_append)

# if that locale doesn't have translation in plurals, add the english hones
if not len(all_locales_strings):
for plural_en_token, plural_en_str in en_plurals_with_token:
all_locales_strings.append(f"{plural_en_token}: \"{plural_en_str.replace("\n", "\\n")}\"")
all_locales_strings.append(f"{plural_en_token}: \"{escape_new_lines(plural_en_str)}\"")
js_plural_object += f" {wrapValue(locale_key)}:"
js_plural_object += "{\n "
js_plural_object += ",\n ".join(all_locales_strings)
Expand All @@ -151,9 +157,9 @@ def generate_type_object(locales):
all_locales_strings = []
for locale, replaced_val in other_locales_replaced_values:
if replaced_val:
all_locales_strings.append(f"{wrapValue(locale.replace("_","-"))}: \"{replaced_val.replace("\n", "\\n")}\"")
all_locales_strings.append(f"{wrapValue(locale.replace("_","-"))}: \"{escape_new_lines(replaced_val)}\"")
else:
all_locales_strings.append(f"{wrapValue(locale.replace("_","-"))}: \"{replaced_en.replace("\n", "\\n")}\"")
all_locales_strings.append(f"{wrapValue(locale.replace("_","-"))}: \"{escape_new_lines(replaced_en)}\"")

# print('key',key, " other_locales_replaced_values:", other_locales_replaced_values)
js_object += f" {wrapValue(key)}: {{\n {",\n ".join(all_locales_strings)},\n args: {as_record_type_en if as_record_type_en else 'undefined,'}\n }},\n"
Expand Down

0 comments on commit 9d79419

Please sign in to comment.