Skip to content

Commit

Permalink
Replace deprecated toLowerCase / toUpperCase with lowercase / uppercase
Browse files Browse the repository at this point in the history
Without arguments lowercase() uses the invariant culture by default, whereas toLowerCase() uses the system's default locale. Using the invariant culture is better because it leads to the same result on every system.

Replace toLowerCase(Locale.US) with lowercase() for simplicity. Analogous for toUpperCase(Locale.US).
  • Loading branch information
riQQ authored and westnordost committed Nov 17, 2023
1 parent 68a227b commit 49f9d25
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/POEditorDownloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private fun fetchLocalizationDownloadUrl(apiToken: String, projectId: String, la
connection.doOutput = true
connection.requestMethod = "POST"
connection.outputStream.bufferedWriter().use { it.write(
"api_token=$apiToken&id=$projectId&language=${languageCode.toLowerCase(Locale.US)}&type=$format&filters=translated"
"api_token=$apiToken&id=$projectId&language=${languageCode.lowercase()}&type=$format&filters=translated"
) }
}) { inputStream ->
val response = Parser.default().parse(inputStream) as JsonObject
Expand Down
5 changes: 2 additions & 3 deletions buildSrc/src/main/java/UpdateNsiPresetsTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import java.io.File
import java.net.URL
import java.util.Locale

/** Download and split the brand presets from the name suggestion index by countries they are in:
* Instead of one big presets file, sort those brands that only exist in certain countries into own
Expand Down Expand Up @@ -77,7 +76,7 @@ open class UpdateNsiPresetsTask : DefaultTask() {
}

for ((country, jsonObject) in byCountryMap.entries) {
val name = "$targetDir/presets${ if (country != null) "-${country.toUpperCase(Locale.US)}" else "" }.json"
val name = "$targetDir/presets${ if (country != null) "-${country.uppercase()}" else "" }.json"
File(name).writeText(jsonObject.toJsonString())
}
}
Expand Down Expand Up @@ -124,7 +123,7 @@ private fun expandM49Codes(codes: MutableList<String>) {
val expandedCodes = M49Codes[cc]
if (expandedCodes != null) {
codes.removeAt(i)
codes.addAll(i, expandedCodes.map { it.toLowerCase(Locale.US) })
codes.addAll(i, expandedCodes.map { it.lowercase() })
} else {
++i
}
Expand Down
3 changes: 1 addition & 2 deletions buildSrc/src/main/java/UpdateStoreDescriptionsTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import java.io.File
import java.util.Locale

/** Update the metadata that contain the store descriptions for the app (for F-Droid) */
open class UpdateStoreDescriptionsTask : DefaultTask() {
Expand All @@ -19,7 +18,7 @@ open class UpdateStoreDescriptionsTask : DefaultTask() {
val languageCodes = fetchAvailableLocalizations(apiToken, projectId).map { it.code }

for (languageCode in languageCodes) {
if (languageCode.toLowerCase(Locale.US) == "en-us") continue
if (languageCode.lowercase() == "en-us") continue
println(languageCode)
val translations = fetchLocalizationJson(apiToken, projectId, languageCode)

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/UpdateWebsiteTranslationsTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ open class UpdateWebsiteTranslationsTask : DefaultTask() {
for (languageCode in languageCodes) {
println(languageCode)
val translations = fetchLocalizationJson(apiToken, projectId, languageCode)
val lang = if (languageCode.toLowerCase() == "en-us") "en" else languageCode.toLowerCase()
val lang = if (languageCode.lowercase() == "en-us") "en" else languageCode.lowercase()
val strings = translations.filterKeys { it in keys || it in requiredKeys }
// only accept complete translations
if (requiredKeys.all { it in strings.keys }) {
Expand Down

0 comments on commit 49f9d25

Please sign in to comment.