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"];
Related
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 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);
In the app I'm making I have a lot of huge strings. I don't want to hardcode these into my code because it makes the code unbearably messy. When I made a similar android app, it was a simple matter of declaring the string in strings.xml as
<string name="hello_world">Hello World!!</string>
and accessing it in the java file with
getString(R.string.hello_world);
How can I do something like this with iOS?
You could put them into a .plist file and load them using the following code (which assumes a file called strings.plist which has been copied into the app bundle):
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"strings" ofType:#"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:filePath];
NSString *string1 = [dict objectForKey:#"string1"];
However if you want to internationalize your app, then using Apple's Internationalization and Localization technology might be something to look at instead.
EDIT: you'll want to load that file/dictionary only once and keep it around the entire app lifetime; don't use the above code for every string access!
I am trying to track the download_count of a gitHub release via the gitHub api. I don't need much, I just want to see what it is.
I'm trying to get this information: http://developer.github.com/v3/repos/releases/#response
As you can see from the URL, the return includes a "download_count" key, but unfortunately, my assets array is entirely empty.
By Using This:
NSString * owner = #"...";
NSString * repo = #"...";
NSString * repoId = #"...";
// Get Release Info
NSString * releaseURL = [NSString stringWithFormat:#"https://api.github.com/repos/%#/%#/releases", owner, repo];
// Get Assets List Specifically
NSString * assetsURL = [NSString stringWithFormat:#"https://api.github.com/repos/%#/%#/releases/%#/assets", owner, repo, repoId];
NSURL * gitAssetsURL = [NSURL URLWithString:releaseURL];
NSData * gitAssetsRawData = [NSData dataWithContentsOfURL:gitAssetsURL];
NSString * gitDataString = [[NSString alloc] initWithData :gitAssetsRawData encoding:NSASCIIStringEncoding];
NSLog(#"%#", gitDataString);
Everything outputs fine, but my assets array is always empty. I do have releases, and the assets array is empty on all of my repositories.
Answered by Ivan in Comments, but just to close the question,
Ivan - "Assets are binaries you can upload when creating a release. Try creating a release and look for the "Attach binaries by dropping them here or selecting one." text. We track download counts only for those assets, not for releases themselves (currently)."
#Logan's answer is correct, but I think it should be noted as well that if you're seeing an empty list but did download some files into the release, that you should make sure you used the binaries download. I read his answer and thought that I had done everything correctly.
It turns out there are two sections in the UI, and I missed the binaries one completely. There's a larger (body) section, where you can add files, and right under that, there's a smaller binaries upload section. That was what I missed when I couldn't figure out why my assets were only showing up in the json under "body."