I want to get the source code from .m file so I use this way:
NSString *path = [[NSBundle mainBundle] pathForResource:#"ViewController" ofType:#".m"];
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSLog(#"%#", content);
However the console print "null".
I wonder if there any way we can use to get .m file's content even if use private method.
If you're copying the actual source file inside your application's bundle and including it, then sure, that'll work, although I don't know why you'd want to do that.
If you're wondering if you can decompile a binary file back to Objective-C code, then no, you can't do that—at least not simply. If you have good enough skill with assembly language, of course, you can read a disassembly of the code, figure out what the original Objective-C did, and use that knowledge to recreate it.
I'm trying to access a strings file I use in my iOS app project, from a mac console app I'm writing.
Obviously with my ios app I can access this directly via the bundle...
NSString *fname = [[NSBundle mainBundle] pathForResource:#"whatever" ofType:#"strings"];
NSDictionary *d = [NSDictionary dictionaryWithContentsOfFile:fname];
NSString *loc = [d objectForKey:#"LABEL_001"];
However, I want to retain the parsing functionality but access the strings file directly.
I haven't been able to find a method to do this?
I am developing an ecommerce app. Initially the app is in the English language and now I want to convert it into the Chinese and French language. I referred to this link
So what I have understood is that every text we need to convert into French and Chinese, in the respective string files for the static data, but I am getting data from the backend. So then how do I convert that text dynamically?
You can use this code. And in Project you can add localisations in info.plist.Hope it will help you.Thank You
NSLocale* curentLocale = [NSLocale currentLocale];
namearray=[NSMutableArray arrayWithObjects:NSLocalizedString(#"Hellokey1",#""),NSLocalizedString(#"Hellokey2",#""),NSLocalizedString(#"Hellokey3",#""),NSLocalizedString(#"Hellokey4",#""),NSLocalizedString (#"Hellokey5",#""),NSLocalizedString(#"Hellokey6",#""),NSLocalizedString(#"Hellokey7",#""),NSLocalizedString(#"Hellokey8",#""),NSLocalizedString(#"Hellokey9",#""),NSLocalizedString(#"Hellokey10",#""),NSLocalizedString(#"Hellokey11",#""),NSLocalizedString(#"Hellokey12",#""),NSLocalizedString(#"Hellokey13",#""),NSLocalizedString(#"Hellokey14",#""),NSLocalizedString(#"Hellokey15",#""),NSLocalizedString(#"Hellokey16",#""),NSLocalizedString(#"Hellokey17",#""),NSLocalizedString(#"Hellokey18",#""),NSLocalizedString(#"Hellokey19",#""),NSLocalizedString(#"Hellokey20",#""),NSLocalizedString(#"Hellokey21",#""),NSLocalizedString(#"Hellokey22",#""),NSLocalizedString(#"Hellokey23",#""),NSLocalizedString(#"Hellokey24",#""),NSLocalizedString(#"Hellokey25",#""),NSLocalizedString(#"Hellokey26",#""),NSLocalizedString(#"Hellokey27",#""),nil];
[curentLocale displayNameForKey:NSLocaleIdentifier
value:[curentLocale localeIdentifier]];
// NSString *path = [[NSBundle mainBundle] pathForResource:#"fr" ofType:#"lproj"];
// NSLog(#"path:%#",path);
NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
If the text received is truly dynamic (i.e. there's no way to know ahead of time what the possible variations are), there's no way to do it. If you know what the possibilities are, you embed the translations just as you do for static text, and you have the server send the localization key. This is the scheme used by iOS for translating notification alerts.
(You could theoretically use a translation API, such as Google Translate, but that has many downsides, and few upsides.)
Having a weird issue that I can't seem to figure out. I have a plist that contains strings with line breaks. I'm using the Xcode plist editor. To perform the line break, I pressed option+return within strings where I want them, and it shows up fine in the editor.
The weird behavior:
When I have my app parse these strings, some of the strings will show with \n where I put the break, and other strings will show \u2028 instead. I understand from reading that these are both escapes, but I can't figure out why Xcode gives me one or the other. Is there a way I can force it to give me \n instead of \u2028? I'd rather not have to manually process the strings after-the-fact to change it
example:
"Hello\nWorld!" - I want and sometimes get this...
"Hello\U2028World!" - I don't want and sometimes get this...
Pulling my hair out. Thanks!
edit:
Here's how I'm getting the strings.
In .plist editor:
In the .plist, I have a dictionary. In the dictionary are the strings. They were "created and defined" in the editor.
In code:
//Get the config variables
NSString *path = [[NSBundle mainBundle] pathForResource:#"Variables" ofType:#"plist"];
vars = [[NSDictionary alloc] initWithContentsOfFile:path];
NSString *blah = [vars objectForKey:#"someString"];
NSLog(#"%#", blah);
I made an ios / cocoa app a few months ago and now I'm trying to localize it. I have already localized XIBs, Strings, etc. successfully.
The problem that I am facing now is that I am parsing an XML (XML-SAX) file to build a list and retrieve more information over the itens, like a tree of information.
The parser simply extract data from the lines.xml file. I tried to localize the file and change every string inside the the just created versions of lines.xml, but I can only see the original strings being displayed.
Please, let me know if you need any other information.
A little help here would be really appreciated.
Thanks.
I found some not so clever way to do so..... it works but I think it is ugly:
if([language isEqual: #"en"]){
s = [[NSString alloc] initWithFormat:#"lines-en"];
}else{
s = [[NSString alloc] initWithFormat:#"lines"];
}
NSString *path = [[NSBundle mainBundle] pathForResource:s ofType:#"xml"];