diff --git a/designsystem/src/commonMain/resources/values-es/strings.xml b/designsystem/src/commonMain/resources/values-es/strings.xml new file mode 100644 index 000000000..eb8ae5901 --- /dev/null +++ b/designsystem/src/commonMain/resources/values-es/strings.xml @@ -0,0 +1,44 @@ + + + Mostrar más + Mostrar menos + FECHA DE NACIMIENTO + EDAD + O + Años + Meses + Días + %d error + %d errores + %d advertencia + %d advertencias + Mostrar campos + Ocultar campos + Siguiente + Agregar archivo + + No + Ingrese número de teléfono + Código QR + Sincronizar + Agregar polígono + Polígono capturado + Agregar ubicación + Lat + Long + Agregar firma + Agregar imagen + No soportado + Buscar + Dibujar aquí + Restablecer + Hecho + Limpiar todo + No se encontraron resultados + Aceptar + Cancelar + Seleccionar fecha + Fecha fuera de rango + Formato de hora incorrecto + No se muestran todas las opciones.\n Busca para ver más. + diff --git a/designsystem/src/commonMain/resources/values/strings_en.xml b/designsystem/src/commonMain/resources/values/strings.xml similarity index 100% rename from designsystem/src/commonMain/resources/values/strings_en.xml rename to designsystem/src/commonMain/resources/values/strings.xml diff --git a/designsystem/src/desktopMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/resource/String.kt b/designsystem/src/desktopMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/resource/String.kt index dff22d960..a5f33e329 100644 --- a/designsystem/src/desktopMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/resource/String.kt +++ b/designsystem/src/desktopMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/resource/String.kt @@ -5,6 +5,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.res.useResource +import androidx.compose.ui.text.intl.Locale @Composable actual fun provideStringResource(id: String): String { @@ -23,18 +24,37 @@ actual fun provideQuantityStringResource(id: String, quantity: Int): String { private fun getResources(): Map { val stringsResources = mutableMapOf() - // for translation we could use Locale.current.language to find the proper xml - useResource("values/strings_en.xml") { inputStream -> - - val regex = Regex("""(.+?)""") - - inputStream.bufferedReader().useLines { lines -> - lines.forEach { line -> - val matchResult = regex.find(line) - if (matchResult != null) { - val key = matchResult.groupValues[1] - val value = matchResult.groupValues[2] - stringsResources[key] = value + val localePath = "values-${Locale.current.language}/strings.xml" + val defaultPath = "values/strings.xml" + + try { + useResource(localePath) { inputStream -> + + val regex = Regex("""(.+?)""") + + inputStream.bufferedReader().useLines { lines -> + lines.forEach { line -> + val matchResult = regex.find(line) + if (matchResult != null) { + val key = matchResult.groupValues[1] + val value = matchResult.groupValues[2] + stringsResources[key] = value + } + } + } + } + } catch (e: IllegalArgumentException) { + useResource(defaultPath) { inputStream -> + val regex = Regex("""(.+?)""") + + inputStream.bufferedReader().useLines { lines -> + lines.forEach { line -> + val matchResult = regex.find(line) + if (matchResult != null) { + val key = matchResult.groupValues[1] + val value = matchResult.groupValues[2] + stringsResources[key] = value + } } } }