Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing a typo in readme.md #59

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Check out Scribe's [architecture diagrams](https://github.com/scribe-org/Organiz

# Contributing [`⇧`](#contents)

Thank you for your interest in contributing to Scribe-i18n! We look forward to welcoming you to the community and working with you to build an tools for language learners to communicate effectively :) The following are some suggested steps for people interested in joining our community.
Thank you for your interest in contributing to Scribe-i18n! We look forward to welcoming you to the community and working with you to build tools for language learners to communicate effectively :) The following are some suggested steps for people interested in joining our community.

Following these guidelines helps to communicate that you respect the time of the developers managing and developing this open-source project. In return, and in accordance with this project's [code of conduct](https://github.com/scribe-org/Scribe-i18n/blob/main/.github/CODE_OF_CONDUCT.md), other contributors will reciprocate that respect in addressing your issue or assessing changes and features.

Expand Down
37 changes: 29 additions & 8 deletions Scribe-i18n/scripts/iOS/convert_xcstrings_to_jsons.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,35 @@
import json
import os

# Determine the directory
directory = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
file = open(os.path.join(directory, "Localizable.xcstrings"), "r").read()
dir_list = os.listdir(directory)

# Ensure the "jsons" folder exists inside the directory
jsons_folder = os.path.join(directory, "jsons")
if not os.path.exists(jsons_folder):
os.makedirs(jsons_folder)

# Read the Localizable.xcstrings file
try:
with open(os.path.join(jsons_folder, "Localizable.xcstrings"), "r") as f:
file = f.read()
except FileNotFoundError:
print("Error: Localizable.xcstrings file not found.")
exit(1)

dir_list = os.listdir(jsons_folder)
languages = [file.replace(".json", "") for file in dir_list if file.endswith(".json")]

for lang in languages:
dest = open(f"{directory}/{lang}.json", "w")
if lang == "en-US":
lang = "en"
lang = "en" if lang == "en-US" else lang

# Attempt to load the JSON data
try:
json_file = json.loads(file)
except json.JSONDecodeError:
print("Error: The Localizable.xcstrings file is not valid JSON.")
exit(1)

json_file = json.loads(file)
strings = json_file["strings"]

data = {}
Expand All @@ -38,8 +56,11 @@

data[key] = translation

json.dump(data, dest, indent=2, ensure_ascii=False)
dest.write("\n")
# Write to the destination JSON file using a context manager
with open(f"{jsons_folder}/{lang}.json", "w") as dest:
json.dump(data, dest, indent=2, ensure_ascii=False)
dest.write("\n")


print(
"Scribe-i18n Localizable.xcstrings file successfully converted to the localization JSON files."
Expand Down
Loading