I want to dynamically change display name from within the application. Is there a way it? i dont want to use .plist. i want to use with xcode from application. Thanks
${PRODUCT_NAME} How can i call this value with code ?
The app name is defined in the app's info.plist file..
That come in Main Bundle..and iOS does not allow anything to be written and updated in Main Bundle..
So you cant programmatically change contents of app info.plist having app's name...bundle identifier ..etc
No, it's not possible. The Info.plist and everything in the app bundle is read-only once it's installed on an iPhone.
Add the following code to get the product name
NSDictionary *infoPList = [[NSBundle mainBundle] infoDictionary];
NSString *appName = [infoPList objectForKey:#"CFBundleDisplayName"];
appName is the value of "Bundle display name" or Product Name
I don't believe so.
You can localise it -- i.e., display different names depending on the language in use -- but I don't think you can change the name dynamically. That's probably a good thing... it could get pretty confusing if abused.
Related
Now, in standard behavior of localization, the iOS determines the currently set Language of iPhone and uses the Localizable.strings file to set the appropriate text.
My client, however, requires a multi-language iOS application in which the language is set within the application independent of the native iOS preferred language. i.e. the application may have different language to what the iOS is currently set to on the iPhone.
Anybody with any ideas about how to go about implementing this scenario?
My idea:
I could create a custom static class similar to the NSLocalizeString and hard code strings within that and return appropriate language string w.r.t language set within the app, and if that is a possible solution then any suggestions about how to structure that class)
You could:
store your translation string in a .plist file (string_key/translation) for each language;
read the appropriate plist (depending on the language currently set) in a NSDictionary;
access the dictionary for each string you want to display (just like you would do with NSLocalizeString).
I once had to create a flashchards app and the client needed to change the language at will. I don't have the source code for it at my box right now, but I remember using this tutorial. Also check the sample code they use.
Side note - dissing your clients publicly is really unprofessional.
Create plist files with needed language. I use {LANG}_{CLASS NAME} and {CLASS NAME} for default with all localized strings.
After that I made a method that checks if proper file exists, take it or default if missing and returns an NSDictionary object depending on the device language, called on class init. This idea can also be used, if you implement localized nibs by adding nib name to the strings file.
+ (NSDictionary *) getLocalized: (NSString *) contollerName andLang:(NSString *) lang {
NSString *fullPath = nil;
// You can use device lang if needed
NSString * curLang=[[NSLocale preferredLanguages] objectAtIndex:0];
fullPath = [[NSBundle mainBundle] pathForResource: [NSString stringWithFormat:#"%#_%#",contollerName,lang] ofType: #"plist"];
if (!fullPath) {
fullPath = [[NSBundle mainBundle] pathForResource:contollerName ofType:#"plist"];
}
return [NSDictionary dictionaryWithContentsOfFile:fullPath];
}
So, it can be called by something like that:
[tools getLocalized:[Controller.class description] andLang:#"XX"];
You can use standard localization (.strings files and localized .xibs) and force your app to use a language other than the iOS language setting. For details on how to achieve this, see this post: Change language of the ios application
Note that if you (or rather your client!) want to switch language on the fly while using the app, it will be more complicated--you would need to implement some sort of refresh feature and make sure the xibs are reloaded.
This question already has answers here:
How to localize bundle display name in iPhone app?
(6 answers)
Closed 5 years ago.
I'm trying to find the easiest way to localize my app. I'm using sqlite, so I need basically only to switch my database name. Problem is the app name - can it be localized from code or I have to make x apps for x languages, so anyone will have app name in his/hers native language? The latter one seems like already rejected app to me... anyone?
I assume you mean the Bundle Display Name that appears on the device's home screen:
You should create a localized file called InfoPlist.strings similar to the Localizable.strings file that you use for the usual text snippets.
In the InfoPlist.strings you can localize the different keys from your Info.plist. To localize the app name add:
"CFBundleDisplayName" = "My localized app name";
To localize a file: Simply create a new strings file in Xcode. Then reveal the right Xcode pane and add localizations via the menu shown here:
Using this technique you can localize any file you like. Simply add the correct version to your bundle. If you then use [[NSBundle mainBundle] pathFor... you will automatically get the path to the correct localization. We do this for sqlites, strings and sometime even images.
I have a method that loads data from the Info.plist file of an app. Right now I'm hardcoding the name and the type, i.e. using pathForResourcehowever, this approach fails if the name of the plist file has changed, say MyAppSettings.plist Is there a way I can get the info.plist file that is being used regardless of the name? Thanks
The main App settings file, mostly named MyApp-info.plist, will al ways be named info.plist after the app is compiled and bundled.
There is also a short way to acces the info.plist:
NSNumber *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleVersion"];
If I have an iPhone app named: MyCoolApp
How do I keep the bundle named: MyCoolApp.app
But have the app name on that shows up underneath my icon read: My Cool App
I have changed my PRODUCT_NAME target setting to be "My Cool App" and changed my plist CFBundleDisplayName and CFBundleName to be "MyCoolApp". So far my app name on the device still reads "My Cool App"
I'm pretty green to this stuff still. Thanks for any help you can provide.
You might need to delete the app from the device and reload it for the change to take effect.
Sometimes when changing the Project Properties it does not work. Project Properties and Target Properties Window look the same. I have mistaken there sooo many times. ;)
The best way to do this is using a key called Bundle Display Name. It has to be added in the info.plist.
DO NOT CHANGE THE PRODUCT NAME IN BUILD SETTINGS.
This is not a good approach as it changes your bundle identifier. All you need to change is the product display label.
Note: Make sure to include this in info.plist in your projectTests info.plist also.
I'd like to reference my own variables in my info.plist & build settings files.
Is this possible? Any ideas?
If you add custom build settings via the 'add build setting' button in the bottom right, then you should be able to use the ${} form within your info.plist to reference the names of those variables.
For example, I have such a setting called 'PJ_VERSION_EXTRA'. In my Info.plist I have:
<key>CFBundleShortVersionString</key>
<string>1.1${PJ_VERSION_EXTRA}</string>
In my debug build configuration, I define that setting as '-DEBUG'. That means that when I show the version string in app, debug builds identify themselves.
I can see any problems with doing this.
Should be as simple as adding an entry to the info plist, and then retrieving it using
[[[NSBundle mainBundle] infoDictionary] objectForKey:myPlistKeyName];