28
votes

I deleted the Localizations of the project from the project's info by mistake. Both the storyboard and the related language were removed.

I got back the storyboard from previous file but when I want to add a new Localization, a window popped out and asked me to "Choose files and reference language to create English localization" and there is no resource file at all.

How can I add back the localizations?

6
Did you ever find a solution for this? I got the exact same problem today and had to use git to save me :)Lasse Christiansen
@LasseChristiansen-sw_lasse Check my answer.Cameron Lowell Palmer
i had some problem this me and may help you : stackoverflow.com/questions/25948181/…Saeid

6 Answers

48
votes

Adding back a localization

When you delete your localizations sometimes you can get that situation where you can't add back any localizations in Xcode. Go to the command-line and create a ISO 639-1 two-letter language abbreviation folder with the lproj extension somewhere within your project.

Create an empty language folder

For example:

${SRCROOT}/Resources/Translations/nb.lproj

or

${SRCROOT}/Resources/Translations/en.lproj

Re-add language files to project

In the folder create an empty file called Localizable.strings and add this file to your project. Don't add the .lproj folder, just the contents. Then when you go back into the project file you will see the language under localizations. Now when you have added this, you should see the localization in your project.

No checkbox

If the added file, like a storyboard, doesn't have a checkbox next to it indicating that is part of that language localization you might need to round trip them through another language. To do this add a new language in the project. It should prompt you to copy the existing localized files over to the new language. Then delete the broken localization and re-add it.

My Example

As a specific example, I added the storyboard in the nb.lproj directory to the project. The Norwegian Bokmål appears in the project, but the checkbox for the language in the storyboard inspector won't let me add it. I created nb_NO in the project and it prompted me to copy over the storyboard. Then the storyboard had that checkbox checked. I deleted the 'nb' localization and re-added it. Now everything was the way I wanted it.

5
votes

I had to solve same problem, and found one solution:

You need to find in finder your *.xcodeproj file and open it as container (ctrl+click on it and you will see it in context menu)

Here you can see project.pbxproj file, open it in Xcode. Its large (but still readable file). (it will be better to make some copy on save spot, before you start)

Now its the task to add the missing language to this file, and its done.(U can try it on other project with localizations).

There is paragraph you need to add. Search in this file for this /* End PBXSourcesBuildPhase section */(its paragraph right before localization paragraph which is missing) and add something like this after:

/* Begin PBXVariantGroup section */
        27548D921611B0BE008EA1CD /* Localizable.strings */ = {
            isa = PBXVariantGroup;
            children = (
                27548D941611B0BE008EA1CD /* en */,
            );
            name = Localizable.strings;
            path = ../Code;
            sourceTree = "<group>";
        };
/* End PBXVariantGroup section */

You have to do some changes first. Look at the long number 27548D921611B0BE008EA1CD, its ID of the localization file (or some xib file, or other localizable file...), if you dont have any in the procject, just add some Localizable.string file to the project, reopen(or refresh) this project.pbxpro, and find this Localizable.string you should find something like this:

275490591611B0BE008EA1CD /* Localizable.strings in Resources */

and this is it what you need to replace in localization paragraph

also you need to do right settings on path parametr and sourceTree. This twos are readable in fileinspector in xcode.

The "sourceTree" param is Location - mostly its relative to group so sourceTree = "<group>";

The path is path relative from the group to the file (if you dont know, try to make some localization files in different project and look at project.pbxpro, what all this works)

After this you can save project.pbxpro, and you should see in xcode info section "en" localization and you can add more localizations and all other localization stuff.

4
votes

In xcode 6, do the following:

  1. With the command line, create the following directory/file structure somewhere outside your project directory:

    • /en.lproj/InfoPlist.strings

    • /en.lproj/Localizable.strings

  2. In Xcode, open your project and choose File>Add Files to ProjectName to add the recently created en.lproj directory.

  3. After that, you will see English in the Localizations list.
1
votes

This is an old topic, but after having this issue, and then trying the solution (and having it not work exactly), I thought I'd give details on what DID work.

Like the original poster, I accidentally deleted all of my localizations and was given no obvious recourse in Xcode-- in the project settings under Info it simply said 'this project has not been localized', and when I clicked on the plus button beneath, a blank list of resource files was presented.

I followed @Cameron's guide but found that language folders with Localizable.strings files were already present in Finder, but weren't being acknowledged by Xcode. I couldn't decide how to proceed, but I happened to see an unrelated comment about adding files to Xcode, so I tried adding the existing en.lproj folder and its Localizable.strings file.

This worked, and the listing for English as the development language appeared under Info as well.

Hopefully this will help anyone who experiences the same problem!

1
votes

Simply create a Folder "Base.lproj" in finder and paste the Xib you want to localize inside it, and add this folder to your project. Now you can able to add other languages without issue.

1
votes

I've followed a similar approach of @user2070775 reply.

Firstyl when you delete Storyboard and Launchscreen to use your own creation or code programmatically, on Localization you might get similar following empty screen.

enter image description here

Then firstly you should know the language code for example to use French localization its fr etc

With project folder in the Project Navigator you must add New Group -> {LANGUAGE_CODE}.lproj. And then you should add New File -> Strings File -> Localizable.strings. In the @user2070775 answer, also InfoPlist.strings file has added so I added too for now.

In the Localizable.strings file you can add <KEY> = <VALUE> pairs for string to localizated.

Our pair is "this-is-key" = "and-this-is-value-for-spesific-language-on-localizable-string"; for now.

HINT: In key-value pair, when I did not put the semicolon, the XCode gives error for this situation.

Until now, the following project scheme, must the result of you have.

enter image description here

enter image description hereAdditionally, when you looked at the Project -> Info -> Localizations the French or etc. language must be added like in the following image.

TESTING

Basically you can get the results of the what've you doneenter image description here

The remaining part can be set from the Simulator. You must change the simulator language, for this answer the correct one is French.

Go to Settings -> General -> Language & Region -> French and run the project again.