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

Test cxspa 9258 #19968

Draft
wants to merge 41 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
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
44 changes: 44 additions & 0 deletions .github/workflows/validate-translations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on:
pull_request:
paths:
- '**/assets/translations/**'

env:
NODE_VERSION: '20'

name: Validate Configuration of Translation Files
jobs:
validate-translations:
name: Validate Translations
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}

- name: Run Translation Validation Script
run: |
BASE_COMMIT=${{ github.event.pull_request.base.sha }}
HEAD_COMMIT=${{ github.event.pull_request.head.sha }}

# Get the paths of the changed files
changed_files=$(git diff --name-only $BASE_COMMIT $HEAD_COMMIT | grep 'assets/translations')

if [ -n "$changed_files" ]; then
for file in $changed_files; do
# Extract the folder path from the file path to pass to the script
folder_path=$(echo "$file" | sed 's|\(.*assets/translations\).*|\1|')
echo "Changes detected in $folder_path"
sh ./ci-scripts/validate-translations.sh "$folder_path"
done
else
echo "No translation changes detected"
exit 1
fi
48 changes: 48 additions & 0 deletions ci-scripts/validate-translations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/sh
# scripts/handle-translation-changes.sh

folder_path=$1
translations_file="$folder_path/translations.ts"

# Function to check if an export statement exists in a file
check_export_statements() {
local folder=$1
local file=$2
local statement="from './$folder/index';"
if ! grep -q "$statement" "$file"; then
echo "$folder is not listed in $file"
exit 1
else
echo "$folder is already listed in $file"
fi
}

# Function to check import statements in index.ts files
check_import_statements() {
local folder=$1
local index_file="$folder_path/$folder/index.ts"
[ -f "$index_file" ] || { echo "Index file not found: $index_file"; exit 1; }

json_files=$(find "$folder_path/$folder" -maxdepth 1 -type f -name "*.json" -exec basename {} \;)
for json_file in $json_files; do
local statement="from './$json_file';"
if ! grep -q "$statement" "$index_file"; then
echo "$json_file not found in $index_file"
exit 1
else
echo "$json_file is already listed in $index_file"
fi
done
}

# Ensure the translations file exists
[ -f "$translations_file" ] || { echo "Translations file not found: $translations_file"; exit 1; }

# Get the list of translation folders
translation_folders=$(find "$folder_path" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)

# Check if each folder and index file is listed in the translations file
for folder in $translation_folders; do
check_export_statements "$folder" "$translations_file"
check_import_statements "$folder"
done
2 changes: 1 addition & 1 deletion integration-libs/s4om/assets/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"lib": {
"entryFile": "./public_api.ts"
}
}
}
2 changes: 1 addition & 1 deletion integration-libs/s4om/assets/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export * from './translations/translations';
/**
* @deprecated Please use **specific language** translations (suffixed with language code) instead,
* like in the following example:
* ```diff
* ```diffs
* i18n: {
* - resources: s4omTranslations
* + resources: { en: s4omTranslationsEn }
Expand Down
2 changes: 2 additions & 0 deletions integration-libs/s4om/assets/translations/de/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* test */

import s4omScheduleLines from './s4omScheduleLines.json';
export const de = {
s4omScheduleLines,
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions integration-libs/s4om/assets/translations/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

/**
* test
*/

import { TranslationChunksConfig } from '@spartacus/core';

export const s4omTranslationChunksConfig: TranslationChunksConfig = {
Expand Down
Loading