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

Update scripts to add languages #1005

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 16 additions & 14 deletions .github/workflows/add-lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,36 @@ jobs:
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_NUM: ${{ github.event.issue.number }}
run: |
NEW_LANG=$(sed 's/.*\[\([^]]*\)].*/\1/' <<< "$ISSUE_TITLE")
if [[ $NEW_LANG =~ ^[a-z]{2}(_[A-Z]{2})?$ ]]; then
echo "new_lang=$NEW_LANG" >> $GITHUB_ENV
LANG_CODE=$(sed 's/.*\[\([^]]*\)].*/\1/' <<< "$ISSUE_TITLE")
FULL_LANG=$(sed 's/.*<\([^>]*\)>.*/\1/' <<< "$ISSUE_TITLE")
if [[ $LANG_CODE =~ ^[a-z]{2}(-[A-Z]{2})?$ && $ISSUE_TITLE =~ <[^>]+> ]]; then
echo "lang_code=$LANG_CODE" >> $GITHUB_ENV
echo "full_lang=$FULL_LANG" >> $GITHUB_ENV
echo "issue_num=$ISSUE_NUM" >> $GITHUB_ENV
else
echo Error: language code in wrong format.
echo Error: language name/code in wrong format.
exit 1
fi

# Check out repo:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: next-release

# Check if language has been added previously.
- name: Check if language is already present
run: |
if [ -d "_translator-files/po/${{ env.new_lang }}" ] ; then
echo Error: The language [${{ env.new_lang }}] seems to already exist.
if [ -d "_translator-files/po/${{ env.lang_code }}" ] ; then
echo Error: The language [${{ env.lang_code }}] seems to already exist.
exit 1
else
echo Language: [${{ env.new_lang }}] not detected. Proceeding to add [${{ env.new_lang }}].
echo Language: [${{ env.lang_code }}] seems to be new as no Language: [${{ env.lang_code }}] was found. Proceeding to add [${{ env.lang_code }}].
fi

# Check po4a cache. If CACHE_HIT: true, retrieve the cache.
# If not, install po4a and its dependencies and copy them all to a folder (~/po4a/) to be cached:
- name: Check for po4a cache
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-po4a
with:
path: "~/po4a"
Expand All @@ -60,23 +62,23 @@ jobs:

# Push changes to 'next-release':
- name: Push changes to repo
uses: EndBug/add-and-commit@v7
uses: EndBug/add-and-commit@v9
with:
branch: next-release
default_author: github_actions
message: 'AUTO: Add new language: (${{ env.new_lang }}) #${{ env.issue_num }}'
message: 'AUTO: Add new language: ${{ env.lang_code }}: ${{ env.full_lang }} #${{ env.issue_num }}'

# Add comment to issue informing of the creation of the language files:
- name: Add comment to issue
uses: peter-evans/create-or-update-comment@v1
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ env.issue_num }}
body: |
- The .po files have been created for **${{ env.new_lang }}** and are now available on [Weblate](https://hosted.weblate.org/projects/jamulus/#languages). If you prefer not to use Weblate and intend to submit translations via a Pull Request, your language files can be found on the `next-release` branch in `_translator-files/po/${{ env.new_lang }}/`.
- The .po files have been created for **${{ env.full_lang }}** and are now available on [Weblate](https://hosted.weblate.org/projects/jamulus/#languages). If you prefer not to use Weblate and intend to submit translations via a Pull Request, your language files can be found on the `next-release` branch in `_translator-files/po/${{ env.lang_code }}/`.
- Please consult [this README file](https://github.com/jamulussoftware/jamuluswebsite/tree/next-release/_translator-files#readme) for more information on the translation process.

# Create target translated files. Never pushed to the repo.
- name: Create translated docs and stats
- name: Create translated docs
run: ./_po4a-tools/po4a-create-all-targets.sh

# Build site
Expand Down
32 changes: 17 additions & 15 deletions _po4a-tools/po4a-add-language.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,40 @@ SCRIPT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$SCRIPT_DIR"

# Create and populate .po file folder
mkdir ../_translator-files/po/$new_lang
mkdir ../_translator-files/po/$lang_code
echo ''
echo .po file folder created for "$new_lang"
echo Creating .po files for "$new_lang"
echo .po file folder created for "$lang_code"
echo Creating .po files for "$full_lang"
./po4a-update-templates.sh

# Go to root directory
cd ../

# Create symlinks for 1-index.html file
ln -s -r ./wiki/$new_lang/1-index.html ./1-$new_lang-index.html
# Create symlinks for 1-index.md file
ln -s -r ./wiki/$lang_code/1-index.md ./1-$lang_code-index.md
if [ $(echo $?) == 0 ] ; then
echo ''
echo 1-"$new_lang"-index.html symlink created for "$new_lang" in /
echo 1-"$lang_code"-index.md symlink created for "$full_lang" in /
else
echo Error creating 1-"$new_lang"-index.html symlink in /
echo Error creating 1-"$lang_code"-index.md symlink in /
exit 1
fi

# Add new language to array in _config.yml
sed -i "s/\(\[\"en\",\)/\1 \"$new_lang\",/" _config.yml
# Add new language to _config.yml
sed -i "s/\(\[\"en\",\)/\1 \"$lang_code\",/" _config.yml
sed -i "/^language_names:/a\ $lang_code: $full_lang" _config.yml

if [ $(echo $?) == 0 ] ; then
echo "$new_lang" added to language array in _config.yml
echo "$lang_code" added to _config.yml
else
echo Error adding "$new_lang" to language array in _config.yml
echo Error adding "$lang_code" to _config.yml
exit 1
fi

# Create images folder for new language
if [ ! -d "./assets/img/$new_lang-screenshots" ] ; then
cp -frp ./assets/img/en-screenshots -T ./assets/img/$new_lang-screenshots
echo Screenshots created for "$new_lang" in ./assets/img/"$new_lang"-screenshots/
if [ ! -d "./assets/img/$lang_code-screenshots" ] ; then
cp -frp ./assets/img/en-screenshots -T ./assets/img/$lang_code-screenshots
echo Screenshots created for "$full_lang" in ./assets/img/"$lang_code"-screenshots/
else
echo Error: screenshots folder for "$new_lang" seems to already exist
echo Error: screenshots folder for "$full_lang" seems to already exist
fi
Loading