Skip to content

Commit

Permalink
feat: [ANDROAPP-5647] Add Spanish translations
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmr committed Jun 11, 2024
1 parent 0b46073 commit 2fd4b1a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 12 deletions.
44 changes: 44 additions & 0 deletions designsystem/src/commonMain/resources/values-es/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<string name="show_more">Mostrar más</string>
<string name="show_less">Mostrar menos</string>
<string name="date_birth">FECHA DE NACIMIENTO</string>
<string name="age">EDAD</string>
<string name="or"> O </string>
<string name="years">Años</string>
<string name="months">Meses</string>
<string name="days">Días</string>
<string name="error_one">%d error</string>
<string name="error_other">%d errores</string>
<string name="warning_one">%d advertencia</string>
<string name="warning_other">%d advertencias</string>
<string name="show_fields">Mostrar campos</string>
<string name="hide_fields">Ocultar campos</string>
<string name="action_next">Siguiente</string>
<string name="add_file">Agregar archivo</string>
<string name="yes">Sí</string>
<string name="no">No</string>
<string name="enter_phone_number">Ingrese número de teléfono</string>
<string name="qr_code">Código QR</string>
<string name="sync">Sincronizar</string>
<string name="add_polygon">Agregar polígono</string>
<string name="polygon_captured">Polígono capturado</string>
<string name="add_location">Agregar ubicación</string>
<string name="latitude">Lat</string>
<string name="longitude">Long</string>
<string name="add_signature">Agregar firma</string>
<string name="add_image">Agregar imagen</string>
<string name="not_supported">No soportado</string>
<string name="search">Buscar</string>
<string name="draw_here">Dibujar aquí</string>
<string name="reset">Restablecer</string>
<string name="done">Hecho</string>
<string name="clear_all">Limpiar todo</string>
<string name="no_results_found">No se encontraron resultados</string>
<string name="ok">Aceptar</string>
<string name="cancel">Cancelar</string>
<string name="select_date">Seleccionar fecha</string>
<string name="date_out_of_range">Fecha fuera de rango</string>
<string name="wrong_hour_format">Formato de hora incorrecto</string>
<string name="search_to_see_more">No se muestran todas las opciones.\n Busca para ver más.</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,18 +24,37 @@ actual fun provideQuantityStringResource(id: String, quantity: Int): String {

private fun getResources(): Map<String, String> {
val stringsResources = mutableMapOf<String, String>()
// for translation we could use Locale.current.language to find the proper xml
useResource("values/strings_en.xml") { inputStream ->

val regex = Regex("""<string name="(.+?)">(.+?)</string>""")

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("""<string name="(.+?)">(.+?)</string>""")

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("""<string name="(.+?)">(.+?)</string>""")

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
}
}
}
}
Expand Down

0 comments on commit 2fd4b1a

Please sign in to comment.