Translations not loaded from Main.Storyboard (English) - ios

The problem my IOS app is facing is that all texts, titles, labels to be translated automatically in the Storyboard are not. At the same time, all texts, titles, labels to be translated by my Swift code, using NSLocalizableStrings are working well.
Here is my environment :
Xcode v 9.4.1
Development Language : English
Localization, English - 6 files localized
Development Language : French - 2 files localized (this line is below the other, correct ?)
Main.Storyboard includes:
Main.Storyboard (Base)
Main.strings (English), which contains all translations in English
The .strings files are correct and contains the translations for NSLocalizable functions
I have done Export for Localization to get an en.xliff file
In the file, it says source=fr and target=en, which is good
I have translated labels, titles, texts, etc in the en .xliff file
I have done Import for Localization using the en .xliff file
To test localization, I do Edit Scheme / Run, with Application Language set to English and Application Region set to System Region
What I see :
Whatever the view, all texts to be translated by a NSLocalizableString function in the Swift code are correctly translated and displayed as expected. Good
But, all texts to be translated automatically by the Storyboard are still displayed in French. All of them (View Title, Button, Label, etc). It looks like the Main.strings (English) is not read at all.
This last part is supposed to be straight forward, isn’t it ?
I have removed three times English and redo the full Localization process, with no effect.
My backup solution is to move all translations into the Swift code and not take advantage of the Storyboard automated translations, but honestly this is not exciting.
Any clue ? Any help ?
Many thanks

Problem:
If you create Localization StoryBoard. and after that you will add some label or button then That will not available in Localization storyboard.
Solution:
Delete complete Localization Story(< YourStoryBoardName >.String) from project. Don't remove only refrence.
Open en.lproj> < YourStoryBoardName >.String And Delete. Do this for other language also This Then again create this you will find all button and label in Localization
Important Note:
By deleting your All localization String will delete So do the backup
first.

Related

How to set Base Localization & Development Language in Xcode 12(.5)?

