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

Add CLI to pip #15

Merged
merged 36 commits into from
Nov 20, 2024
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
590877b
Added command_line.py, default language file, setup file, and basic f…
Oct 23, 2024
9cf43de
fixed pathing error
Oct 23, 2024
afac5c4
commented code, cleaned up code, added skeleton for tests
Oct 23, 2024
b2f2c36
implemented cli for add and update
steph-feng Oct 24, 2024
c9f9dbe
tests
Oct 24, 2024
83dd85d
Merge branch 'main' into create_cli
Oct 24, 2024
dec7d3d
merged
Oct 25, 2024
67cb834
merge with mainMerge branch 'main' into create_cli
Oct 25, 2024
8b36bd8
feat: cli for delete
Oct 26, 2024
de8dcfc
fixed pathing issue with tests
Oct 31, 2024
e3fe661
Merge branch 'create_cli' of https://github.com/ubclaunchpad/localiza…
Oct 31, 2024
0f97045
add setup/teardown and test for add_word
steph-feng Oct 31, 2024
9251c39
fix differences
Oct 31, 2024
8fae35d
Merge branch 'create_cli' of https://github.com/ubclaunchpad/localiza…
Oct 31, 2024
9f4e3cc
Merge branch 'main' into create_cli
angelafeliciaa Nov 2, 2024
dfaa017
Merge branch 'create_cli' of https://github.com/ubclaunchpad/localiza…
Nov 2, 2024
b37d718
added init files
Nov 3, 2024
24f35bd
add test for update
steph-feng Nov 4, 2024
860a984
Merge branch 'main' into create_cli
Nov 16, 2024
536d4d0
refactored add-language, added test
Nov 16, 2024
0820c6b
refactor add_word, update tests
steph-feng Nov 16, 2024
abb20ec
edit add/update word tests
steph-feng Nov 16, 2024
55a0993
gitignore
angelafeliciaa Nov 16, 2024
7462306
refactor delete translation
angelafeliciaa Nov 16, 2024
ee14131
add tests for delete
angelafeliciaa Nov 16, 2024
fe1c049
delete pycache
angelafeliciaa Nov 16, 2024
e1a2e89
Revert "delete pycache"
angelafeliciaa Nov 16, 2024
3792274
remove egg info
angelafeliciaa Nov 17, 2024
b8951da
remove useless
angelafeliciaa Nov 17, 2024
0288632
move languages_dir to globals
angelafeliciaa Nov 17, 2024
688a46c
delete more egg info
angelafeliciaa Nov 17, 2024
499b6f6
Merge branch 'main' into create_cli
angelafeliciaa Nov 17, 2024
7d7f7aa
delete build files
angelafeliciaa Nov 19, 2024
140ad3c
Merge branch 'create_cli' of https://github.com/ubclaunchpad/localiza…
angelafeliciaa Nov 19, 2024
d341e65
delete pycache
angelafeliciaa Nov 19, 2024
f00e7ba
delete pycache
angelafeliciaa Nov 19, 2024
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
Prev Previous commit
Next Next commit
refactor delete translation
  • Loading branch information
angelafeliciaa committed Nov 16, 2024
commit 7462306019c83b47c8d8fcbcb8f58a576a1e4d9c
37 changes: 19 additions & 18 deletions i18nilize/src/internationalize/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,29 @@ def add_update_translated_word(language, original_word, translated_word):
json.dump(data, file, indent=4)
print(f"{original_word}: {translated_word} added to translations.")

# // MUST BE REFACTORED
# Deletes a translated word
# Deletes a translated word for the given language
def delete_translation(language, original_word, translated_word):
data = get_json(DEFAULT_PATH)
translations = data.get('translations', [])

language_exists = False
for translation in translations:
if translation.get('language') == language:
language_exists = True
if original_word in translation and translation[original_word] == translated_word:
del translation[original_word]

with open(DEFAULT_PATH, 'w') as file:
json.dump(data, file, indent=4)

break

if not language_exists:
file_path = os.path.join(LANGUAGES_DIR, f"{language.lower()}.json")

if not os.path.exists(file_path):
print(f"Error: Language '{language}' does not exist.")
sys.exit(1)

data = get_json(file_path)

if original_word not in data:
print(f"Error: Original word '{original_word}' does not exist in language '{language}'.")
sys.exit(1)

if data[original_word] != translated_word:
print(f"Error: Translated word for '{original_word}' does not match '{translated_word}'.")
sys.exit(1)

del data[original_word]
with open(file_path, 'w') as file:
json.dump(data, file, indent=4)
print(f"Translation for '{original_word}' deleted successfully from language '{language}'.")

# Input:
# - file_path: path of json file
# Output: Token in json file
Expand Down