I have an NSLocalizedString which says something like this:
The house of David received 2 new offers.
Where the actual string is
NSLocalizedString(#"The house of %# received %i new offers", nil);
And I would like to add attributes on this string so it would look like this:
The house of David received 2 new offers.
It's amazing this is so hard. I tried to search for the parameters in the string, get their location and add the attributes, but it screws up when I want to change the string to "The 2 houses of david received 2 new offers". There it will make all the "2" strings bold.
Is there a better way to do this? After searching for days online I hope you guys can help me.
Related
My goal is to write a validation class for Rails that is capable of using an OCR recognised text from a business card and is able to detect string snippets and assign them to the correct attributes. I know this cannot be probably 100% perfect but I want to get as close as possible. Here is my approach so far:
I scan business cards via jquery's navigator.mediaDevices
I send the scanned image to a third party API Service, called OCRSpace (a gem is available here: https://github.com/suyesh/ocr_space)
I then get a unformatted array of recognised text snippets back, for example:
result = [['John Doe'], ['+49 160 123456'], ['Mainstr. 45a'], ['12345 Berlin'], ['CEO'], ['johndoe#business-website.de'], ['www.business-website.de']]
I then iterate through the array and do some checks, for example
Using the people library (https://github.com/mericson/people)
to split the name in firstname and lastname (additionally the title
or middlenames) Using the phonelib library
(https://github.com/daddyz/phonelib) to look up a valid phone number
and format it in an international string
Doing a basic regex check on the email address and store it
What I miss now is:
How can I find out what the name-string would possibly be? Right now I let the user choose it (in my example he defines "John Doe" as the name and then the library does the rest). I'm sure I would run into conflicts when using a regex as strings like "Main Street" would then also be recognized as a name?
How do I regex a combination of ZIP-Code and City name? I'm not a regex expert, do you know any good sources that would help? Couldn't find any so far except some regex-checkers in general.
In general: Do you like my approach or is this way too complicated? And do you know some best-practices that look better?
Don't consider this a full answer, but it was too much to make it a comment.
Your way of working seems Ok but I wouldn't use the OCR Service since there are other ways , Tesseract is the best known.
If you do and all the results are comparible presented it seems not too difficult since every piece of info has it's own characteristics.
You can identify the name part because it won't have numbers in it, the rest does, also you can expect to contain it "Mr." or "Mrs." or the such and not "Str.", "street" and so on. You could also use Google Maps to check for correct adresses, there are Ruby gems but have no experience with them.
Your people gem could also help.
You could guess all of this, present the results in you webpage and let the user confirm or adjust.
You could also RegExpr the post-city combination by looking fo a number and string combination in either order but you could also use a gem like ZipCodes to help.
I'm sorry, don't have the time now to test some Regular Expressions now and I don't publish code without testing.
Hope this was some help, success !
I have a list of users in Firebase that looks like this...
How would I retrieve only the email (for example) values?
THE answer.
Two things.
1) Please copy and paste your structure instead of a picture so we don't have to retype it. Please take a minute to format it so it looks cool.
2) This is a very basic query in Firebase and fully explained in the Most Excellent Guide to Retrieving Data In Firebase
Scroll down the query section and there are a couple of examples that are very similar to what you are asking for.
And a tad more info. Doing a query will retrieve each child node that matches the query (including the other stuff within the node). It's up to your code to grab each email (pretty simple task as it's key:value pairs)
If you don't want the other stuff, you would need to change the structure of the data
asdf
firstName
lastName
etc
emails
asdf
email: email address
asdf1
email: email address
or, use events: value for example and a structure like this
emails
asdf: email address
asdf1: email address
Simple question, new to iOS and Objective-C, not understand why it's not doing the full link.
NSLog(#"http://iam.colum.edu/portfolio/api/course/%#", setCourseNumber, "?json=True");
output: http://iam.colum.edu/portfolio/api/course/32-2400
Not going to go into what the coursenumber is, no point, the question is that my output is not including the "?json=True" part of the link. I know it must be something small that I am not including, I just am new to Objective-C and can't figure it out. Thank you in advance.
This:
NSLog(#"http://iam.colum.edu/portfolio/api/course/%#", setCourseNumber, "?json=True");
Could be this:
NSLog(#"http://iam.colum.edu/portfolio/api/course/%#?json=True", setCourseNumber);
Looks like Logan beat me too it.
Here's some more information from Apple's documentation on formatting string objects.
Here's a list of string formats. Things like %#, %d, etc.
Because you have two arguments, but using only one:
NSLog(#"http://iam.colum.edu/portfolio/api/course/%#", setCourseNumber, "?json=True");
setCourseNumber is first attribute - %#
"?json=True" is second attribute - ?
So you can modify it like this:
NSLog(#"http://iam.colum.edu/portfolio/api/course/%#%#", setCourseNumber, "?json=True")
Or use
NSLog(#"http://iam.colum.edu/portfolio/api/course/%#?json=True", setCourseNumber)
No matter, where argument is situated - in the middle or in the end.
In numerous places in my app, I have a name displayed (current user or other user). I have 3 fields for name: firstName, lastName and fullName. Full is simply firstName + lastName, and not used very often. I use 'firstName lastName' more often than fullName.
I recently localized the app into other languages, among them Chinese and Japanese, in which the order for names is reversed to 'lastName firstName'.
I am unsure how to handle this change now in my app. Has anyone encountered a similar challenge and how did you handle it?
Thank you
I figured out how to do this by saving a string called fullName in my Localizable Strings file as follows:
"fullName" = "%1$# %2$#";
Then, in the languages that have the name order different, their "fullName" string is like this:
"fullName" = "%2$# %1$#";
Hope this is helpful to someone else! :)
I want to store the exact country name using g:countrySelect. Example Germany instead of DEU. It is the value in the drop down menu. The drop down text is Germany but when it saves it to the database it changes back to the country code. Sorry if I am somewhat naive but I have been searching for almost 3 hours for solutions and it isn't well documented at the grails website. I could opt for any alternative even ajax. Just to have an easy way to display a list of countries and will be able to store the REAL NAME of the country NOT country code. Thank you!
You can convert from an ISO3 country code to the country name using this function
def getCountryName(String countryCode) {
Locale.availableLocales.find{it.ISO3Country == countryCode}.displayCountry
}
// Test
println getCountryName('DEU') // prints 'Germany'
If you want to do this within a GSP, it would be best to make this available as a TagLib.
Not sure when the above solution stopped working but if you try that now, you'll get an error:
Couldn't find 3-letter country code for CS
With the latest grail version, the current way of getting the full country name is by using this tag:
<g:country code="${country}"/>
I know this thread is old, but I was looking for the same issue and I had to share my solution.
You can use the CountryTagLib object to convert the ISO3 code back to full country name like this :
def country = CountryTagLib.ISO3166_3[code]
The "code" property being the ISO3 code that you got from <g:countrySelect>.