I use several storyboards and I have just decided to localize them (.strings files have been generated by Xcode).
I notice that in the Build Phases > Copy Bundle Resources, all resources related to localization appear in red.
At run time, localization works only on the main storyboard. Localization with Localizable.strings also works. But it doesn't on the other storyboards.
I tried to restart Xcode but it didn't change anything. (cf Base internationalization and multiple storyboard not working right)
My localized storyboards were previously compiled. I f I add another storyboard, localize it and lauch the compilation, it fails with this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Maintenance' in bundle NSBundle (...)
Do you have any idea to solve this issue?
This error is probably due to the fact that you didn't implement one of more languages you chose to localize in your application settings.
In order to implement a language in a storyboard :
Select the storyboard
On the right panel, go to the File inspector tab (first from the left)
In Localization, check all language(s)
You now have two ways to localize your storyboard :
Either you choose to create a .strings file for your language by choosing Localizable Strings, this will generate a list of strings xcode found in your storyboard.
Or you can choose to create a "sub"-storyboard by choosing Interface Builder Cocoa Touch Storyboard which creates a different version of your storyboard for a particular language.
So far I only found one way to refresh the .strings file in xcode if you add new strings : simply uncheck and recheck the language and select "Replace File" when asked. Apple also provides a tool you can use in the terminal. Finally there's a script that does it automatically.
Open the storyboard file
See the right panel, on first tab (identity) on the localization section, uncheck "Base"
You should be prompted a dialog, no matter the answer the problem should be fixed.
Now you see that the Build Phases is correct, and you should be able to run your project.
One of the reasons for the red Localizable.strings or other Localization-files which can't be copied in the 'Copy Bundle Resources' can be the setting for the 'Localization native development region' in your Target settings.
This region should be added to the 'Localizations' of your project.
I.e. if the 'Localization native development region' is 'en', then 'English' should be added as Localization in your project settings.
Related
How can I use container apps localized strings from shared extension in Swift. I have already added containers strings files into extension -> build phase -> compile sources but its still not working. Should I set anything in configuration? From main container app strings are translated but from shared extension it shows only the string keys/ids for texts.
You need to change target membership of the Localizable.strings file. Select Localizable.strings in the Project Navigator on the left, then open File Inspector on the right and add checkmark next to your extension target in the "Target Membership" field.
There are a couple things to check:
One is the solution offered here by #ovejka - click on your string
localization file and ensure, in the rightside settings pane, that
the file applies to your widget as well as your main app (target
membership).
Another is to ensure that your storyboard strings file, which should
have been created automatically when you added a second language to
your app, has the proper translations.
If neither of those work, given that a widget is quite small and
likely only has few labels, you could add a switch statement to 'viewWillAppear' to translate each label based on the detected language
Finally, none of those seemed to be working for me in the simulator or even by switching the schema language and running it on my actual phone.
It turns out, it was working all along and the simulated language wasn't applying to the widget. I turned my actual phone's language to Spanish, run the new version of my app, and the widget was translated.
I have a project with 3 targets. Each target needs to suppport only one language, but the language is not the same for each target.
Currently I have
Target 1 (es)
Target 2 (es)
Target 3 (pt)
Most of my strings are in a Localizable.strings file, and I simply target a different file for each target. However, a number of strings are in my storyboards. My problem is that it does not seem possible to create different storyboard localization files for each target. If I change the targeting of the portuguese file, the targeting of the spanish file changes automatically.
A possible solution is to duplicate each Storyboard for each target, but this won't scale well as the number of tagets grow. I could also modify all the text with NSLocalizedString in each ViewController, but this seems tedious and error prone.
Is there a better solution?
Shared Storyboard across targets
While this answer is the preferred approach, you can assign different Storyboard localizations to different targets, while sharing the same Storyboard across all targets.
Prerequisites:
Follow this instructions in this answer.
Concept:
You want to have the Main.storyboard in each target, but a different Main.strings in each target. Additionally, you do not want all localizations to be available in each target.
To achieve this, you must manipulate the .lproj directly, a process which is hidden when merely using the File Inspector.
Step by step:
Create all the pieces by following the steps in this answer.
From any target, remove the Main.storyboard. Of course, select Remove Reference to keep the storyboard around.
In the Finder, locate Base.lproj. Drag and drop Main.storyboard back to your project, and select every target.
In the File Inspector, ensure that the languages are not selected, and that you are still using Localizable Strings.
In the Finder again, locate en.lproj, es.lproj, fr.lproj, etc. Notice that they each contain a version of Main.strings. Drag these .lproj (the entire directories) back into your project. This time, do not select any target
One last time, in File inspector, associate each Main.strings to the desired target. Repeat for each .strings.
Conclusion
By decoupling the .lproj from the .storyboard in the Project Navigator, you can associate files and targets freely.
Demo:
See it at work using a French target, on a device with language set to Français in the Settings:
► Find this solution on GitHub and additional details on Swift Recipes.
Shared localizations across targets
Assuming you already have multiple languages in your project, in the Project Navigator, select your storyboard (say Main.storyboard)
In the File Inspector, under Localization, add English. Pick Localizable Strings which is the default. This will create a Main.string for each language, and share your Storyboard across all languages.
Merely clicking that checkbox in step 2. will add a Main.string (English) for that language, specifically for that Main.Storyboard. Pay special attention to the new hierarchy, these are not Localizable.strings but Main.strings, derived from Main.storyboard:
Localize in each language file to your heart content.
For example, starting with a UILabel which message was in Esperanto, it will appear in English when the device runs in English:
/* Class = "UILabel"; text = "Tiu mesaĝo estas en Esperanto"; ObjectID = "acC-pA-eMt"; */
"acC-pA-eMt.text" = "This message is in English";
Start here to add multiple languages to your project:
In the event you need to add more languages, follow these steps:
In the Project Navigator, select your Project
In the Project and Target List, select, once again, the Project
Select the Info tab
Under Localizations, keep Use Base Internationalization (unless your UI itself must change across languages)
Click +, pick a new language. In the dialog presented to you, select every Storyboard you want to have multiple localizations for.
If you missed Storyboards at Step 5. you can simply add a new language to that a storyboard by following the steps in Assuming you already have multiple languages.
All you need: to make common xcode workspace for your app, then to create a duplicates of main xcodeproj file for your set of languages and make different targets for all of them, also then you can set language for individual project settings in new xcodeproj's. Also you easy can tune build phase 'Copy Bundle Resourses' and others. I use this method. If you have a Xcode's crash during adding project in workspace - open project with Xcode, rename it and rename or duplicate targets (I think same names cause this issue).
I'm trying to localize an iOS app. According to all the tutorials, one of the first steps is to add localizations to the info pane of the project editor. When I get there, "use base internationalization" isn't checked by default. When I click it, the window "choose files and reference language..." comes up as expected, but it doesn't list any files--i.e. there are no choices for files to localize.
The app builds/runs fine. My storyboard is named "main.storyboard" and is in the project's main folder, so I'm not sure why xCode wouldn't recognize the file.
Of note, the project has gone through a re-naming, and I've been through a couple abortive attempts to localize after adding a language without the base, with the idea of adding the base later. But it looks like that takes me off track, and I had to undo those attempts; in the process, I manually deleted the .lproj folders that had been created.
Any ideas on what the problem is?
Important: Before you do any actions, keep backup of your project folder.
When you select use base internationalization, Xcode will look for User Interface files (Storyboard, Xibs) inside any *.lproj folders in your project. But in your case it won't find any *.lproj folder.
Steps to fix:
Create a "en.lproj" folder next to the storyboard using the Finder.
Then move one UI file like the main.storyboard (or other UI file) into the new folder.
On Xcode, relocate the storyboard file. One way to do it is to remove the old reference to the storyboard file. (will be in red) and re-add it to Xcode.
Now you will see that this file has "English" localization selected.
Retry now the 'use base internationalization' button and it should suggest you to move the main.storyboard to the Base.lproj which it will create for you.
I've been working on a application for a long time now and out from the blue i got this:
"Could not find a storyboard named 'MainStoryboard' in bundle
NSBundle"
I've red the similar questions here on StackOverflow and i tried everything including:
- Renaming the storyboard file
- Re-adding the storyboard file
- Cleaned the project
- Reset contents and setting on the simulator
I've also checked the plist file and the Copy Bundle Resources and the storyboard name is as it should be. Nothing of this works.
I'm developing the application with a friend and we are using Git. The weird thing is that the same version works just fine for him.
However, in the Copy Bundle Resources the MainStoryboard.storyboard and InfoPlist.strings are red. But they have been red for a long time without any troubles. And my friend (for which the project works fine) they are also red.
Ideas?
I would suggest to check that this file is not localized (with no actual localization), to remove the localization and to re-add the file.
If this does not work, have you tried to clone a fresh copy of the project from Git?
Select the MainStoryboard.storyboard, from under the project, located in the left panel of the XCode
Click the File inspector, on the right side of the XCode.
Check the box for Project Target under Target Membership.
Do the same for infoplist.strings
Clean the project and run it.
OR
Remove the files from Copy Bundle Resources
Add those two file by clicking + sign.
Clean the project and run it.
For what it's worth, I've just had this problem with a fresh project in Xcode 5, trying to set the deployment target back to 5.0.
The empty Utility Application would start up fine on simulator on iOS 6+, but would crash with above warning on iOS 5.0/5.1.
Selecting the storyboard in the Project Navigator and File Inspector tab, I found the 'English' icon was plain and unchecked. I checked it:
then clicked on 'Localizable strings', whence I got an alert:
After converting, File Inspector looks like this:
and the app no longer crashes. The Project Navigator now shows both Base and English storyboards:
I will leave to someone more knowledgeable to explain what's going on here and what are the consequences of losing the 'Localizable strings' in favour of a proliferation of storyboards...
Go to build phases in your app.
click on 'Copy Bundle Resources'
Find your main storyboard file if not than click on '+' icon in bottom and add your main storyboard file to it.
Now run the project again.
In Bombr 1.2 I added a half-assed French localization, over time adding more strings to localize I've decided to drop the French localization. In Bombr 1.2.1 I removed the reference to fr.lproj/Localizable.strings from the Xcode project but the file still exists. Now that 1.2.1 is on the app store it still says that French is a supported language.
Will removing the fr.lproj folder and resubmitting correctly display the supported languages (this is my hunch), or is it possibly that iTunes Connect will not allow you to drop support for a language?
(I took a year of French in high school for fun, but not enough to translate my own app.)
Building on the answer given by #vanya, select your project from the list and delete the language under in the "localization" section.
If you want to remove app metadata localization, there's a delete menu on iTunesConnect
try to look at the info.plist which defines localizations and I guess some work in iTunesConnect should be done as well, but before approving an app
To remove the localization from Xcode (I'm using 4.2 on Snow Leopard) click on the file/folder in the sidebar, "Localizable.strings" and open the File Inspector (keyboard shortcut cmd-opt-1 or View > Utilities > Show File Inspector in the menu bar). You'll see a Localization pane with your localizations listed. Select the one you want to remove and click the minus sign to delete it.
So I landed on this question, but with some specific criteria:
I want to remove the base development language (English)
I want to keep the localized language (French)
None of the above answers worked and I couldn't find anything better on Stack Overflow. Eventually I found this gem: XCode: Remove localizations on build.
I develop in English, so the entire base of the app is in the English localisation. I then translated it into Finnish for the first release, but the intention was to only release the Finnish content and not the English.
Setting up a small script during a final Build phase works wonders to strip unwanted localisations:
#Remove english
rm -r "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/en.lproj"
# Remove base (iOS 9)
rm -r "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Base.lproj"
Then I had some runtime errors because some Storyboard files were localized and located in the Base.lproj folder. I worked around this by doing the following:
Un-localized those Storyboards (unchecked all languages) and then "Moved to trash"
Dragged the Storyboards from the trash back into the project. (Basically moving the Storyboards from Base.lproj folder – which the script would delete – to the project folder.)
Note: none of these Storyboards were actually localized (the .strings files were all empty). All the translations were properly set in code using NSLocalizedString.