Skip to content

Commit

Permalink
don't use suffix for fdroid build
Browse files Browse the repository at this point in the history
  • Loading branch information
CampelloManuel committed Jul 26, 2023
1 parent f29d773 commit a2ce6f4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 64 deletions.
63 changes: 0 additions & 63 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -215,66 +215,3 @@ dependencies {
// no kotlin!
// implementation "org.jetbrains.kotlin:kotlin-stdlib:1.7.20"
}

// run with: ./gradlew checkLanguages
task checkLanguages {

// TODO Feeder has a better version of this, but you need to change the locales code. See:
// https://gitlab.com/spacecowboy/Feeder/-/blob/master/app/build.gradle.kts#L344

group 'NoNonsenseNotes custom tasks'
description 'Ensure all languages in res/values-*/strings.xml are selectable in the spinner'

var readFromFolders = () -> {
// Read res/values/ folders, add their codes to localesInFolders
File resDir = new File(projectDir, "src/main/res")
FileFilter theFilter = (file) -> file.name.toLowerCase().startsWith("values")
File[] dirs = resDir.listFiles(theFilter)

var localesInFolders = new ArrayList<String>()
for (File valueFolder : dirs) {
// exclude folders like 'values-600dp' which don't represent languages
if (valueFolder.name.contains("0dp")) continue
if (valueFolder.name.contains("values-land")) continue

String localeCode = valueFolder.name.replace("values-", "")
localesInFolders.add(localeCode)
}
return localesInFolders
}

var readFromXML = () -> {
// read the language list in arrays.xml
File arrFile = new File(projectDir, "src/main/res/values/arrays.xml")
var reader = new FileReader(arrFile.absolutePath)
String xmlText = reader.text
reader.close()

// locate where the "translated_langs" array is
int posBegin = xmlText.indexOf("<string-array name=\"translated_langs\" tools:ignore=\"MissingTranslation\">")
int posEnd = xmlText.indexOf("</string-array>", posBegin)
String onlyLangArray = xmlText.substring(posBegin, posEnd)

// add locale codes to localesInXML
var localesInXML = new ArrayList<String>()
for (String line : onlyLangArray.split('\n')) {
if (!line.contains("<item>")) continue

String localeCode = line.replace("<item>", "").replace("</item>", "")
localesInXML.add(localeCode)
}

return localesInXML
}

doLast {
// actually run the task
var listDir = readFromFolders()
var listXML = readFromXML()
if (listDir.size != listXML.size) {
String errMsg = "Outdated translation: XML element has " + listXML.size
errMsg += " locales, but the values-* folders are " + listDir.size
throw new GradleException(errMsg)
}
}
}
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ allprojects {
options.incremental = true
options.encoding = 'UTF-8'
}
}
}

// import our custom gradle tasks
apply from: 'customTasks.gradle'
64 changes: 64 additions & 0 deletions customTasks.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// custom tasks for gradle

// run with: ./gradlew checkLanguages
task checkLanguages {

// TODO Feeder has a better version of this, but you need to change the locales code. See:
// https://gitlab.com/spacecowboy/Feeder/-/blob/master/app/build.gradle.kts#L344

group 'NoNonsenseNotes custom tasks'
description 'Ensure all languages in res/values-*/strings.xml are selectable in the spinner'

var readFromFolders = () -> {
// Read res/values/ folders, add their codes to localesInFolders
File resDir = new File(projectDir, "app/src/main/res")
FileFilter theFilter = (file) -> file.name.toLowerCase().startsWith("values")
File[] dirs = resDir.listFiles(theFilter)

var localesInFolders = new ArrayList<String>()
for (File valueFolder : dirs) {
// exclude folders like 'values-600dp' which don't represent languages
if (valueFolder.name.contains("0dp")) continue
if (valueFolder.name.contains("values-land")) continue

String localeCode = valueFolder.name.replace("values-", "")
localesInFolders.add(localeCode)
}
return localesInFolders
}

var readFromXML = () -> {
// read the language list in arrays.xml
File arrFile = new File(projectDir, "app/src/main/res/values/arrays.xml")
var reader = new FileReader(arrFile.absolutePath)
String xmlText = reader.text
reader.close()

// locate where the "translated_langs" array is
int posBegin = xmlText.indexOf("<string-array name=\"translated_langs\" tools:ignore=\"MissingTranslation\">")
int posEnd = xmlText.indexOf("</string-array>", posBegin)
String onlyLangArray = xmlText.substring(posBegin, posEnd)

// add locale codes to localesInXML
var localesInXML = new ArrayList<String>()
for (String line : onlyLangArray.split('\n')) {
if (!line.contains("<item>")) continue

String localeCode = line.replace("<item>", "").replace("</item>", "")
localesInXML.add(localeCode)
}

return localesInXML
}

doLast {
// actually run the task
var listDir = readFromFolders()
var listXML = readFromXML()
if (listDir.size != listXML.size) {
String errMsg = "Outdated translation: XML element has " + listXML.size
errMsg += " locales, but the values-* folders are " + listDir.size
throw new GradleException(errMsg)
}
}
}

0 comments on commit a2ce6f4

Please sign in to comment.