diff --git a/app/build.gradle b/app/build.gradle index 9a9e65f4..f13a79dc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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() - 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("") - int posEnd = xmlText.indexOf("", posBegin) - String onlyLangArray = xmlText.substring(posBegin, posEnd) - - // add locale codes to localesInXML - var localesInXML = new ArrayList() - for (String line : onlyLangArray.split('\n')) { - if (!line.contains("")) continue - - String localeCode = line.replace("", "").replace("", "") - 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) - } - } -} diff --git a/build.gradle b/build.gradle index 8a5ef916..902077e3 100644 --- a/build.gradle +++ b/build.gradle @@ -39,4 +39,7 @@ allprojects { options.incremental = true options.encoding = 'UTF-8' } -} \ No newline at end of file +} + +// import our custom gradle tasks +apply from: 'customTasks.gradle' \ No newline at end of file diff --git a/customTasks.gradle b/customTasks.gradle new file mode 100644 index 00000000..f5002575 --- /dev/null +++ b/customTasks.gradle @@ -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() + 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("") + int posEnd = xmlText.indexOf("", posBegin) + String onlyLangArray = xmlText.substring(posBegin, posEnd) + + // add locale codes to localesInXML + var localesInXML = new ArrayList() + for (String line : onlyLangArray.split('\n')) { + if (!line.contains("")) continue + + String localeCode = line.replace("", "").replace("", "") + 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) + } + } +}