I followed various tutorials on "How To Localize an iOS(iPhone) App".
All of them were suggesting to perform following steps,
Select your project from Project Navigator
Click the checkbox for “Use Base Internationalization”
Select your storyboard to Localizable Strings
But my iOS application xcode 7.2 project does not include any storyboard,
so I am not able to enable “Use Base Internationalization” in my iOS application.
Please help me out how to enable “Use Base Internationalization” without storyboard selection and what should I do to perform various alert messages to be localized using "Localizable.strings" file.
Go to project->New Files->Resource-> String File-> Save it as Localizable.string
now
Now again go to project setting... then choose project instead of target in setting... Where you have only two options... Go in info section where you find localization... add your language here for localization.
created file is already in base Internationalization mode... now go to file and in side bar of right side check localize button... click on it and chooose language which you added in your project.
now this file add a dropdown in it.. click on arrow... which will show you localized file.string now first one is base english... which is default and second one localized string file...
copy all text which you hardcode in both file like this
Base File-> "Enter a keyword to search" = "Enter a keyword to search";
Localize file -> "Enter a keyword to search" = "Localized String";
now to use this localized string you can fetch strings like this
label.text = NSLocalizedString("your String",nil);
Note:- string file should have name "Localizable"... if you not save it with this name... this will not work.. and you have to provide path every time you use localized string
Thanks to Divyanshu Sharma.
Here is steps for Xcode 8 (Swift 3).
File > New > File... ( ⌘N )
Scroll to "Resource" section and choose "Strings File", press Next
Save it as "Localizable.string" in to your project
In Project Navigator select your new file "Localizable.string" (usually already selected after creating new file)
Go to View > Utilities > Show File Inspector (⌥⌘1)
Locate Localization section and select "Localize..."
Choose base language (I chose English), then click Localize
Open to Project Info settings and in
Press (+) to add new language in Localizations section
Select "Localizable.string" and press Finish in newly opened localizable resource selection window
Now you should have default localizations without Storyboards.
Related
I am trying to localize my application with out storyBoard in my native language urdu (Pakistan). I watch many videos and links.
I am trying follwing steps:
First Add the language
then make a new String File named Localizable.string
Go to View > Utilities > Show File Inspector (⌥⌘1)
Locate Localization section and select "Localize..."
Choose base language (I chose English), and click the required language and then click the localize.
After that go to "Editscheme" select the Application language, there is no option to select the urdu(Pakistan) language.
Some one says go to project.pbxpro file and make changes to it. I tried to make changes to the file but I can't succeed.
Totally confused. What can I do?
I suggest you to create the Localizable file first, then add the language. This is because you don't have a storyboard, Xcode might not know what you want to localize when you try to add the language in the project settings.
So,
create the Localizable.strings file first, press "Localize" and select "Base"
Go to project settings' Localization section:
Select the language:
Now select Localizable.strings file to localize (in the picture I have other files as well, but you should only have Localizable.strings)
Now you should have two Localizable.strings files, one says "Base", one says "Urdu (Pakistan)". Write your localizations in the corresponding files!
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 have searched related questions and tried many suggested methods but none seems to work.
I have a japanese-only App that when run on an english device gets UI items such as back buttons translated ("Back").
To achieve this I have:
Deleted the English from "Localizations" from my project and chose to delete localized files (was a single *.strings file).
Changed CFBundleDevelopmentRegion in my Info.plist from jp_JPto jp as I read it should match the name of the *.lproj folder.
Cleaned, deleted, closed Xcode, etc. But default UI items are still getting translated to english.
Also I get some weird behavior in Xcode 5 now:
Checking the "Use Base Internationalization" checkbook presents an empty "Choose files and reference language to create Base localization". Choosing either Cancel or Finish has no effect and nothing happens.
Clicking on the "+" button to add the Other > "Base (Base)" localization does nothing.
I thing that my problem seems to be that my Base localization is still somehow english but I can't find a way to change that. Any ideas?
I found that to truly remove English support I have to properly set the CFBundleDevelopmentRegion into a full valid region (e.g. ja_JP) and not just a language (just ja still resulted in English showing up).
When you have a valid region Xcode will show you the name of your country instead of the raw value in the Plist editor.
Seems like some modules, such as MFMailComposeViewController, get localized to English no matter what (tested on iOS 6 and 7).
I encountered the same issue. Here are the steps I did to get past them.
Localize your storyboard file.
Select your Storyboard file in Xcode.
In the “File Inspector”, under the “Localization” sub header, press the “Localize…” button.
A dialog appears that says “Do you want to localize this file? The file will be moved into the lproj folder for the following language.” It lists a language. For me it was “English” and I chose that. For you, I suspect it will be “Japanese”.
Press the “Localize” button.
If it warns you that your storyboard file has changed outside of the project, choose “Save anyway”. If you don't it deletes the storyboard from your project. This happened to me with a source controlled project, but not with a new empty project.
Go back to your project and check the “Use Base Internationalization” checkbox. Your storyboard should show up in the "Choose files and reference language to create Base localization" sheet.
If you go back to your storyboard, you will see “Base” as the checked localization. I had my language (English) show up as an option. When I checked it, a storyboard.strings file was created. Since my base was already in my preferred language, I didn’t need a strings file so I removed it. I presume that if I had another language, I could select that and get a storyboard.strings file for that language.
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?
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.
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.
In xcode 6, do the following:
With the command line, create the following directory/file structure somewhere outside your project directory:
/en.lproj/InfoPlist.strings
/en.lproj/Localizable.strings
In Xcode, open your project and choose File>Add Files to ProjectName to add the recently created en.lproj directory.
After that, you will see English in the Localizations list.
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!
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.
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.
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.
Additionally, 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 done
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.
I develop ios application (iPhone) in MonoTouch(5.2.12)/MonoDevelop(3.0.3.2)
I tried to localize it.
I created localization folders (de.lproj)(Add->New folder) and I placed 'Localizable.strings' file there. This file was added to project (Add->Add files ...).
Localization doesn't work.
I find out that localization files (Localizable.strings) don't locate in runtime place
(/user/jpa/Library/Application Support/iPhone Simulator/5.1/Applications/A99 ...B13/MyApp.app/de.lproj/), even though in MonoDevelop they are.
Why? What is wrong? File is UTF-8 coded. (It doesn't depict with UTF-16)
Thanks.
I believe you'll need to set the build action of your files to "Content" (right click file -> Build Action -> Content).
How do you call your Localized string ? Can you give us a piece of code ?
You don't need to create manually the localization folders, just:
create a Localizable.string file (Right click in project explorer then "New File")
select it
open the Xcode right panel (if not already open)
click on + in the Localization part, and select the language
This method will prevent from manipulation errors because Xcode create the localization folders itself.