Skip to content

Commit

Permalink
Remove hardcoded variables
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGrosjean committed Jan 1, 2025
1 parent bb0018c commit 238f174
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ python paradox_localization_utils/apply_diff_all.py <old_localisation_dir> <curr
Example to apply in French files the modifications done in English

```shell
python paradox_localization_utils/apply_diff_all.py "<...>\V1\localisation\english" "<...>\V2\localisation\english" -dest_dir "<...>\V1\localisation\french"
python paradox_localization_utils/apply_diff_all.py "<...>\V1\localisation\english" "<...>\V2\localisation\english" -dest_dir "<...>\V1\localisation\french" -source_lang english -dest_lang french
```

#### For old EUIV, HoI4 or Stellaris localisation format (all files in the same directory)

```shell
python paradox_localization_utils/apply_diff_all.py <old_localisation_dir> <current_localisation_dir> -source_lang <source_lang> -dest_lang <dest_lang>
python paradox_localization_utils/apply_diff_all.py <old_localisation_dir> <current_localisation_dir> -source_lang <source_lang> -dest_lang <dest_lang> -old_format
```

- <old_localisation_dir> contains the localisation of the old source version
Expand Down
21 changes: 9 additions & 12 deletions paradox_localization_utils/apply_diff_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def get_args():
parser.add_argument("-source_lang", type=str, help="Source language when EUIV, HoI4 or Stellaris game")
parser.add_argument("-dest_lang", type=str, help="Destination language when EUIV, HoI4 or Stellaris game")
parser.add_argument("-keys_to_ignore", type=str, help="File with at each lines a key to ignore")
parser.add_argument("-old_format", action="store_true", help="Use old format for EUIV, HoI4 or Stellaris game")
return parser.parse_args()


Expand Down Expand Up @@ -253,18 +254,14 @@ def apply_diff_all_old_formats(old_dir, current_dir, source_lang, dest_lang, key
else:
with open(args.keys_to_ignore, "r", encoding="utf-8") as f:
keys_to_ignore = [line.replace("\n", "") for line in f.readlines()]
if (args.source_lang is None) and (args.dest_lang is None):
# source_lang = args.source_dir.split("\\")[-1]
# dest_lang = args.dest_dir.split("\\")[-1]
source_lang = "english"
dest_lang = "french"
apply_diff_all(args.old_source_dir, args.source_dir, args.dest_dir, source_lang, dest_lang, keys_to_ignore)
for root, _, files in os.walk(os.path.join(args.dest_dir, source_lang)):
dest_dir = root.replace(os.path.join(args.dest_dir, source_lang), os.path.join(args.dest_dir, dest_lang))
for file in files:
if dest_lang in file:
shutil.move(os.path.join(root, file), os.path.join(dest_dir, file))
else:
if args.old_format:
apply_diff_all_old_formats(
args.old_source_dir, args.source_dir, args.source_lang, args.dest_lang, keys_to_ignore
)
else:
apply_diff_all(args.old_source_dir, args.source_dir, args.dest_dir, args.source_lang, args.dest_lang, keys_to_ignore)
for root, _, files in os.walk(os.path.join(args.dest_dir, args.source_lang)):
dest_dir = root.replace(os.path.join(args.dest_dir, args.source_lang), os.path.join(args.dest_dir, args.dest_lang))
for file in files:
if args.dest_lang in file:
shutil.move(os.path.join(root, file), os.path.join(dest_dir, file))

0 comments on commit 238f174

Please sign in to comment.