Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 18  Localization


Now it is time to make the magic happen. Add Spanish versions of all your strings to res/values-es/
strings.xml. (If you do not wish to type these strings in, copy the contents from the solution file. You
can find the URL in the section called Adding an Icon in Chapter 2.)


Listing 18.1  Adding Spanish alternative of string resources


(res/values-es/strings.xml)



IntentoCriminal
Introduzca un título para el crimen.
Título
Detalles
Solucionado
Fecha del crimen:
Crimen Nuevo
Mostrar Subtítulos
Esconder Subtítulos
%1$s crímenes
Elegir Sospechoso
Enviar el Informe del Crimen
%1$s!
El crimen fue descubierto el %2$s. %3$s, y %4$s

El caso está resuelto
El caso no está resuelto
no hay sospechoso.
el/la sospechoso/a es %s.
IntentoCriminal Informe del Crimen
Enviar el informe del crimen a través de

That is all you have to do to provide localized string resources for your app. To confirm, change your
device’s settings to Spanish by opening Settings and finding the language settings. Depending on your
version of Android, these settings will be labeled Language and input, Language and Keyboard, or
something similar.


When you get to a list of language options, choose a setting for Español. The region (España or
Estados Unidos) will not matter, because the qualification -es matches both. (Note that on newer
versions of Android, users can select multiple languages and assign a priority order. If you are on a
newer device, make sure Español appears first in your language settings list.)


Run CriminalIntent and bask in the glory of your newly localized app. When you are done basking,
return your device’s language setting to English. Look for Ajustes or Configuración (Settings) in the
launcher and find the setting that includes Idioma (Language).

Free download pdf