Change a localized InfoPlist.strings using an Xcode target - iphone

Here's an obscure problem. I'm using an InfoPlist.strings to localize my app name. It's only got one value: CFBundleDisplayName = "Mon App". The strings file is localized (putting it in a directory for that localization).
I've just made an extra target, where I change things like the non-localized app name (different Info.plists), and the icon. I'm also changing the Default.png using a run script build phase (copying different files depending on the app type I'm building).
I've tried using the script to copy different versions of my InfoPlist.strings, but I couldn't make it work. Here's what I used:
if($TARGET_NAME == "MonApp")then
cp fr.lproj/MonApp_InfoPlist.strings fr.lproj/InfoPlist.strings
endif
I've seen a post suggesting wincent strings util for processing strings, but wanted to see if there's an easy way to do this. Any help greatly appreciated.

You don't need to do this.
If you have fr.lprog/InfoPlist.strings and en.lproj/InfoPlist.strings in your project, you should see just one InfoPlist.strings entry, with two subitems fr and en. If you drag and drop the InfoPlist.strings file into a Copy Bundle Resources build phase, all localized versions will be copied into the appropriate .lproj files at build time. You don't need to create a separate target or write a script to do this; the right thing happens.

Related

where in an XCode project does it set "InfoPlist.strings" as the filename to use for locationalization?

where in an XCode project does it set "InfoPlist.strings" as the filename to use for locationalization?
Just trying to understand how XCode pulls things together here. For example to set the app name specifically I can change this in "AppName_plist-Info.plist", however if I go localization it seems it then has to be set via the "InfoPlist.strings" files.
I can see in XCode where it specifies the "AppName_plist-Info.plist" file name, in the Target/BuildSettings/Packaging information area, but I don't see mention of "InfoPlist.strings", so how does Xcode/IOS know to override what is in "AppName_plist-Info.plist" based on what's in "InfoPlist.strings"?
Xcode doesn't really override the name, it creates localizations in your apps bundle. iOS will look for the name of the app in de localization folder to which the language of the system is set.
These files have pre-determent names, thus you can not set them.
All the localized files will be for example in bundle.app\en.lproj for english or bundle.app\nl.lprojfor dutch.

how to copy property list file and its localized version to documents folder and make the system recognize the two version for a loclized application

i make a localized iphone application and in run time i want to modify the property list, so i at the first run of the application i copied the plist file but i don't sure if the copy operation also copied the localized version which the system store in a folder like: lp.fr
my quetion is: what i must do for the system to recognise the two files? should i make two directory in documents folder like lp.en and lp.fr and copy the two files?
also also xcode make the two plist with the same name, how i can determine every version and copy it?
i am waiting for some one to direct me to write way.
thanks
Take a look at NSBundle's pathForResource:ofType. It clearly states that it will return a non localized file if it exists or else pick a file in the order of user's language preferences. As you wan't to copy a localized resource, don't create a non localized copy and this will return the path for the most suitable resource. You can just copy that file and make changes to it.
If you are interested in getting the path to a resource of a specific language, take a look at pathForResource:ofType:inDirectory:forLocalization.

iPhone wrong Localizable.strings used

I have a project with different Localizable.string files:
../en-GB.lproj
/Localizable.strings
../en-US.lproj
/Localizable.strings
../fr-FR.lproj
/Localizable.strings
../fr-CH.lproj
/Localizable.strings
etc... with about 10 different languages. All are UTF16 encoded. I use XCode4. When I configure my test iPod in fr-FR and launch my app the line:
NSLog(#"Current Locale: %#", [[NSLocale currentLocale] localeIdentifier]);
returns: Current Locale: fr_FR
But all my NSLocalizedString(#"my_string",nil) always return the values located in my Portugese localizable. Any clue for that problem?
Not sure if this applies to you, but i have noticed similar problems using ShareKit. It wasn't ShareKit's problem per se, but the problem involved localizable.strings files inside the library that overlapped mine (for example, I had 2 localizable.strings for the english language. One was mine, the other one was for sharekit).
The app was running, and was finding it difficult to decide which of the two localizable.strings file should it choose to draw strings from.
The solution was transferring all strings in one file end deleting the duplicate files, of course.
I hope I helped.
Firstly check your Scheme Options. You might have changed the "Application Region" which in above case maybe set to "Portugal". This should be set to "System Region" and "Application Language" to "System Language"
Make sure that you're dragging the localized files to their right folder. It's pretty easy to put in the wrong place.
Have a look here for the complete list of what you should do, including screenshots of where you should drag the translations in the project tree:
http://www.icanlocalize.com/site/tutorials/iphone-applications-localization-guide/
Try doing a clean and remove the app off the device/simulator and rebuild/deploy.
I have run into issues when adding new localisations and the device caching the app resources.
Also when I localise I tend to use the country code as the name for the .lproj folder eg.:
en.lproj
fr.lproj

Bundle Display Name in iPhone

Is it possible to modify the BundleDisplay name at runtime ???
Thanks
I'd be really surprised if you could, since doing so would require you to edit the Info.plist file, which is in a write-protected directory. Even if you could modify it, it would cause the code signature to no longer match the application bundle, and the app would refuse to launch.
The closest you can get to using a different display name is to provide localized versions of it.
If you set the Bundle Display Name to a variable ie ${MY_BUNDLE_DISPLAY_NAME} and make sure that gets set in your build phases or from your ENV, or from an XCCONFIG file when building from the command line, the name should be replaced with what you set it with.

how to creating localizable.strings file by code in iPhone

I am working on one multilanguage project which will download string from server depend on language selected by user. I would like to save this downloaded string into localizable.string file. So how could I do that? I know how genstrings works but I would like to generated *.strings file by code and save it. My code will read this *.strings file for localizable. Anybody know which api i have to use?
thanks in advance
Manu
Typically, localization depends on strings files that are within the app bundle. Since you can not modify the app bundle at run time, you will have to put the strings files you downlaod elsewhere and you will have to modify the usual localization methods to find and use those strings files.
Look at Apple's iPhone samples to see how they do localization and fetching of the strings, and see if you can replace all the local accesses of the localization resources with resources in another directory.