expand: check language properties (#2724)

# Description

Improvement in `check_language_properties.py`:

Added support for local Windows commands to check language properties
files with an updated script.
Added a new optional argument `--check-file` to specify a single file to
check, replacing the need to process all files in the directory.
Adjusted file path handling to better support Windows paths.

Update to `update-translations.yml`:

Added `workflow_dispatch` trigger to allow manual execution of the
workflow.

Documentation update in `HowToAddNewLanguage.md`:

Added instructions for running the language properties check locally on
Windows, including example commands.
These changes streamline the process of checking language properties
files and provide additional flexibility for local testing and manual
workflow triggering.

## Checklist

- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [x] I have performed a self-review of my own code
- [ ] I have attached images of the change if it is UI based
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] If my code has heavily changed functionality I have updated
relevant docs on [Stirling-PDFs doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
- [x] My changes generate no new warnings
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)
This commit is contained in:
Ludy 2025-01-16 23:03:54 +01:00 committed by GitHub
parent c888cef023
commit b4b5a2419b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 6 deletions

View File

@ -11,6 +11,8 @@ adjusting the format.
Usage: Usage:
python check_language_properties.py --reference-file <path_to_reference_file> --branch <branch_name> [--actor <actor_name>] [--files <list_of_changed_files>] python check_language_properties.py --reference-file <path_to_reference_file> --branch <branch_name> [--actor <actor_name>] [--files <list_of_changed_files>]
""" """
# Sample for Windows:
# python .github/scripts/check_language_properties.py --reference-file src\main\resources\messages_en_GB.properties --branch "" --files src\main\resources\messages_de_DE.properties src\main\resources\messages_uk_UA.properties
import copy import copy
import glob import glob
@ -164,8 +166,14 @@ def check_for_differences(reference_file, file_list, branch, actor):
basename_current_file = os.path.basename(os.path.join(branch, file_path)) basename_current_file = os.path.basename(os.path.join(branch, file_path))
if ( if (
basename_current_file == basename_reference_file basename_current_file == basename_reference_file
or not file_path.startswith( or (
os.path.join("src", "main", "resources", "messages_") # only local windows command
not file_path.startswith(
os.path.join("", "src", "main", "resources", "messages_")
)
and not file_path.startswith(
os.path.join(os.getcwd(), "src", "main", "resources", "messages_")
)
) )
or not file_path.endswith(".properties") or not file_path.endswith(".properties")
or not basename_current_file.startswith("messages_") or not basename_current_file.startswith("messages_")
@ -275,6 +283,12 @@ if __name__ == "__main__":
required=True, required=True,
help="Branch name.", help="Branch name.",
) )
parser.add_argument(
"--check-file",
type=str,
required=False,
help="List of changed files, separated by spaces.",
)
parser.add_argument( parser.add_argument(
"--files", "--files",
nargs="+", nargs="+",
@ -293,11 +307,14 @@ if __name__ == "__main__":
file_list = args.files file_list = args.files
if file_list is None: if file_list is None:
file_list = glob.glob( if args.check_file:
os.path.join( file_list = [args.check_file]
os.getcwd(), "src", "main", "resources", "messages_*.properties" else:
file_list = glob.glob(
os.path.join(
os.getcwd(), "src", "main", "resources", "messages_*.properties"
)
) )
)
update_missing_keys(args.reference_file, file_list) update_missing_keys(args.reference_file, file_list)
else: else:
check_for_differences(args.reference_file, file_list, args.branch, args.actor) check_for_differences(args.reference_file, file_list, args.branch, args.actor)

View File

@ -1,6 +1,7 @@
name: Update Translations name: Update Translations
on: on:
workflow_dispatch:
push: push:
branches: ["main"] branches: ["main"]
paths: paths:

View File

@ -60,3 +60,13 @@ ignore = [
- After adding the new tags to `messages_en_GB.properties`, add and translate them in the respective language file (e.g., `messages_pl_PL.properties`). - After adding the new tags to `messages_en_GB.properties`, add and translate them in the respective language file (e.g., `messages_pl_PL.properties`).
Make sure to place the entry under the correct language section. This helps maintain the accuracy of translation progress statistics and ensures that the translation tool or scripts do not misinterpret the completion rate. Make sure to place the entry under the correct language section. This helps maintain the accuracy of translation progress statistics and ensures that the translation tool or scripts do not misinterpret the completion rate.
### Use this code to perform a local check
#### Windows command
```ps
python .github/scripts/check_language_properties.py --reference-file src\main\resources\messages_en_GB.properties --branch "" --files src\main\resources\messages_pl_PL.properties
python .github/scripts/check_language_properties.py --reference-file src\main\resources\messages_en_GB.properties --branch "" --check-file src\main\resources\messages_pl_PL.properties
```