There are a lot of posts on this but all seem to be an out of date method? It seems its done using info.plist and adding localization to it and then more info.plist files are created within for each language. It seems to be working but only ever displays the English Bundle display name no matter what system language I use. Not sure what else needs to be done. I checked it on both the simulator and a device.
you need to create "InfoPlist.strings" and add languages which you want to support there, then set your bundle name and display name as the following for each language
"CFBundleDisplayName" = "App Name";
"CFBundleName" = "App Name";
How to enable Localization and add more language to your project.
Choose your project on the tree.
Choose your project.
Info Tab -> Localizations.
Choose which language you want to support.
then on your strings file, when you choose it, on right side you can find which languages you want to support into this strings file.
Related
I need to set Spanish as development language for an iOS app. I'm already using Xcode 6, and I changed the Localization native development region entry in app's Info.plist (CFBundleDevelopmentRegion) from "en" to "es". However, in Project > Info > Localizations, English remains set as Development Language.
As said in Information Property List Key Reference, CFBundleDevelopmentRegion specifies the default language. I need to set Spanish to the default language, what am I missing?
Thanks
Here's how you can do this:
Add the language you want to be your Base language first. Uncheck all of the files that Xcode offers to localize for you.
In the Info.plist, change the development region to the language that you want to be your base language. Note that the property is a bit misnamed, because its value should be a language code (with an optional country code), rather than a region or country code.
Close your project in Xcode. In another code editor, open projectname.xcodeproj/project.pbxproj and search for developmentRegion. You should see a line like developmentRegion = English;. Change this to reference the same language you put in your Info.plist file.
Reopen the project in Xcode. Go through all your localizable files and check the boxes next to English to generate the localizable resources. Note that for storyboards and xibs, Xcode might create a storyboard instead of a strings file. If that happens, just change the filetype to strings file.
Here's an example of the result for me using fr as the Base language:
For Xcode 9 through 13:
Close Xcode.
Open your project.pbxproj in a text editor
Look for developmentRegion and set its value (es for spanish, fr for french,...)
Look for knownRegions and add the new language to the list
Open Xcode: Your project info should now show the language name with Development Language next to it.
In your project's .xcodeproj file, search for the string developmentRegion. Supposedly, it says "English" right now. If you change it to "Spanish", Xcode 6 should recognize Spanish as your project's default localization language in the "Info" tab as long as you add "Spanish" to the list.
You can read more about this topic at http://eschatologist.net/blog/?p=224
open your target -> info -> change "Localization native development region" to your language
Changing the default localization is now natively supported as of Xcode 14.3. It can be configured from the language menu in the project editor’s Info tab.
For someone that needs help like I did, I have two targets, one I want to be EN Base localization and second target I need to be another language.
The option mention above: "change projectname.xcodeproj/project.pbxproj and search for developmentRegion and change ..." doesn't work for me because of targets.
What worked for me, Xcode 11.5, is that only I need to change the language code in the "Localization native development region" for that particular target and it works, no need to change anything in projectname.xcodeproj/project.pbxproj
P.S.
Here "Localization native development region" must go country code like fr_Fr or in my case hr for Croatian
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!
As you might know the iOS 8 requires NSLocationWhenInUseUsageDescription key for using user's location. I have added this key and some general information into my info plist.
How can I use translation string inside the plist file ?
-- Update --
I already have a Localizable string. I'm just wondering that can I use something like
NSLocalizedString(MYSTRING,nil) inside the plist string. I know that I can create multiple file of info.plist for localisation but I was wondering there might be an easier way.
You should use InfoPlist.strings file (keep both I & P capital) to localize values of Info.plist. To do this, go to File->New->File, choose Strings File under Resource tab of iOS, name it InfoPlist, and create. Open and insert the Info.plist values you want to localize like:
NSLocationWhenInUseUsageDescription = "Description of this";
Now you can localize InfoPlist.strings file with translations.
Select the localization options, or enable localization if needed,
You should be able to see the file also on the left side editor.
NOTE: When testing the localizations on the simulator. You have to change the language on the simulator itself not just the language in the Xcode target. (Credits to John Webb)
Here is the official documentation for Info.plist keys localization.
Credits to Marco, thanks for including the pics in this answer!
All the above did not work for me (XCode 7.3) so I read Apple reference on how to do, and it is much simpler than described above. According to Apple:
Localized values are not stored in the Info.plist file itself.
Instead, you store the values for a particular localization in a
strings file with the name InfoPlist.strings. You place this file in
the same language-specific project directory that you use to store
other resources for the same localization.
Accordingly, I created a string file named InfoPlist.strings and placed it in the xx.lproj folder of the "xx" language (and added it to the project using File->Add Files to ...). That's it. No need for the key "Localized resources can be mixed" = YES, and no need for InfoPlist.strings in base.lproj or en.lproj.
The application uses the Info.plist key-value as the default value if it can not find a key in the language specific file. Thus, I put my English value in the Info.plist file and the translated one in the language specific file, tested and everything works.
In particular, there is no need to localize the InfoPlist.strings (which creates a version of the file in the base.lproj, en.lroj, and xx.lproj), and in my case going that way did not work.
Step by step localize Info.plist:
Find in the Xcode the folder Resources (is placed in root)
Select the folder Resources
Then press the main menu File->New->File...
Select in section "Resource" Strings File and press Next
Then in Save As field write InfoPlist ONLY ("I" (eye) capital and "P" capital - the l (ell) after the P should not be capital)
Then press Create
Then select the file InfoPlist.strings that created in Resources folder and press in the right menu the button "Localize"
Then you Select the Project from the Project Navigator and select the The project from project list
In the info tab at the bottom you can as many as language you want (There is in section Localizations)
The language you can see in Resources Folder
To localize the values ("key") from info.plist file you can open with a text editor and get all the keys you want to localize
You write any key as the example in any InfoPlist.strings like the above example
"NSLocationAlwaysAndWhenInUseUsageDescription"="blabla";
"NSLocationAlwaysUsageDescription"="blabla2";
That's all work and you have localize your info.plist file!
Tips
Remember that the iOS Simulator exploits by default your system language. Please change the language (and region) in the iOS Simulator Setting too in order to test your translations.
The localisation string (see Apple docs here) should be
NSLocationWhenInUseUsageDescription = "Description of this";
and not (with quote "...")
"NSLocationWhenInUseUsageDescription" = "Description of this";
If something is not working make sure you added:
"Localized resources can be mixed" = YES
into the info.plist. In my case the InfoPlist.strings files were just ignored.
I would highly recommend reading Apple's guides, and viewing the WWDC resources listed here:
Internationalization and Localization Topics
To specifically answer your question, when you add a new language to your project, you get an opportunity to choose what InfoPlist files to include (if you have multiple targets, you'll have multiple Info plist files). All you need to do to get the following screen is hit the + under Localizations and choose a new language to add support for.
Once you've added, it will create the necessary string files in the appropriate lproj directories for the given language.
--EDIT--
Just to be clear, iOS will swap out the string for your Plist file based upon the user's currently selected language using the plist entry's key as the key in the localized strings file.
For newer XCode 12 / 13 /...
1. Create a new InfoPlist.string file in your project.
2. Select your file, and you should see the right sidebar option "Localize"
3. If you want add more languages in your project's Info >> Localizations
It will create automatically a copy of your "InfoPlist.string" for the new languages you add.
For anyone experiencing the problem of the info.plist not being included when trying to add localizations, like in Xcode 9.
You need make the info.plist localiazble by going into it and clicking on the localize button in the file inspector, as shown below.
The info.plist will then be included in the file resources for when you go to add new Localizations.
In addition to the accepted answer (the project is on Flutter but it's basically the same as native):
I do have folders Base.lproj, en.lproj, xx.kproj. etc. with InfoPlist.strings in each.
This file has lines like this (no quotes around the key and with a semicolon at the end):
NSLocationWhenInUseUsageDescription = "My explanation why I need this";
Check that you have your languages in your YourProject > Info:
Also, check the project.pbxproj file, it is in XXX.xcodeproj/project.pbxproj:
it should have all your languages in codes (en, fr, etc.)
But even then it didn't work. Finally, I noticed the CFBundleLocalizations key in the Info.plist file. (to open it as raw key-values in XCode - right mouse button on the Info.plist file -> Open As -> Source Code)
Make sure that the values in array are codes rather than complete words, for example fr instead of French etc.
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>ru</string>
<string>lv</string>
</array>
And double-check that your device is set to the language you're testing. Cheers
P.S. "Development Language" doesn't affect your issue, don't bother changing it.
As RGML say, you can create an InfoPlist.strings, localize it then add your key and the value like this:
"NSLocationWhenInUseUsageDescription" = "Help To locate me!";
It will add the key to your info.plist for the specified language.
When using InfoPlist.strings file (in XCode it should be placed next to Info.plist file - real file location can be anywhere within the project probably
) be careful to use the key's short name for the translation.
I was trying to use Privacy - Camera Usage Description, but the working key is NSCameraUsageDescription
In my case everything was set up correctly but still the InfoPlist.strings file was not found.
The only thing that really worked was, to remove and add the InfoPlist.strings files again to the project.
In my case the localization not worked cause of '-' symbol in the name.
Example: "aero-Info.plist"
And localized files: "aero-InfoPlist.strings" and "aeroInfoPlist.strings" did not work.
iOS localize .plist
You can skip defining key into .plist if you set it in InfoPlist.string
.plist
InfoPlist.string
"NSPhotoLibraryAddUsageDescription" = "You need to allow access to the photo library to download image";
In my iOS project, I am having multiple targets for building several slightly different apps. It is required for each app to have its own localised name. How can I achieve this? I have tried to localise the Info.plist but failed.
You can go to 'Build Settings' and pick the name of your Info.plist File (INFOPLIST_FILE) for each target, independently.
You can also use different InfoPlist.strings.
Use InfoPlist.strings in your xx.lproj (for example en.lproj)
Add the following line in InfoPlist.strings:
/* Application Name on the Springboard */
"CFBundleDisplayName" = "my app";
To localize the value of an Info.plist key we need to add an InfoPlist.strings file to the project. We can do that in the usual way by right-clicking on the Resources group and selecting “Add -> New File…” and choosing the Strings file template from Resource section. Give the new file the name InfoPlist.strings and ensure it is added to the current target:
Before we localise the file we can add the default values for the English locale. We will add values for both the CFBundleDisplayName and CFBundleName keys though for iOS the important one is the bundle display name:
"CFBundleDisplayName" = "Hello";
"CFBundleName" = "Hello";
To localise the file, click on it at the "Identity and Type” panel and click the “Localize..” button, after that you can add the localisation language you want as below:
For different targets, remember not change the file name of "InfoPlist.strings", still use the same name for all the targets, but put them to different folders.
I'm trying to add a localization. I've read all those localization/internationalization guides from Apple and raywenderlich.com. I've marked all my code with NSLocalizedString macro, I've used genstrings to create Localizable.strings. But somehow I'm missing some important step.
When I try to add localization to my Localizable.strings I'm somehow restricted to English only.
When I try to add localization to project via "Editor"->"Add Localization" all language options are disabled.
Does anybody have any thoughts as to why am I restricted to English only? What have I missed?
I've tried to add localization to other projects with the same result. :(
You need to first add your localizations to your project. Click on the project file, ensure that the project, not the target, is selected in the middle pane and then choose the "Info" screen. There's a area called "Localizations" where you can add languages. You should then be able to localize your resources.
Another possible issue is that you are not selecting appropriately the project, which leads to all languages in the Add localization list being disabled.
By default the target may be selected, make sure you select the project instead. Then you can use the Add localization normally.
Something which kept me busy for too long. I looked over the language I needed (Swedish) in the first list and took the one from the "Other" list. Well my phone or emulator didn't change at all to Swedish. But when I took Swedish from the first list it got nicely updated when changing the language settings.
With Xcode 6, you can do it via Project Settings.