How to rename infoplist.strings file? [duplicate] - cocoa-touch

This question already has an answer here:
XCode - Multiple targets, Multiple *internationalized* names?
(1 answer)
Closed 2 years ago.
Is it possible to use other names for infoplist.strings file?
My problem: I want to create more than one target with different localized app names.

You just create localized version of the same file. And in there you set the name for each language for CFBundleDisplayName.
For example:
In the english file:
CFBundleDisplayName = "English name of the app"
In the French file:
CFBundleDisplayName = "French name of the app"
iOS will load the proper localization file. And if a language is missing it will use the default language in the info.plist. In my case, it en.

I've had what sounds like the same issue. I'm building two different apps from the same files, just with two different XCode projects, but the InfoPlist.strings files need to be different as they contain the name of the app. A simple solution I found is to use two separate folders inside of which your localized infoplist.strings are. For example:
+Version_A
+en.lproj
InfoPlist.strings
+fr.lproj
InfoPlist.strings
+Version_B
+en.lproj
InfoPlist.strings
+fr.lproj
InfoPlist.strings
Then in each XCode project you simply include the one relevant location (Version_A or Version_B) and not the other. If you do that too, check that the Copy Bundle Resources under your Build Phases pick the correct version (you can click Show in Finder from there).

You could use
NSLocalizedStringFromTable(#"key", #"myStringsFile", #"comment");
where you can specify the name of the .strings file which you can then make dependent on the target.

Related

How to add Objective-C Bridging Header entry?

I have a Swift project and have add a cocoapod, which is written in Objective-C. It has header and implementation files. From what I understand, to use/import these files into my Swift files, I need to add a bridging file.
I found this site describing how to do this manually, since the Objective-C files are already part of my project (from the cocoapod).
http://www.learnswiftonline.com/getting-started/adding-swift-bridging-header/
1.) Navigate to your project build settings and find the “Swift Compiler – Code Generation” section. You may find it faster to type in “Swift Compiler” into the search box to narrow down the results.
2.) Next to “Objective-C Bridging Header” you will need to add the name/path of your header file. If your file resides in your project’s root folder simply put the name of the header file there.
I don't have a Objective-C Bridging Header in that section and it doesn't appear you can add new entries there.
I'm using Xcode 7.3.1. Anyone have some idea how this should be done?
Are you sure you looked at the correct Build Settings section, search with the keyword Swift compiler - General in the search field as describe below and then you can find it.
You need to create the header file first. It is a regular Objective-C header file and should be named <Your app or framework name>-Bridging-Header.h. For any Objective-C headers you want Swift to know about add an import statement to the newly created header file. Then follow your previous steps.
There is also a hidden header that gets created for you called <Your app or framework name>-Swift.h. If you need to access any Swift classes from an Objective-C file import this header.

how to localize iOS 8 today extensions widget and also the widget name

I can't understand how I can localize today extensions, I want to create the Localize.strings file like a normal xcode project that for example have this string:
.en
"Apple" = "Apple"
.it
"Apple" = "Mela"
and I also want to know how I can localize the iOS 8 Today Extensions widget name.
I have tried to create a Strings File in Xcode, and I have tried to insert this:
"CFBundleDisplayName" = "App Name";
but the name doesn't change...
Add LSHasLocalizedDisplayName = YES to Info.plist file and add your localizations to InfoPlist.strings which you have to place under the language.proj folder per languages, for example de.lproj for German versions.
Before testing:
- Clean the project
- Remove the application from the simulator.
- Add language.proj folder references to extension's Supporting files part - to include them inside Copy bundle resources section in Build Phases of your extension target.
For strings in your containing app and Today Widget can share the same localization files. You can simply select Localizable.string, and in the File inspector check your today widget target in Target Membership. Then all your NSLocalizedString in the today widget share the same one with the containing localization strings.
For the today widget application name, then just add an InfoPlist.strings file, and
"CFBundleDisplayName" = "Translated Name";
"CFBundleName" = "Translated Name";
Just run your containing app for testing.

XCode warning - duplicate CMakeLists.txt while trying to change project name

