Skip to content

Commit

Permalink
require that translations that are completed by 90% must be included …
Browse files Browse the repository at this point in the history
…in the app

Just so it is not missed if the translation to a language is completed. Saves me from looking through POEditor website from time to time
  • Loading branch information
westnordost committed Oct 21, 2023
1 parent 2b6882c commit f5337e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ tasks.register<UpdateAppTranslationsTask>("updateTranslations") {

tasks.register<UpdateAppTranslationCompletenessTask>("updateTranslationCompleteness") {
group = "streetcomplete"
languageCodes = bcp47ExportLanguages
mustIncludeLanguagePercentage = 90
apiToken = properties["POEditorAPIToken"] as String
projectId = poEditorProjectId
targetFiles = { "$projectDir/src/main/res/values-$it/translation_info.xml" }
Expand Down
20 changes: 17 additions & 3 deletions buildSrc/src/main/java/UpdateAppTranslationCompletenessTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,38 @@ import org.gradle.api.tasks.TaskAction
import java.io.File
import java.util.Locale

/** Update a resources file that specifies the current translation completeness for every language */
/** Update a resources file that specifies the current translation completeness for every language
* and checks if a language should be included that isn't yet */
open class UpdateAppTranslationCompletenessTask : DefaultTask() {

@get:Input var projectId: String? = null
@get:Input var apiToken: String? = null
@get:Input var languageCodes: Collection<String>? = null
@get:Input var mustIncludeLanguagePercentage: Int = 80
@get:Input var targetFiles: ((androidResCode: String) -> String)? = null

@TaskAction fun run() {
val targetFiles = targetFiles ?: return
val apiToken = apiToken ?: return
val projectId = projectId ?: return
val exportLanguages = languageCodes?.map { Locale.forLanguageTag(it) }

val localizations = fetchAvailableLocalizations(apiToken, projectId)
for (status in localizations) {
val locale = Locale.forLanguageTag(status.code).transformPOEditorLanguageTag()
val locale = Locale.forLanguageTag(status.code)
val completedPercentage = status.percentage

val androidResCodes = locale.toAndroidResCodes()
if (exportLanguages != null && !exportLanguages.any { it == locale } && locale != Locale.US) {
if (completedPercentage >= mustIncludeLanguagePercentage) {
throw Exception(
"App has been translated ${completedPercentage}% to " +
"${locale.displayLanguage} (${locale.language}) " +
" but the language is not included in the app."
)
}
}

val androidResCodes = locale.transformPOEditorLanguageTag().toAndroidResCodes()

// create a metadata file that describes how complete the translation is
for (androidResCode in androidResCodes) {
Expand Down

0 comments on commit f5337e0

Please sign in to comment.