From e6eb46d7fa7ef5d9a26673b4cba75dd0bdc163e7 Mon Sep 17 00:00:00 2001 From: Oth3r <68134921+Oth3r@users.noreply.github.com> Date: Sat, 14 Jun 2025 17:41:08 -0500 Subject: [PATCH] lowercase locale --- .../workflows/crowdin-download-workflow.yml | 114 ++++++++++++++++-- .github/workflows/crowdin-upload-workflow.yml | 2 +- crowdin.yml | 2 +- .../java/one/oth3r/sit/file/ServerConfig.java | 11 +- .../sit-oth3r/lang/{en_US.json => en_us.json} | 0 5 files changed, 113 insertions(+), 16 deletions(-) rename src/main/resources/assets/sit-oth3r/lang/{en_US.json => en_us.json} (100%) diff --git a/.github/workflows/crowdin-download-workflow.yml b/.github/workflows/crowdin-download-workflow.yml index ddaec73..d09141d 100644 --- a/.github/workflows/crowdin-download-workflow.yml +++ b/.github/workflows/crowdin-download-workflow.yml @@ -3,31 +3,123 @@ name: Crowdin Download Action permissions: contents: write pull-requests: write - actions: read on: workflow_dispatch: + inputs: + localization_branch_name: + description: 'The branch to create for the translations PR.' + required: true + default: 'crowdin/translations' + pull_request_base_branch: + description: 'The base branch for the pull request.' + required: true + default: 'dev' jobs: - crowdin: + download-translations: runs-on: ubuntu-latest steps: - - name: Checkout + # Checkout the BASE branch first. The PR branch will be created later. + - name: Checkout Base Branch uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.pull_request_base_branch }} - - name: Synchronize with Crowdin + - name: Configure Git User + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Synchronize with Crowdin (Download Only) uses: crowdin/github-action@v2 with: upload_sources: false upload_translations: false download_translations: true - localization_branch_name: crowdin_translations - - create_pull_request: true - pull_request_title: 'Updated Crowdin translations' - pull_request_body: 'New Crowdin pull request with translations' - pull_request_base_branch_name: 'dev' + create_pull_request: false + localization_branch_name: ${{ github.event.inputs.localization_branch_name }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} - CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} \ No newline at end of file + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} + + rename-files: + needs: download-translations + runs-on: ubuntu-latest + steps: + - name: Checkout Localization Branch + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.localization_branch_name }} + + - name: Configure Git User + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Rename JSON Files to Lowercase + env: + TARGET_DIR: "common/src/main/resources/assets/directionhud/lang/" + run: | + echo "Starting renaming process for JSON files within $TARGET_DIR..." + if [ ! -d "$TARGET_DIR" ]; then + echo "Warning: Target directory '$TARGET_DIR' does not exist. Skipping rename." + exit 0 + fi + find "$TARGET_DIR" -type f -name '*[A-Z]*.json' | while IFS= read -r file; do + original_path="$file" + dir_name=$(dirname "$original_path") + base_name=$(basename "$original_path") + new_base_name=$(echo "$base_name" | tr '[:upper:]' '[:lower:]') + new_path="$dir_name/$new_base_name" + if [ "$original_path" != "$new_path" ]; then + if [ -e "$new_path" ] && [ ! "$(readlink -f "$original_path")" = "$(readlink -f "$new_path")" ]; then + echo "::warning file=$original_path::Cannot rename '$original_path' to '$new_path' because it already exists. Skipping." + else + git mv "$original_path" "$new_path" + fi + fi + done + echo "JSON file renaming complete." + + - name: Commit Renamed Files + run: | + echo "Committing renamed files..." + git add -A + git commit -m "Rename JSON translation files to lowercase for consistency" + echo "Renames committed." + + - name: Push Changes to Localization Branch + run: | + echo "Pushing combined changes to ${{ github.event.inputs.localization_branch_name }}..." + git push origin ${{ github.event.inputs.localization_branch_name }} + + create-pr: + needs: [ download-translations, rename-files ] + runs-on: ubuntu-latest + steps: + - name: Checkout branch + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.localization_branch_name }} + + - name: Set up Git config + run: | + git config user.name "github-actions" + git config user.email "github-actions@github.com" + + - name: Install GitHub CLI + run: sudo apt-get install gh -y + + - name: Authenticate GitHub CLI + run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token + + - name: Create Pull Request + run: | + gh pr create \ + --title "Update translations from Crowdin" \ + --body "This PR includes:\n- New translations from Crowdin\n- Renamed translation files to lowercase" \ + --head ${{ github.event.inputs.localization_branch_name }} \ + --base ${{ github.event.inputs.pull_request_base_branch }} \ + --label "localization" \ No newline at end of file diff --git a/.github/workflows/crowdin-upload-workflow.yml b/.github/workflows/crowdin-upload-workflow.yml index fe9194b..5516194 100644 --- a/.github/workflows/crowdin-upload-workflow.yml +++ b/.github/workflows/crowdin-upload-workflow.yml @@ -2,7 +2,7 @@ name: Crowdin Upload Action on: push: - paths: [ "src/main/resources/assets/sit-oth3r/lang/en_US.json"] + paths: [ "src/main/resources/assets/sit-oth3r/lang/en_us.json"] branches: [ dev ] workflow_dispatch: diff --git a/crowdin.yml b/crowdin.yml index 352acbc..bb81024 100644 --- a/crowdin.yml +++ b/crowdin.yml @@ -6,7 +6,7 @@ files: [ { - "source": "src/main/resources/assets/sit-oth3r/lang/en_US.json", + "source": "src/main/resources/assets/sit-oth3r/lang/en_us.json", "translation": "src/main/resources/assets/sit-oth3r/lang/%locale_with_underscore%.json", } ] \ No newline at end of file diff --git a/src/main/java/one/oth3r/sit/file/ServerConfig.java b/src/main/java/one/oth3r/sit/file/ServerConfig.java index e4bcccf..f4cd25e 100644 --- a/src/main/java/one/oth3r/sit/file/ServerConfig.java +++ b/src/main/java/one/oth3r/sit/file/ServerConfig.java @@ -27,12 +27,12 @@ import java.util.stream.Collectors; public class ServerConfig implements CustomFile { @SerializedName("version") - private Double version = 2.2; + private Double version = 2.3; @SerializedName("lang") - private String lang = "en_US"; + private String lang = "en_us"; @SerializedName("lang-options") - private final String langOptions = "en_US, it_IT, pt_BR, tr_TR, zh_TW, zh_CH, de_DE"; + private final String langOptions = "en_us, it_it, pt_br, tr_tr, zh_tw, zh_ch, de_de"; @SerializedName("keep-active") private Boolean keepActive = true; @@ -276,6 +276,11 @@ public class ServerConfig implements CustomFile { if (version >= 2.0 && version <= 2.1) { version = 2.2; } + if (version == 2.2) { + // make sure that the lang is all lowercase + version = 2.3; + this.lang = this.lang.substring(0,3)+this.lang.substring(3).toLowerCase(); + } } @Override diff --git a/src/main/resources/assets/sit-oth3r/lang/en_US.json b/src/main/resources/assets/sit-oth3r/lang/en_us.json similarity index 100% rename from src/main/resources/assets/sit-oth3r/lang/en_US.json rename to src/main/resources/assets/sit-oth3r/lang/en_us.json