Skip to content

Commit

Permalink
add crowdin translations download / upload task
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Jan 18, 2024
1 parent 390d091 commit cc66e70
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 45 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Upload lang keys to Crowdin

on:
workflow_dispatch:
push:
branches:
- '1.[0-9]+'
- '1.[0-9]+.[0-9]+'
paths:
- 'src/main/resources/assets/vampirism/lang/en_us.json'
- 'src/main/resources/assets/vampirismguide/lang/en_us.json'

jobs:
upload-translations:
environment: Testing
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup Java JDK
uses: actions/setup-java@v3.1.0
with:
java-version: '17'
distribution: 'adopt'
cache: 'gradle'
- name: Determine Crowdin branch
id: get_crowdin_branch
run: |
output=$(./gradlew crowdinBranch)
version=$(echo $output | awk -F ': ' '{print $2}')
echo "crowdin_branch=$version" >> $GITHUB_OUTPUT
- name: Upload translation keys
uses: crowdin/github-action@v1
with:
crowdin_branch_name: ${{ steps.get_crowdin_branch.outputs.crowdin_branch }}
env:
CROWDIN_KEY: ${{ secrets.CROWDIN_KEY }}
- name: Install Crowdin CLI
run: npm i -g @crowdin/cli
- name: Pre-translate
run: crowdin pre-translate -b ${{ steps.get_crowdin_branch.outputs.crowdin_branch }} --translate-with-perfect-match-only --translate-untranslated-only --method=tm
env:
CROWDIN_KEY: ${{ secrets.CROWDIN_KEY }}
101 changes: 101 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Publish

on:
push:
tags:
- v*
workflow_dispatch:
inputs:
versionType:
description: 'Version Type'
required: true
default: 'alpha'
type: choice
options:
- alpha
- beta
- release
additionalVersionInfo:
description: 'Additional Version Info. Only relevant for beta versions.'
required: false
default: ''
type: string
changelog:
description: 'Changelog added to Curseforge and Modrinth'
required: false
default: ''
type: string

permissions:
contents: read

jobs:
determine-environment:
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.get_environment.outputs.environment }}
version: ${{ steps.get_environment.outputs.version }}
steps:
- uses: actions/checkout@v3
- name: Determine Environment
id: get_environment
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
if [[ "${{ github.event.inputs.versionType }}" == 'alpha' ]]; then
echo "environment=Testing" >> $GITHUB_OUTPUT
echo "version=alpha" >> $GITHUB_OUTPUT
elif [[ "${{ github.event.inputs.versionType }}" == 'beta' ]]; then
echo "environment=Testing" >> $GITHUB_OUTPUT
echo "version=beta=${{ github.event.inputs.additionalVersionInfo }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.event.inputs.versionType }}" == 'release' ]]; then
echo "environment=Release" >> $GITHUB_OUTPUT
echo "version=release" >> $GITHUB_OUTPUT
fi
elif [[ ${{ github.event.ref }} =~ refs\/tags\/v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)-(0|[1-9]\d*)\.(0|[1-9]\d*) ]]; then
echo "environment=Release" >> $GITHUB_OUTPUT
echo "version=release" >> $GITHUB_OUTPUT
fi
determine-crowdin-branch:
runs-on: ubuntu-latest
outputs:
crowdin_branch: ${{ steps.get_crowdin_branch.outputs.crowdin_branch }}
steps:
- uses: actions/checkout@v3
- name: Setup Java JDK
uses: actions/setup-java@v3.1.0
with:
java-version: '17'
distribution: 'adopt'
cache: 'gradle'
- name: Determine Crowdin branch
id: get_crowdin_branch
run: |
output=$(./gradlew crowdinBranch)
version=$(echo $output | awk -F ': ' '{print $2}')
echo "crowdin_branch=$version" >> $GITHUB_OUTPUT
publish:
runs-on: ubuntu-latest
needs: [determine-crowdin-branch, determine-environment]
environment: ${{ needs.determine-environment.outputs.environment }}
if: needs.determine-environment.outputs.version != '' && needs.determine-environment.outputs.environment != ''

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
cache: 'gradle'
- name: Install Crowdin CLI
run: npm i -g @crowdin/cli
- name: Download translations
run: crowdin download -b ${{ needs.determine-crowdin-branch.outputs.crowdin_branch }}
env:
CROWDIN_KEY: ${{ secrets.CROWDIN_KEY }}
- name: Publish
uses: gradle/gradle-build-action@v2.7.0
with:
arguments: publishAll -PMAVEN_URL=${{ secrets.MAVEN_URL }} -PMAVEN_USER=${{ secrets.MAVEN_USER }} -PMAVEN_TOKEN=${{ secrets.MAVEN_TOKEN }} -PCURSEFORGE_API=${{ secrets.CURSEFORGE_API }} -PMODRINTH_API=${{ secrets.MODRINTH_API }} -PCHANGELOG=${{ github.event.inputs.changelog }} -P${{ needs.determine-environment.outputs.version }}
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ tasks.named('processResources', ProcessResources).configure {
}