I'm writing this question because a lot of information on Stackoverflow (and even Apple's developer website) about this topic is unfortunately partially outdated:
I want to support multiple languages in my Xcode 12.5/Swift 5/iOS 12.3+ app: German as the default language and English as a "fallback".
Currently the "Info" tab lists two "Localization" languages:
The "Localization" section of the File Inspector for both my Main.storyboard and LaunchScreen.storyboard file look like this (by default):
"Base" is checked and that's why the first screenshot shows 2 files for it.
The language in Info.plist is set to the following:
So far I haven't touched the actual localization settings yet and I've been using the same language for every label,... in XIB (which is probably saved in "Base").
According to Apple's old Localization Guide, "Base" is the default language that is used, as long as it's included in the user's language settings (so in my case: German). The "Developer Language" is the "fallback" language that is used if the user's language settings don't include the base language (in my case: English). This Q&A page also says:
If you adopt Base Localization, make sure that the value of
CFBundleDevelopmentRegion matches the language used by your content in
the Base.lproj folder.
... and in this guide enabling the base localization for "English - Development Language" for both storyboards adds 2 localized files to it, without actually adding another ("Base") localization to the list. As you can see on my first screenshot, "Base" and "Development" are separate list entries, which wasn't the case in earlier Xcode versions.
My first question is: Did I understand all of this correctly? It's a bit confusing that the quote sees "Base" and "Development Language" as the same thing, even though you can of course have a default language that isn't the "fallback" language.
The same Q&A I linked above also goes into detail about regional versions of a specific language:
If my app supports "German" (language code: "de") but the user's language settings only list e.g. Austrian German ("de_AT"), then the app is still going to set its own language to German. Let's say I want to use Swiss German (de_CH) as the default language but the user only picked Austrian German ("de_AT") in his settings, does this still work the same way? Should you rather set your app's default language to the regular non-regional language (German = "de") instead, even if the labels,... use e.g. Swiss German words?
How do I change the "Base" language to German (let's say, "de_CH") and also make it appear as that in the list, while using English ("en") as the "fallback"? I did find a similar question but unfortunately the steps described in the answer don't work the same way in Xcode 12.5. anymore.
What I wanted to achieve:
Support English but use German as the default language that is also used if the user's language settings don't include English or German.
How I achieved this in Xcode 12.5:
Add "German (de)" to the "Localizations" list via the little "+" button. In the new Choose files and reference language to create German localization pop-up every storyboard file should already be ticked by default. This adds .strings (German) localization files for all storyboards in the Project Navigator on the left:
In Main.storyboard's File Inspector tick the "English" box in the "Localization" section (this might take a while). This adds an additional Main.strings (English) file in the Project Navigator. Repeat this step for each storyboard, including the launch screen.
To change the "Development Language", which is the language the app uses by default and also if it doesn't support any of the languages the user set in their device's language settings, close Xcode, then open the project's .xcodeproj file with a text editor (I used BBEdit, which is free). There should be a list of files, including project.pbxproj. Open it and set developmentRegion (= development language) to the language code of the language that you added in step 1, so in my case "de". Do not use a different code (e.g. add "German (de)" but set it to "de_CH") because that's going to create an additional localization.
There are now two ways to finish this part of localization:
A. Leave it as is. Changes in storyboard aren't going to affect any of the .strings files. Advantage: The text can be edited directly (without using storyboard), which is useful if you aren't the person who's working on the translations. Disadvantage: You can't quickly see and test the changes to a translation in storyboard but have to run the app in the simulator or on an actual device.
B. Use the default language as "Base" language: Untick "German" for every storyboard and hit "Remove" in the pop-up, which removes the localizations in the list. This way changes to the storyboard affect the default language, which makes it easier to test changes.
I used version B:
Important:
These .strings files are only used for storyboards! If you also want to set localized text at runtime using NSLocalizedString (e.g. for an error dialog), then you have to add an additional Localizable.strings file (more details here):
File - New - File - Strings File - Call it Localizable.strings
Click "Localize" in its File Inspector and pick one of the languages you want to use in code.
Afterwards, also in the File Inspector, you can tick the other languages in the "Localization" section (including the development one).
Bonus infos:
You can change the app language of the simulator through the scheme:
Product - Scheme - Edit Scheme - Run (left side) - Options tab (right side) - App Language
You can also show a preview of the currently selected UIViewController and change its displayed language without starting a simulator:
Editor - Preview - In the new preview window on the right there's a button in the bottom right
Disclaimer: I found this solution by testing different things, as there's currently no tutorial for this (using the latest Xcode version). If this is not the "right" way to do localization, please post your own answer and I'll check it out.

Should I have Localizable.strings Base or English?

Following Ray Wenderlich tutorial (https://www.raywenderlich.com/180356/ios-internationalization), the Localizable.strings is as following. Notice there is no Localizable.strings(Base)
But in some other tutorials, they would use Base instead of English, so did I in my project as follow.
My iPhone's preferred language order is English then Chinese and is currently set to English. But whenever I run the app, it goes to Chinese except when I explicitly edit scheme to ask Xcode to run it in English. Does that mean I should have Localizable.strings (English) instead of Localizable.strings (Base)?
Another question, I have Main.storyboard (Base) and Main.strings (Chinese (Simplified)) under Main.storyboard. But no matter what I do, the storyboard always shows up in Chinese version. What have I done wrong?
=== Update ===
I played around with it (simply remove and recreate, nothing changed), and then magically the localization works as expected: The app default to English, which is my system language, and switches to Chinese when I edit scheme. However, now my storyboard is stuck with (Base) version no matter what I do.
I am no expert on this, but as I understand the Base file is a fallback if your app doesn't have a Localizable.strings file for the user's device language.
So if you have English and Chinese as localization files, but your preferred languages are German and Japanese, the system will check the Base file for strings.
In your case you have Chinese and the base files. English is not found, so it takes the other preferred language (Chinese). Therefore the base strings are not used -- the app defaults to the Chinese localization.
To solve the problem, you need to make an English strings file in addition to your base strings.

Localization and User-Facing Text in Storyboards

I am learning from the iOS 9 AppCoda book on Swift (https://www.appcoda.com/swift/) and I am stuck in particular on the Localization section. So the author has gone through with changing some user-facing strings in code from just String to NSLocalizedString. That makes sense and the changes I made there were automatically updated appropriately with the XLIFF file. In the section about Localisation, the author mentions that you can also translate Storyboard user-facing Strings with the Export Localization feature of Xcode.
Because it's a book you work through, he provides an already translated XLIFF file into Chinese and German which includes the source code translated text and the Storyboard elements translated as well.
When I import the files into Xcode, I see three storyboards (Base and the Chinese/German.strings, etc) but when I run the app, none of the Storyboard elements are actually translated and only the elements from the source code.
When I click on the German Storyboard, I get the "no localized strings".
The app in his example works and the UI elements in storyboard are translated but they're not in my case. The entire app thus far has been followed with the exercises so there aren't really any differences. Or even if there are, the similarities themselves should be translated, but in the Storyboard elements, they're not.
Does anyone have any ideas on why the Storyboard elements wouldn't be updated with the Translated text in my case?
Any thoughts would be appreciated.
Here is my guess... Exporting localization strings from Storyboards works a little different from exporting those strings from code.
The localization file for strings from code gets the actual text from the NSLocalizedString macro and creates a mapping such as:
"Original string" = "Translated string".
So, you just have to use "Original string" in your code then Xcode knows it should translate it to "Translated string".
However, the storyboard localisation file uses the UI objects handles to set localized strings. For example:
/* Class = "UILabel"; text = "Ops..."; ObjectID = "fe4-zT-gjU"; */
"fe4-zT-gjU.text" = "Wait for it...";
In this example my storyboard has a UILabel, with the text "Ops...", and that label has an ObjectID equal to "fe4-zT-gjU".
The object IDs are kinda unique for each object in each project, so obviously the object IDs from the app coda tutorial will be unique for the project the author created; unless you have downloaded the author's original storyboard, your storyboard will have all different object IDs, so Xcode won't know how to associate the correct translations to the correct objects.
I don't think Xcode will import localisation for objects with objectIDs it doesn't recognise.
So what I think you should do is to perform an "Export for localisation" operation. This should update your storyboard .strings file. Then you copy each translation from the tutorial file into your .strings file using an xliff editor. Boring, I know. Welcome to the app development world. :-)
When you added your localization did you select the storyboard file?
If so, then check that your scheme is set to the correct language. This can be done under Product > Scheme > Edit Scheme
If that doesn't do it, then check that your simulator is set to the language you want to display. This can be done in the simulator's settings, same as an iPhone.
Hope this helps.

Develop app in Japanese, add localization into English

I am developing an iOS app targeted almost exclusively at a Japanese audience, with the possibility of a small portion of english-speaking users.
All storyboards and xibs are being designed with Japanese strings, and localization into English should take place at a later stage.
From the beginning, the Project's Info/Localizations section in Xcode reads:
(The two files are, of course, "Main.storyboard" and "LaunchScreen.xib")
Because "English" is already added (as the development language), I can not click the "+" button and add it as a localization. I could add 'Japanese' instead, but I want it to be the Development Language, not just some (secondary) localization.
Also, and in an apparent contradiction with the above, The Target's Info.plist file reads:
When I select either of the localized files (Main.storyboard and LaunchScreen.xib) in the Project Navigator, and check the file inspector, the 'Localization' section reads:
...which seems to suggest that the existing, Japanese files (.xib and .storyboard) are the 'Base' and checking 'English' will add support for that language too (The pull-down menu seems to indicate that I can chose between using a strings file or a dedicated duplicate of the storyboard. I am inclined to believe the strings approach is better).
...So, how should I proceed?
A. Check the 'English' box in the File inspector / Localization section?
This creates an en.lproj folder and adds a strings file inside it that I should translate later, I guess. This effectively seems to treat my existing Interface Builder files (populated with Japanese labels) as 'Base', and provide for localization into English through the strings file created (if I understand correctly). However, English as the Development Language in the Project settings remains somehow unsettling...
B. Remove English and instead add Japanese in the Project/Info/Localizations pane?
This will make Japanese the Development Language, and I can re-add English as a localization afterwards. But for some reason, if I do this Japanese will not be treated as 'Base' language, and (unnecessary) string files will be also added for Japanese, not just for English.
EDIT: I found this question, which somehow provides a 'fix' for the option B above.
OK, this is what I settled for (but I will still accept better/smarter answers):
I did as suggested by the question I mentioned before, and edited the Xcode project file to force Japanese as the "Development Language":
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
becomes:
developmentRegion = Japanese;
hasScannedForEncodings = 0;
knownRegions = (
en,
ja,
Base,
Next, for the storyboards/xibs I want to localize, I will check the 'English' checkbox in the File inspector/Localization:
...and that will create my string files for English localization (Notice the 'Japanese' checkbox below 'English'. I'd rather it not be there at all, because the Base xibs/storyboards already have Japanese text labels by default, but I can just leave it unchecked).
Now, the Project's Info pane, 'Localizations' section looks like this:
ADDENDUM: Now that I think of it, with things setup like this, if someone ever launches this app on (say) an iPhone set to French, the app will fall back to Japanese (not English). This is probably not ideal, since the default language for non-Japanese speakers should be English, not the other way around.
However, I can not afford to design my xibs with English text and translate them to Japanese afterwards.

Localization of iOS application

I tried to Localized my app English to French but i've Trouble the problem,i Converted into Strings English to French Language here the Below Screen Shots About English And French.
French Language
but i didn't Get response in my app can you please suggest me,any changes....!
Finally I found the way to Localization.
Make the Localized Strings follow the Below Steps
First we select the language into editor area
2.then after we choose the different languages.
3.Next Click the Use Base INternationalization
Now,Click the Finish button.
4.The next step Localize the our Xib files like this
5.Then,covert to the Xib files to localizedStrings
finally get the Localized strings like
6.And add the one file into our project i.e
Click Next and Save the file name Localized.
7.Now Localized.Strings file add to localize languages
Final step is Go to Click the Product->Scheme->New Scheme
And Select the AppleLanguages
and what we want change language called like this code
Finally i found the how to Localization.

Resources