From 04ef92eb78e7b468086119bdb5958a974d192ac3 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sun, 11 Apr 2021 12:50:11 +0200 Subject: [PATCH] Add gsNotLocalised in ResourceHelper --- .../androidaps/utils/resources/ResourceHelper.kt | 1 + .../utils/resources/ResourceHelperImplementation.kt | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt index 7701def98d..7a068c57ee 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt @@ -10,6 +10,7 @@ interface ResourceHelper { fun gs(@StringRes id: Int): String fun gs(@StringRes id: Int, vararg args: Any?): String fun gq(@PluralsRes id: Int, quantity: Int, vararg args: Any?): String + fun gsNotLocalised(@StringRes id: Int, vararg args: Any?): String fun gc(@ColorRes id: Int): Int fun gd(@DrawableRes id: Int): Drawable? fun gb(@BoolRes id :Int) : Boolean diff --git a/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt index 3e2c3bf461..214ccc8b53 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.utils.resources import android.annotation.SuppressLint import android.content.Context import android.content.res.AssetFileDescriptor +import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.BitmapFactory import android.graphics.drawable.Drawable @@ -10,6 +11,7 @@ import android.util.DisplayMetrics import androidx.annotation.* import androidx.core.content.ContextCompat import info.nightscout.androidaps.core.R +import java.util.* import javax.inject.Inject /** @@ -24,6 +26,12 @@ class ResourceHelperImplementation @Inject constructor(private val context: Cont override fun gq(@PluralsRes id: Int, quantity: Int, vararg args: Any?): String = context.resources.getQuantityString(id, quantity, *args) + override fun gsNotLocalised(@StringRes id: Int, vararg args: Any?) : String = + with(Configuration(context.resources.configuration)) { + setLocale(Locale.ENGLISH) + context.createConfigurationContext(this).getString(id, args) + } + override fun gc(@ColorRes id: Int): Int = ContextCompat.getColor(context, id) override fun gd(@DrawableRes id: Int): Drawable? = context.getDrawable(id)