tasks.named('jar', Jar).configure {
dependsOn 'crowdin'

includeEmptyDirs = false

from sourceSets.main.output.classesDirs
from sourceSets.api.output.classesDirs
from sourceSets.lib.output.classesDirs
Expand Down
19 changes: 19 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
project_id: "113663"
api_token_env: CROWDIN_KEY
base_path: "."
base_url: "https://api.crowdin.com"

preserve_hierarchy: true

files: [
{
source: "src/main/resources/assets/vampirism/lang/en_us.json",
translation: "src/main/resources/assets/vampirism/lang/%locale_with_underscore%.json",
dest: "main_translations.json",
},
{
source: "src/main/resources/assets/vampirismguide/lang/en_us.json",
translation: "src/main/resources/assets/vampirismguide/lang/%locale_with_underscore%.json",
dest: "guide.json",
}
]
42 changes: 2 additions & 40 deletions gradle/crowdin.gradle
Original file line number Diff line number Diff line change
@@ -1,43 +1,5 @@
tasks.register('downloadCrowdin') {
ext {
output = file('build/crowdin_raw.zip')
update = file('build/crowdin.json')
id = 'vampirism'
}
outputs.upToDateWhen { false }
onlyIf {
project.hasProperty('VAMPIRISM_CROWDIN_KEY') && !project.gradle.startParameter.isOffline()
}
tasks.register('crowdinBranch') {
doLast {
download {
src "https://api.crowdin.com/api/project/${id}/export?key=${project.VAMPIRISM_CROWDIN_KEY}&export_translated_only&json"
dest update
overwrite true
}
if (!update.text.contains('success')) {
throw new RuntimeException("Crowdin export failed, see ${update} for more info")
}
download {
src "https://api.crowdin.com/api/project/${id}/download/all.zip?key=${project.VAMPIRISM_CROWDIN_KEY}"
dest output
overwrite true
}
}
}

tasks.register('crowdin', Copy) {
dependsOn downloadCrowdin
onlyIf {
!downloadCrowdin.state.skipped
}
destinationDir = file('build/translations')
from(zipTree(downloadCrowdin.output)) {
filter { String line ->
line.indexOf("\"\"") != -1 ? null : line //Filter empty translations
}
filteringCharset = 'UTF-8'
exclude { it.isDirectory() }
rename { it.toLowerCase() }//Minecraft needs it lowercase.
exclude '**/*.lang' //Pre-1.13 format
print("${project.main_version}.${project.major_version}")
}
}
5 changes: 3 additions & 2 deletions gradle/deploy.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ curseforge {
project {
id = "233029"

changelog = findProperty("CHANGELOG") ?:""
if (project.type == "beta") {
releaseType = 'beta'
//changelog = new File("resources/changelog/${project.version}.txt").text
} else if (project.type == "release") {
releaseType = 'release'
} else {
releaseType = 'alpha'
changelog = "This version should not be used in your 'productive' world. It contains the latest features, but also the latest bugs.\n Probably not all features are finished.\n To see what might have changed visit our Github page and browse the latest commits."
changelog = !(findProperty("CHANGELOG") ?: "").toString().isEmpty() ? getProperty("CHANGELOG") : "This version should not be used in your 'productive' world. It contains the latest features, but also the latest bugs.\n Probably not all features are finished.\n To see what might have changed visit our Github page and browse the latest commits."
}
addGameVersion project.minecraft_version

Expand Down Expand Up @@ -108,9 +109,9 @@ publishing {

// Make sure it runs after build!
modrinth {
changelog = findProperty("CHANGELOG") ?:""
if (project.type == "beta") {
versionType = 'beta'
//changelog = new File("resources/changelog/${project.version}.txt").text
} else if (project.type == "release") {
versionType = 'release'
} else {
Expand Down

0 comments on commit cc66e70

Please sign in to comment.