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:
Then, I enabled the Use Base Internationalization check box to separate the translatable parts of the application’s computer code.
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.
From here on, the process of localization can be done in two ways:
- by exporting an .xliff files so that, after that, someone will translate it; or
- by editing the text directly from the program.
For this test, I chose to export the file to open it with an editor.
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:
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.
Then, I deleted the lines in Russian and replaced them with the Spanish translation.
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”.
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.
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.
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:
The final result
The result was a complete success, as the simulated iPhone screen showed all the adapted and translated text.
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.