Localization of an iPhone to Spanish with Xcode

To do a localization test of an iPhone to Spanish with Xcode, I based on the tutorial and the application created by Balaji Mallisham. Next you can see how I did the process with my own screenshots.

This application consists of a screen that displays basic information of a country based on the language of the iPhone.

To perform this test, I used the Mac OS program called Xcode, which is only in English.

Loading the application

Once I loaded the sample application, I found that the only existing languages were English and Russian as you can see in Figure 1:

Screens in English and Russian
Figure 1. Display in English and its location in Russian

Then, I enabled the Use Base Internationalization check box to separate the translatable parts of the application’s computer code.

Internationalization
Figure 2. Selecting the Internationalization option.

In the next screen, I had to choose the files and the reference languages to use in order to perform the localization in Spanish. In the image below, you can see the Russian and Base languages. The latter refers to English because it is the original language of the application example.

Localization of an iPhone to Spanish with Xcode: selection of files to perform the localization
Figure 3. Selection of files to perform the localization.

Localization process

From here on, the process of localization can be done in two ways:

  1. by exporting an .xliff files so that, after that, someone will translate it; or
  2. by editing the text directly from the program.

For this test, I chose to export the file to open it with an editor.

Editing XLIFF file
Figure 4. Editing the .xliff file with CotEditor.

Here, I could see that the original text was bounded by the <source> and </source> tags. Also, that the target text had the labels with <target> and </target>. Therefore, I adapted the texts to add the information from Spain. When I reached the end of the file, I realized that there were segments that did not have the target tags (framed in blue in the photo). Then, I decided to add them and write the translations. The result was that when I imported the file, the Xcode program closed itself. So, I immediately realized that this was due to the extra tags I added along with their translations. Therefore, I deleted them and left them as they were.

Importing the file again

Again, I proceeded to import the file. This time, the program did not close and showed me the following screen:

Empty translations screen
Figure 5. Screen showing empty translations.

Precisely, the segments I tried to add by hand and caused the problems are those that appeared on the screen. Furthermore, in the capture, the text appears translated into Russian because it is already localized.

Next, I clicked on Import and went to The Localizable.strings (Spanish) section. And, as you can see in Figure 6, there were the problematic fields with their translation into Russian.

Field to translate
Figure 6. Fields that need to be translated into Spanish.

Then, I deleted the lines in Russian and replaced them with the Spanish translation.

Fields translated to Spanish
Figure 7. Fields translated to Spanish.

The name of the application

I also tried to change the name of the application in English to display it in Spanish. To do this, I edited the InfoPlist.strings section and replaced “iOSLocalizationExample” with “iOSLocalización”.

Change of name
Figure 8. Change of name in English to a Spanish one.

Then, I inspected the other sections that appeared and found Assets.xcassets where the USA and Russia flags appeared.

Since Spain’s flag was not there, when I ran the application and set the iPhone in Spanish, there was no image to show. In fact, looking at the ViewController.swift section, there was an IF sentence that verified the name of an image (Flag), followed by a hyphen and the language code used.

IF sentence
Figure 9. IF sentence that checks the name of the flag image.

So, I looked for a flag on the Internet and added a new set of images to the application. I named this set Flag-ES to follow the nomenclature mentioned above.

Set of images for the Spanish flag
Figure 10. Creation of a set of images for the Spanish flag.

At this point, and after loading the images of the flag, I only had to set the iPhone in Spanish and run the application, as you can see in the screenshot:

Localization of an iPhone to Spanish with Xcode: change of language
Figure 11. Change of the language of the iPhone to Spanish of Spain.

The final result

The result was a complete success, as the simulated iPhone screen showed all the adapted and translated text.

Localization of an iPhone to Spanish with Xcode completed
Figure 12. Application fully localized to Spanish.

I hope you find this small contribution to the localization of an iPhone to Spanish with Xcode interesting, because I am passionate about everything related to it.

Regards.