开发者

Listing localized files

Konichiwa folks, I'm banging my head over a non-standard procedure to read a bunch of localized xml located in my project.

My purpose is to read recursively all these files in order to feed a coredata sqlite db to create various lang-based versions of the same DB.

In the first place, I've tried an old school technique, like:

NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil];
NSArray *onlyXMLs = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.xml'"]];
for (NSString *tString in onlyXMLs) { 
   /* stuff */
}

with no luck at all, because it pops out all the non-localized xmls in my project and nothing more.

so I was wondering if there would be a way to get t开发者_StackOverflow中文版hose damn't localized xmls out there.

thanks in advance.

If u got doubts or questions don't be a stranger, drop me a line.

-k-


ok, solved it!

for the ones who are seeking for an answer to the problem, here's the solution:

    NSArray *onlyXMLs = [[NSBundle mainBundle] pathsForResourcesOfType:@"xml" inDirectory:nil forLocalization:@"English"];

remember that the parameter that carries the desired language must always be the same of the .plist directory containing the desired files in your project.

so if you've got a English.plist with the stuff you need in it, that must also be the name string to pass (like shown in the above example), otherwise if you're dealing with a en.plist, @"en" shall be the string.

that's it, that's all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