I tried to change the name of my xcode project, (which uses the cocos2d framework), but for some reason my main files folder (the one that contains all the .h and .mm files) wouldn't change the name. so then i manually clicked under "MyProj TARGETS -> Build Settings" and manually changed the fields:
Info.plist File
Header Search Paths
User Header Search Paths
Prefix Header
to be using "MyProj/" instead of "PrevName/" (the previous name i had named the project) but now i'm getting these two strange warnings:
Warning: Multiple build commands for output file /Users/me/Library/Developer/Xcode/DerivedData/MyProj-fzlkaghtvjzkgkenbpejhzwvxsft/Build/Products/Debug-iphonesimulator/MyProj.app/CMakeLists.txt
Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'MyProj/Resources/Info.plist'.
you'll see that this is also mentioned under: http://www.cocos2d-iphone.org/forum/topic/33245 but no one has answered this part
and i tried to look under Xcode warning: "Multiple build commands for output file" to see under "Build Phases -> Copy Bundle Resource"... and indeed, there were 2 CMakeLists.txt files. one is:
MyProj/libs/Box2D
and the other is:
MyProj/libs/kazmath/src
which one do i need? or do i need both, since i think xcode used to be compiling with both??
i should mention that my project seems to be running okay right now if i leave the warnings in. but i don't like warnings that i don't understand, and i know that i could just swap my source/assets to a new project to get rid of the warning, but i'd like to know for future reference how to properly rename everything in a xcode project.
Thanks
Oh wow... I had no idea the traffic on stackoverflow is so low these days...(or at least for xcode & iOS dev) sighs
Anyways, I think I figured out a fix.
I read apple developer guilde for the second Warning
For the first Warning, I looked at another file that I had created, and I compared my project's settings to the other project's settings. (such a simple solution, duh, why didn't I think of this >_<) and it turns out, under Copy Bundle Resources, you're only supposed to have:
Your .png files and other resources used in code (but NOT your plist file, for the very reason given in the link above)
iTunesArtwork
ChangeLog
Actually, i'm not sure if you even need #2 or #3. I'll give an upvote to whoever experiments with it. So.... the solution is to simply remove all those other CMakeLists and cmakes and all that junk, including plist :)

Include issue: header file not found in iOS project in Xcode 4

Consider my setup looks like this:
XCode 4 iphone/ipad project
ObjC .m file that includes a new header file, this header is reported as "file not found"
ObjC .m file is located in root folder of the project
new header file is also located in root folder of the project
new header file was created within Xcode 4 as "C header file" (!!)
I tried using #import and #include statements with both "" and <> lookup syntax.
The project already consists of a bunch of other objC headers/classes and they work nicely. I suspect that creating the file as a C-style header is the issue.
I did explicitly NOT try to add a USER_PATH or anything like that, since it's all happening in the root project folder.
Any ideas? I'm really surprised how complicated such simple things can get!
! Additional comment: (EDIT)
I now verified that I can create any type of header (menu "new file"->"C/C++"->"header") and it will never be found by objective-C code. Even a new clean project behaves the same! What kind of feature is this?
Weirdness.
I talked to a bunch of fellow Xcode sufferers and they confirmed I HAVE to set the extra path variable. Their explanation was a bit odd though: in objectiveC the lookup (import) simply scans the whole subfolder structure, whereas an 'include' does not. From my point of view this would only be a valid argument if the header file in question was located in a subfolder! But mine is in the exact same location as the '.m' file!

.lproj and Localizable.strings : project with localized text?

i was reading the doc about localization and internationalization , but it's not really clear for me : can you explain me the link between the .lproj files, and/or the Localizable.strings file (if those are connected) ?
Or by any chance, if you know where i could see/download an example of an app using localized text?
I've seen the Localizable.strings file with the sample code 'NavBar' (from the doc), but nothing yet about a sample code using .lproj files.
Thanks for your help
It's very simple: create a folder for each localization, with the localization name followed by ".lproj", there you put any localizable file (you can also localize images) and your Localizable.strings (which contains the text returned by the obj-c API for localization). Don't forget to add the files in your resources, in Xcode.
For exemple, if you have 3 localizations, you could have this structure:
PROJECT_DIR/
- en.lproj/
Localizable.strings
- it.lproj/
Localizable.strings
- pt.lproj/
Localizable.strings
en.lproj/Localizable.strings have the english strings, and so on. Add the three Localizable.strings on your Xcode (it will be smart enough to group then) and it's done.
To use the localized strings just call NSLocalizedString(NSString *key, NSString *comment), it will automatically look for the key in your Localizable.strings file for the current locale and return the value associated with the key. For more information about NSLocalizedString see NSLocalizedString.