In my app there are so many plist files, and I am trying to localise them all.
As far as I know, this can be done by simply(or hardly ) creating a .strings for each plist, and in each .strings file, you do the normal replacing of value with the localized value.
This is fine for small amount of files with small keys.I am considering the plist files with each more than 300+ keys.
Hence I decided to convert the plist in format of .strings, and at the end replace it in the place of plist.strings file.
Attempt :
I have a test.plist which has 400 keys in the format
key type value
test1 String its a string
test2 Dictionary
item1 String item1 in dictionary test2
item2 String item2 in dictionary test2
item3 String item3 in dictionary test2
....
....
test100
and I am extracting all the keys and their values by looping through each key programmatically and converting them into .strings file format which is
"value" : "value";
" item1 in dictionary test2":" item1 in dictionary test2";
" item2 in dictionary test2":" item2 in dictionary test2";
" item3 in dictionary test2":" item3 in dictionary test2";
Q1: Can I copy paste this content in the InfoPlist.strings ?
Q2: Do I need to create a testPlist.strings for the test.plist file?
I know that we have to create InfoPlist.strings for Info.plist file.
But I am not sure If I have to create testPlist.strings for test.plist file or I can just copy paste the content of converted test.plist into InfoPlist.strings!
This is how I get the data in my required format.
NSString * path = [@"~/test.plist" stringByExpandingTildeInPath];
NSAssert(path != nil, @"need a path to continue");
NSDictionary * messagesDictionary = [NSDictionary dictionaryWithContentsOfFile:path];
NSAssert(messagesDictionary != nil, @"need a dictionary to continue");
NSMutableString * result_plain = [NSMutableString string];
for (NSString * messageCode in [[messagesDictionary allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]) {
NSDictionary * messageInfo = messagesDictionary[messageCode];
[result_plain appendString:@"\n"];
if ([messageInfo isKindOfClass:[NSDictionary class]]) {
[result_plain appendFormat:@"\"%@\" : \"%@\";), ", messageInfo[@"cancel"], messageInfo[@"cancel"]];
[result_plain appendFormat:@"\"%@\" : \"%@\";), ", messageInfo[@"message"], messageInfo[@"message"]];
[result_plain appendFormat:@"\"%@\" : \"%@\";), ", messageInfo[@"title"], messageInfo[@"title"]];
}
if ([messageInfo isKindOfClass:[NSString class]]) {
[result_plain appendFormat:@"\"%@\" : \"%@\";), ", messageInfo, messageInfo];
}
}
Can I put all plist strings(10+ .plist file strings) in the file InfoPlist.strings ?
Q3. Does xcode refer to one plist.strings for all .plist files ?