Iphone 音频本地化

Iphone 音频本地化,iphone,objective-c,xcode,audio,localization,Iphone,Objective C,Xcode,Audio,Localization,首先,我是n00b。 经过3天的努力和研究,我决定寻求一些外部帮助 我所做的和我的项目: 我为孩子们做了一本书。 现在我正在本地化我的应用程序。 对于图像,我是这样做的: UIImage *schrift = [UIImage imageNamed:NSLocalizedString (@"Schrift_en.png", nil)]; image = [[UIImageView alloc] initWithImage:schrift]; image.frame = CGRectMake(75

首先,我是n00b。 经过3天的努力和研究,我决定寻求一些外部帮助

我所做的和我的项目:

我为孩子们做了一本书。 现在我正在本地化我的应用程序。 对于图像,我是这样做的:

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];
YourBook.app/en.lproj/Vorwort.mp3
YourBook.app/fr.lproj/Vorwort.mp3
对我来说很好:)

现在我正试图用我的“讲述人”音频文件做同样的事情,但不知道如何做

NSString *path = [[NSBundle mainBundle] pathForResource:@"Vorwort" ofType:@"mp3"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL   fileURLWithPath:path] error:NULL];
self.audioPlayer = theAudio;
[theAudio release];
如何更改上述代码以使其正常工作,以及如何在Localizable.strings-file中定义@“mp3”类型

谷歌帮不了我。 有什么想法吗? 慢慢地,我肯定会失去动力

如果有人能帮我,那就太酷了! 提前谢谢 Planky试试这个

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];
试试这个

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];

这不是Localizable.strings的真正用途。查看NSBundle的文档

该方法首先在指定包的非本地化资源目录中查找匹配的资源文件。(…在iOS中,它是主捆绑包目录。)如果找不到匹配的资源文件,它将在任何可用的特定于语言的“.lproj”目录的顶层查找。(特定语言目录的搜索顺序对应于用户的首选项。)它不会在这些位置的任何其他子目录中递归

因此,如果您以前在这里有音频文件:

YourBook.app/Vorwort.mp3
你应该这样安排:

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];
YourBook.app/en.lproj/Vorwort.mp3
YourBook.app/fr.lproj/Vorwort.mp3
.app文件夹的顶层不应存在Volwort.mp3


您需要创建en.lroj/fr.lproj目录,并将它们拖到您的XCode项目中。右键单击Finder中的.app并单击“显示捆绑内容”,检查应用程序捆绑结构。

这不是Localizable.strings的真正用途。查看NSBundle的文档

该方法首先在指定包的非本地化资源目录中查找匹配的资源文件。(…在iOS中,它是主捆绑包目录。)如果找不到匹配的资源文件,它将在任何可用的特定于语言的“.lproj”目录的顶层查找。(特定语言目录的搜索顺序对应于用户的首选项。)它不会在这些位置的任何其他子目录中递归

因此,如果您以前在这里有音频文件:

YourBook.app/Vorwort.mp3
你应该这样安排:

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];
YourBook.app/en.lproj/Vorwort.mp3
YourBook.app/fr.lproj/Vorwort.mp3
.app文件夹的顶层不应存在Volwort.mp3

您需要创建en.lroj/fr.lproj目录,并将它们拖到您的XCode项目中。右键单击Finder中的.app并单击“显示捆绑内容”,检查应用程序捆绑结构