From f1805c9ddd982f1a3bee76e0b14948f377429868 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 17 May 2023 11:25:07 +0200 Subject: [PATCH] convert further strings to be translatable and unify logging tag Signed-off-by: Andy Scherzinger --- .../talk/translate/TranslateActivity.kt | 37 ++++++++++--------- app/src/main/res/values/strings.xml | 2 + 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/translate/TranslateActivity.kt b/app/src/main/java/com/nextcloud/talk/translate/TranslateActivity.kt index ee9c90e55..520dce1b2 100644 --- a/app/src/main/java/com/nextcloud/talk/translate/TranslateActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/translate/TranslateActivity.kt @@ -112,18 +112,18 @@ class TranslateActivity : BaseActivity() { private fun getLanguageOptions() { val currentUser: User = userManager.currentUser.blockingGet() val json = JSONArray(CapabilitiesUtilNew.getLanguages(currentUser).toString()) - Log.i("TranslateActivity", "json is: $json") + Log.i(TAG, "json is: $json") - val fromLanguagesSet = mutableSetOf("Detect Language") - val toLanguagesSet = mutableSetOf("Device Settings") + val fromLanguagesSet = mutableSetOf(resources.getString(R.string.translation_detect_language)) + val toLanguagesSet = mutableSetOf(resources.getString(R.string.translation_device_settings)) for (i in 0..json.length() - 1) { val current = json.getJSONObject(i) - if (current.getString("from") != Locale.getDefault().language) { - toLanguagesSet.add(current.getString("fromLabel")) + if (current.getString(FROM_ID) != Locale.getDefault().language) { + toLanguagesSet.add(current.getString(FROM_LABEL)) } - fromLanguagesSet.add(current.getString("toLabel")) + fromLanguagesSet.add(current.getString(TO_LABEL)) } fromLanguages = fromLanguagesSet.toTypedArray() @@ -156,7 +156,7 @@ class TranslateActivity : BaseActivity() { "" } - Log.i("TranslateActivity", "Url is: $translateURL") + Log.i(TAG, "Url is: $translateURL") ncApi.translateMessage(credentials, translateURL) ?.subscribeOn(Schedulers.io()) ?.observeOn(AndroidSchedulers.mainThread()) @@ -206,7 +206,7 @@ class TranslateActivity : BaseActivity() { } private fun getISOFromLanguage(language: String): String { - if (language == "Device Settings") { + if (resources.getString(R.string.translation_device_settings).equals(language)) { return Locale.getDefault().language } @@ -215,8 +215,8 @@ class TranslateActivity : BaseActivity() { for (i in 0..json.length() - 1) { val current = json.getJSONObject(i) - if (current.getString("fromLabel") == language) { - return current.getString("from") + if (current.getString(FROM_LABEL) == language) { + return current.getString(FROM_ID) } } @@ -238,10 +238,7 @@ class TranslateActivity : BaseActivity() { if (++check > 1) { val fromLabel: String = getISOFromLanguage(parent.getItemAtPosition(position).toString()) val toLabel: String = getISOFromLanguage(binding.toLanguageSpinner.selectedItem.toString()) - Log.i( - "TranslateActivity", "fromLanguageSpinner :: fromLabel = $fromLabel, toLabel = $ count: " + - "$check" - ) + Log.i(TAG, "fromLanguageSpinner :: $FROM_LABEL = $fromLabel, $TO_LABEL = $ count: $check") translate(fromLabel, toLabel) } } @@ -256,10 +253,7 @@ class TranslateActivity : BaseActivity() { if (++check > 2) { val toLabel: String = getISOFromLanguage(parent.getItemAtPosition(position).toString()) val fromLabel: String = getISOFromLanguage(binding.fromLanguageSpinner.selectedItem.toString()) - Log.i( - "TranslateActivity", "toLanguageSpinner :: fromLabel = $fromLabel, toLabel = $toLabel " + - "count: $check" - ) + Log.i(TAG, "toLanguageSpinner :: $FROM_LABEL = $fromLabel, $TO_LABEL = $toLabel count: $check") translate(fromLabel, toLabel) } } @@ -269,4 +263,11 @@ class TranslateActivity : BaseActivity() { } } } + + companion object { + private val TAG = TranslateActivity::class.simpleName + private const val FROM_ID = "from" + private const val FROM_LABEL = "fromLabel" + private const val TO_LABEL = "toLabel" + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a1b3e757b..e386f5d1a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -658,6 +658,8 @@ How to translate with transifex: Scroll to bottom Translate Translation + Detect language + Device settings Translation failed Could not detect language