-
-
Notifications
You must be signed in to change notification settings - Fork 9
6.0 Enhancement #15
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
Merged
Merged
6.0 Enhancement #15
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0a14378
Update README.md
1998code 47c92c3
Update README.md
1998code 613a73c
Support SwiftGlass
1998code 48396f9
Update data.json in zh and add Workflow checking
1998code e11656f
Update validate-json.yml
1998code 57c8c0f
Update validate-json.yml
1998code 47f1b11
Check Localization Completeness
1998code 22b20bf
Update validate-json.yml
1998code 5c13366
Update data.json
1998code 8d7296b
Update data.json
1998code e0a8d15
Update Package.resolved
1998code 0ba3fe7
Delete SwiftNEWTests.swift
1998code 8a8014d
Readme in multi-languages
1998code 532bcfa
Update accessibility
1998code b2d8c93
Update README.md
1998code 8e50310
Update Demo/What's New?.xcodeproj/project.pbxproj
1998code e88ceb5
Update README.md
1998code 6e86dd6
Support tvOS
1998code b73dcc0
Fix macOS
1998code 6845b91
Add Japanese and Korean
1998code 31070b4
Update data.json
1998code fe6d98a
Update README.md
1998code f85aef8
Update README.md
1998code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,243 @@ | ||
| name: Validate JSON Files | ||
|
|
||
| on: | ||
| push: | ||
| paths: | ||
| - '**/*.json' | ||
| pull_request: | ||
| paths: | ||
| - '**/*.json' | ||
| workflow_dispatch: # Allows manual triggering | ||
|
|
||
| jobs: | ||
| validate-json: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '18' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install -g ajv-cli ajv-formats | ||
|
|
||
| - name: Create JSON schema for validation | ||
| run: | | ||
| cat > schema.json << 'EOL' | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object", | ||
| "required": ["version", "new"], | ||
| "properties": { | ||
| "version": { | ||
| "type": "string", | ||
| "pattern": "^\\d+\\.\\d+$|^\\d+\\.\\d+\\.\\d+$" | ||
| }, | ||
| "subVersion": { | ||
| "type": "string", | ||
| "pattern": "^\\d+\\.\\d+\\.\\d+$" | ||
| }, | ||
| "new": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object", | ||
| "required": ["icon", "title", "subtitle", "body"], | ||
| "properties": { | ||
| "icon": { "type": "string" }, | ||
| "title": { "type": "string" }, | ||
| "subtitle": { "type": "string" }, | ||
| "body": { "type": "string" } | ||
| } | ||
| }, | ||
| "minItems": 1 | ||
| } | ||
| } | ||
| }, | ||
| "minItems": 1 | ||
| } | ||
| EOL | ||
|
|
||
| - name: Scan for JSON files | ||
| id: scan | ||
| run: | | ||
| echo "Scanning for JSON files..." | ||
| # Create a temporary file to store the list of JSON files | ||
| touch json_files.txt | ||
|
|
||
| # Find all data.json files and group them by language | ||
| find Demo -name "data.json" -print0 | while IFS= read -r -d '' FILE; do | ||
| # Extract the language from the directory path | ||
| LANG_DIR=$(dirname "$FILE") | ||
| LANG=$(basename "$LANG_DIR") | ||
| echo "$LANG:$FILE" >> json_files.txt | ||
| done | ||
|
|
||
| echo "Found the following JSON files for validation:" | ||
| cat json_files.txt | ||
|
|
||
| echo "Scan completed." | ||
|
|
||
| - name: Validate JSON syntax per language | ||
| run: | | ||
| echo "Validating JSON syntax for each language..." | ||
| ERROR=0 | ||
|
|
||
| # Process each file by language | ||
| while IFS=':' read -r LANG_DIR FILE || [ -n "$FILE" ]; do | ||
| echo "Checking syntax for language: $LANG_DIR - $FILE" | ||
|
|
||
| # Check JSON syntax | ||
| if ! jq empty "$FILE" 2>/dev/null; then | ||
| echo "❌ Invalid JSON syntax in $LANG_DIR ($FILE)" | ||
| ERROR=1 | ||
| else | ||
| echo "✅ JSON syntax is valid for $LANG_DIR" | ||
| fi | ||
| done < json_files.txt | ||
|
|
||
| if [ $ERROR -ne 0 ]; then | ||
| echo "JSON syntax validation failed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Validate schema per language | ||
| run: | | ||
| echo "Validating JSON schema for each language..." | ||
| ERROR=0 | ||
|
|
||
| # Process each file by language | ||
| while IFS=':' read -r LANG_DIR FILE || [ -n "$FILE" ]; do | ||
| echo "Validating schema for language: $LANG_DIR - $FILE" | ||
|
|
||
| # Validate against schema | ||
| if ! npx ajv -s schema.json -d "$FILE" --strict=false; then | ||
| echo "❌ $LANG_DIR ($FILE) does not match the required schema" | ||
| ERROR=1 | ||
| else | ||
| echo "✅ Schema is valid for $LANG_DIR" | ||
| fi | ||
| done < json_files.txt | ||
|
|
||
| if [ $ERROR -ne 0 ]; then | ||
| echo "JSON schema validation failed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "All JSON files are valid! 🎉" | ||
|
|
||
| check-localization-completeness: | ||
| runs-on: ubuntu-latest | ||
| needs: validate-json | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Find JSON files | ||
| id: find-json | ||
| run: | | ||
| # Create a directory to store extracted language files | ||
| mkdir -p extracted_langs | ||
|
|
||
| # Find the base (en) language JSON file | ||
| BASE_FILE=$(find Demo -path "*/en.lproj/data.json" -print -quit) | ||
| if [ ! -f "$BASE_FILE" ]; then | ||
| echo "❌ Base language file (en.lproj/data.json) not found!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Find all localized JSON files | ||
| find Demo -name "data.json" | grep -v "$BASE_FILE" > localized_files.txt | ||
|
|
||
| echo "Base file: $BASE_FILE" | ||
| echo "Found $(wc -l < localized_files.txt) localized files" | ||
|
|
||
| - name: Check for missing versions | ||
| run: | | ||
| BASE_FILE=$(find Demo -path "*/en.lproj/data.json" -print -quit) | ||
|
|
||
| # Extract version numbers from base file | ||
| jq -r '.[].version' "$BASE_FILE" | sort -V > base_versions.txt | ||
|
|
||
| # Create a report file | ||
| touch localization_report.md | ||
| echo "# Localization Completeness Report" >> localization_report.md | ||
| echo "Generated on $(date)" >> localization_report.md | ||
| echo "" >> localization_report.md | ||
|
|
||
| # Check each localized file | ||
| while read -r LOC_FILE; do | ||
| LANG_DIR=$(dirname "$LOC_FILE") | ||
| LANG=$(basename "$LANG_DIR" | sed 's/\.lproj//') | ||
|
|
||
| echo "## Checking $LANG" >> localization_report.md | ||
|
|
||
| # Extract version numbers from localized file | ||
| jq -r '.[].version' "$LOC_FILE" | sort -V > "${LANG}_versions.txt" | ||
|
|
||
| # Find missing versions | ||
| MISSING_VERSIONS=$(comm -23 base_versions.txt "${LANG}_versions.txt") | ||
|
|
||
| if [ -n "$MISSING_VERSIONS" ]; then | ||
| echo "❌ $LANG is missing versions: $MISSING_VERSIONS" | ||
| echo "### Missing versions:" >> localization_report.md | ||
| echo '```' >> localization_report.md | ||
| echo "$MISSING_VERSIONS" >> localization_report.md | ||
| echo '```' >> localization_report.md | ||
| echo "" >> localization_report.md | ||
| EXIT_CODE=1 | ||
| else | ||
| echo "✅ $LANG has all versions from base language" | ||
| echo "✅ All versions present" >> localization_report.md | ||
| echo "" >> localization_report.md | ||
| fi | ||
|
|
||
| # Check content for each version | ||
| echo "### Content comparison:" >> localization_report.md | ||
|
|
||
| while read -r VERSION; do | ||
| # Extract base data for this version | ||
| jq -r --arg v "$VERSION" '.[] | select(.version == $v)' "$BASE_FILE" > "base_${VERSION}.json" | ||
| jq -r --arg v "$VERSION" '.[] | select(.version == $v)' "$LOC_FILE" > "${LANG}_${VERSION}.json" | ||
|
|
||
| if [ -s "${LANG}_${VERSION}.json" ]; then | ||
| # Count items in the "new" array for base and localized | ||
| BASE_ITEMS=$(jq -r '.new | length' "base_${VERSION}.json") | ||
| LOC_ITEMS=$(jq -r '.new | length' "${LANG}_${VERSION}.json") | ||
|
|
||
| if [ "$BASE_ITEMS" -ne "$LOC_ITEMS" ]; then | ||
| echo "❌ $LANG version $VERSION has $LOC_ITEMS items (base has $BASE_ITEMS)" | ||
| echo "- Version $VERSION: $LOC_ITEMS/$BASE_ITEMS items ❌" >> localization_report.md | ||
| EXIT_CODE=1 | ||
| else | ||
| echo "✅ $LANG version $VERSION has all $BASE_ITEMS items" | ||
| echo "- Version $VERSION: $LOC_ITEMS/$BASE_ITEMS items ✅" >> localization_report.md | ||
| fi | ||
| fi | ||
| done < base_versions.txt | ||
|
|
||
| echo "" >> localization_report.md | ||
| done < localized_files.txt | ||
|
|
||
| cat localization_report.md | ||
|
|
||
| # Exit with the accumulated status | ||
| if [ "$EXIT_CODE" -eq 1 ]; then | ||
| echo "❌ Localization check failed - some languages are missing versions or items" | ||
| exit 1 | ||
| else | ||
| echo "✅ All languages have complete translations" | ||
| fi | ||
|
|
||
| - name: Upload Localization Report | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: localization-report | ||
| path: localization_report.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
Demo/What's New?.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.