localization from inside the application in iphone - iphone

how can we localized our application from the button in built in application not from iphone setting. please suggest me something i am stuck in it. Thanx in advance

You change the bundle before you call for the translation;
NSString *bundle_path = [[NSBundle mainBundle]
pathForResource:#"Localizable"
ofType:#"strings"
inDirectory:nil
forLocalization:#"se"];
NSBundle *localized_bundle = [[NSBundle alloc]
initWithPath:[bundle_path stringByDeletingLastPathComponent]];
NSString* translated = NSLocalizedStringFromTableInBundle(#"KEY", nil, localized_bundle, nil);

Related

Get name of Xcode Project in actual code

So you know the part of the project that is "MyNameGoesHere.app" or "MyNameGoesHere.xcodeproj" - is there a way to get the MyNameGoesHere part via objective-c code?
I can get all kind of device info from UIDevice messages but I can't figure out how to get project/app name.
CFBundleDisplayName doesn't work anymore. Use:
NSString *bundleName = [[NSBundle mainBundle]
objectForInfoDictionaryKey:#"CFBundleName"];
You're probably looking at the bundle's InfoDictionary. You can get the app's name via the following code:
NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
NSString *bundleName = [NSString stringWithFormat:#"%#", [info objectForKey:#"CFBundleDisplayName"]];

Accessing the image which is in external bundle

I created a bundle with name applausible.bundle, i placed the bundle in supporting files.This is my code
NSBundle* myBundle;
myBundle = [NSBundle bundleWithPath:#"/Library/applausible.bundle"];
NSString *path = [myBundle pathForResource:#"splash.png" ofType:nil];
[imageName setImage:[UIImage imageNamed:path]];
Here I am unable to display the image on the image view. Another way I tried like this I place the image on the image view using xib,while running the app. The output is coming like this in console
Could not load the "splash_screen high resolution.png" image referenced from a nib in the bundle with identifier "com.xxxxxxx.ImageSample". Can any one tell me where i made a mistake.Finally my goal is to display the image on the UIImageview which is in external bundle.
This may help you.
NSString bundlePath = [[NSBundle mainBundle] pathForResource:#"applausible" ofType:#"Bundle"];
NSLog(#"Bundle path is %#",bundlePath);
NSBundle myBundle;
myBundle = [NSBundle bundleWithPath:bundlePath];
NSString *path = [myBundle pathForResource:#"splash_screen high resolution" ofType:#"png"];
UIImage *image=[[UIImage alloc]initWithContentsOfFile:path];
[imageName setImage:image];
please try it out.
It may be helpful
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:#"applausible" ofType:#"Bundle"];
using this method you can get the bundle path.Then use your code from second line
myBundle = [NSBundle bundleWithPath:bundlePath];
NSString *path = [myBundle pathForResource:#"splash" ofType:n#"png"];
[imageName setImage:[UIImage imageNamed:path]];

Error in internationalization iPhone

I am using iOS 5, XCODE 4.2
In my loginViewController:
-(IBAction)loginButton:(id)sender{
textClass=[[MainScreenController alloc ] init];
NSLog(#"ShowText called");
textClass.selectedLanguage=currentLanguage;
[self.view addSubview:textClass.view] ;
NSLog(#"txtclaslan=%d",textClass.selectedLanguage);
}
In my MainViewController viewDidLoad: method:
mainScreenTitle.text=[self languageSelectedStringForKey:#"screenTitle"];
And in languageSelectedStringForKey:
-(NSString*) languageSelectedStringForKey:(NSString*) key{
NSString *path;
if(selectedLanguage==ENGLSIH_LANGUAGE)
path = [[NSBundle mainBundle] pathForResource:#"en" ofType:#"lproj"];
else if(selectedLanguage==TURKISH_LANGUAGE)
path = [[NSBundle mainBundle] pathForResource:#"tr" ofType:#"lproj"];
else
path = [[NSBundle mainBundle] pathForResource:#"en" ofType:#"lproj"];
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
NSString* str = [languageBundle localizedStringForKey:key value:#"" table:nil];
return str;
}
Here in this method languageSelectedStringForKey when I load the MainViewController I my application crashes. I don't get any error just this line is highlighted
NSBundle* languageBundle = [NSBundle bundleWithPath:path]; < Thread 1
What can be the issue with this?
Thanks in advance
As suggested:
Looking at your code it seems that if the language is not English and not Turkish then path is not set.
You may also want to follow this advice from the [NSBundle localizedStringForKey:value:table:] method description:
"Using the user default NSShowNonLocalizedStrings, you can alter the behavior of localizedStringForKey:value:table: to log a message when the method can’t find a localized string. If you set this default to YES (in the global domain or in the application’s domain), then when the method can’t find a localized string in the table, it logs a message to the console and capitalizes key before returning it."

Localization of Audio

First of all i am a n00b.
After 3 days of trying and research i decided to get some external help.
What i did and my Project:
i make a book for children.
Now i am localizing my app.
for a Image i did it like this:
UIImage *schrift = [UIImage imageNamed:NSLocalizedString (#"Schrift_en.png", nil)];
image = [[UIImageView alloc] initWithImage:schrift];
image.frame = CGRectMake(75.5, 80, 617, 137);
[self.view addSubview:image];
[image release];
works great for me :)
Now i am trying to do the same with my Narrator Audiofile but can´t figure out how.
NSString *path = [[NSBundle mainBundle] pathForResource:#"Vorwort" ofType:#"mp3"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
self.audioPlayer = theAudio;
[theAudio release];
How can i change the code above to make it work and how to define ofType:#"mp3" in Localizable.strings-file?
Google can´t help me.
Any ideas?
slowly but surely i am losing my motivation.
It would be really cool if anyone could help me!
Thanks in advance
Planky
This isn't really what Localizable.strings is for. Check out the docs for NSBundle's pathForResource:ofType:
The method first looks for a matching resource file in the non-localized resource directory of the specified bundle. (… in iOS, it is the main bundle directory.) If a matching resource file is not found, it then looks in the top level of any available language-specific “.lproj” directories. (The search order for the language-specific directories corresponds to the user’s preferences.) It does not recurse through other subdirectories at any of these locations.
So if you previously had your audio file here:
YourBook.app/Vorwort.mp3
you should instead arrange it like this:
YourBook.app/en.lproj/Vorwort.mp3
YourBook.app/fr.lproj/Vorwort.mp3
No Volwort.mp3 should exists at the top level of the .app folder.
You will need to create the en.lroj/fr.lproj directories and drag them to your XCode project. Check your app bundle structure by right clicking on the .app in the Finder and clicking 'Show bundle contents'.
Try this
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/%#", [[NSBundle mainBundle] resourcePath], NSLocalizedString (#"audiofilename.mp3", nil)]];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
self.audioPlayer = theAudio;
[theAudio release];

How can I access the application version?

I would like to know how can I access the iOS application target version.
This number : http://img11.hostingpics.net/pics/146187Capturedcran20110728111355.png
Thanks
NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
NSString* versionNum = [infoDict objectForKey:#"CFBundleVersion"];
This will give the version number. Similarly you can get other attributes as well.