Rails Gem Geocoder does not obey per request language setting? - ruby-on-rails

I am trying to get a different language version of an address from Geocoder using Google API. I have tried to geocode the result using the following:
Geocoder.search("Effel Tower", language: :fr)
or
Geocoder.search("Effel Tower", {language: :fr})
but nothing works. It would work if I change the configuration:
Geocoder::Configuration.locale = :fr
Geocoder.search("Effel Tower")
I have been searching for an answer... even to look into the code. https://github.com/alexreisner/geocoder/blob/master/lib/geocoder/lookups/google.rb. In the google.rb language parameter is handled so it should work: :language.
Any idea? Thank you :)

I've found the answer. The language setting should be sent as string, not symbol. As a result:
Geocoder.search("Effel Tower", language: "fr")
will return French result. Thank you.

Related

Dynamic setting language in Golang web framework Iris

I have these language files:
locales/
en-US/
a.yaml
b.yaml
zh-CN/
a.yaml
b.yaml
DA/
a.yaml
b.yaml
set default language:
app.I18n.SetDefault("en-US")
How to set language dynamically according to l parameter:
www.sete.com/xx/xxx?l=en => set en-US
www.sete.com/xx/xxx?l=cn => set zh-CN
www.sete.com/xx/xxx?l=da => set DA
www.sete.com/xx/xxx?l=NotFound => default en-US
In addition, whenI set a language that doesn't exist:
www.sete.com/xx/xxx?l=NotFound
I get an error in response like this:
{
"user": "yaml%!(EXTRA string=Tom....)"
}
So , what should I do to better solve these problems? I tried my best, my English is not good, please help me.....
You can find Iris i18n examples at: https://github.com/kataras/iris/tree/master/_examples/i18n
If the language was not found, then the default language's key will be shown instead unless app.I18N.Strict is true. If the Strict field is false and the default language has no available key for the translation then the app.I18n.DefaultMessageFunc will be fired instead, you can take a look on how to configure what happens if a key does not exist at: https://github.com/kataras/iris/blob/7b6a8f1e26469ab3ae53cfe468d6e5202c75c2a8/_examples/i18n/basic/main.go#L38-L47

Nexmo VoiceXML not working in language other than en-US

I have a running VoiceXML application that works ok in Nexmo. If I set any language other than en-US the calls want get answered. I just change en xml:lang as in:
<vxml application="/dialogue/root/50b9bab0-9ce8-4d7a-9389-09f06aa8f9ee" version="2.1" xml:lang="es-es">
I have tried in the vxml above and also in the prompt tag. Any language like es-es, es-ES... even en-UK will make my vxml stop working in Nexmo.
I am sure script is OK as I can change en-US female and male voice with en-us-male and en-us-female. That works.
Am I missing something?
(I don't think it makes a difference but I use the great Rivr java library to generated vxml)
for me "fr-ca" doesnt work but "fr-ca-female" does work

Why numbers getting reversed when formatted in RTL Arabic - Rails application?

I'm using Prawn gem in my Rails app to generate PDF reports.
I read the documentation for putting the text in Arabic with text_direction RTL in arabic.
But, issue is that numbers are getting reversed here.
I wanted semester 1234 as الفصل الدراسي 1234,
but in my app the output is الفصل الدراسي 4321.
My two lines of code is here:
pdftable = Prawn::Document.new
pdftable.text(t('org.semester') + " " + #semester)
#semester = '1234' (The reason would be that it is being treated as a text/string, thus changes to RTL (reversed))
Anyway, Please help me to retain numbers in proper order without changing the RTL format.
Without hacking too much you could use
#semester.to_s.reverse
So you reverse the string twice

Pasting strings outside of Xcode to an array doesn't regonize them as strings

so after a long time writing down all different currencies i need for my currency converter i was going to paste them into Xcode. But when i do that the text doesn't turn red. Im afraid i need to rewrite it all string again, which took my almost 1h to do. Is there any way to fix this?
Datarray2 = [[NSMutableArray alloc]initWithObjects:#"United States Dollar",#”Euro”,#”Japanese yen”,#”Bulgarian lev”,#”Czech koruna”,#”Danish krone”,#”British pound”,#”Hungarian forint”#”Lithuanian litas”,#”Polish złoty”,#”Romanian leu”,#”Swedish krona”,#”Swiss franc”,#”Norwegian krone”,#”Croatian kuna”,#”Russian ruble”,#”Turkish lira”,#”Australian dollar”,#”Brazilian real”,#”Canadian dollar”,”Chinese yuan”,#”Hong Kong dollar”,#”Indonesian rupiah”,#”Israeli new shekel”,#”Indian rupee”,#South Korean won”,#”Mexican peso”,#”Malaysian ringgit”,#”New Zealand dollar”,#”Philippine peso”,#”Singapore dollar”,#”Thai baht”,#”South African rand”,nil];
EDIT: interestly, they don't show as string here at stackoverflow either outside from US Dollar which i wrote from inside xcode.
If you look at the text, the quotes are wrong. You have ”, but should have " (and the first USD one does).
Global find and replace the wrong quotes with the correct quotes.

Can I use a regular expression to extract the domain from a URL?

Suppose I want to turn this :
http://en.wikipedia.org/wiki/Anarchy
into this :
en.wikipedia.org
or even better, this :
wikipedia.org
Is this even possible in regex?
Why use a regex when Ruby has a library for it? The URI library:
ruby-1.9.1-p378 > require 'uri'
=> true
ruby-1.9.1-p378 > uri = URI.parse("http://en.wikipedia.org/wiki/Anarchy")
=> #<URI::HTTP:0x000001010a2270 URL:http://en.wikipedia.org/wiki/Anarchy>
ruby-1.9.1-p378 > uri.host
=> "en.wikipedia.org"
ruby-1.9.1-p378 > uri.host.split('.')
=> ["en", "wikipedia", "org"]
Splitting the host is one way to separate the domains, but I'm not aware of a reliable way to get the base domain -- you can't just count, in the event of a URL like "http://somedomain.otherdomain.school.ac.uk" vs "www.google.com".
/http:\/\/([^\/]*).*/ will produce en.wikipedia.org from the string you provided.
/http:\/\/.{0,3}\.([^\/]*).*/ will produce wikipedia.org.
yes
Now I know you haven't asked for how, and you haven't specified a language, but I'll answer anyway... (note, this works for all language subsites, not just en.wikipedia...)
perl:
$url =~ s,http://[a-z]{2}\.(wikipedia\.org)/.*,$1,;
ruby:
url = url.sub(/http:\/\/[a-z]{2}\.(wikipedia\.org)\/.*/, '\1')
php:
$url = preg_replace('|http://[a-z]{2}.(wikipedia.org)/.*|, '$1', $url);
Of course, for this particular example, you don't even need a regex, just this will do:
url = 'wikipedia.org'
but I jest...
you probably want to handle any URL and pull out the domain part, and it should also work for domains in different countries, eg: foo.co.uk.
In which case, I'd use Mark Rushakoff's solution to get the hostname and then a regex to pull out the domain:
domain = host.sub(/^.*\.([^.]+\.[^.]+(\.[a-z]{2})?)$/, '\1')
Hope this helps
Also, if you want to learn more, I have a regex tute online: http://tech.bluesmoon.info/2006/04/beginning-regular-expressions.html
Sure all you would have to do is search on http://(.*)/wiki/Anarchy
In Perl (Sorry I don't know Ruby, but I expect it's similar)
$string_to_search =~ s/http:////(.)//. should give you wikipedia.org
to get rid of the en, you can simply search on http:////en(.)//......
That should do it.
Update: In case you're not familiar with Regex, I would recommend picking up a Regex book, this one really rocks and I like it: REGEX BOOK,Mastering Regular Expressions, I saw it on half.com the other day for 14.99 used, but to clarify what i suggested above, is to look for the string http://en, then for anything until you find a / this is all captured in $1 (in perl, not sure if it's the same in ruby), a simple print $1 will print the string.
Update: #2 sorry the star in the regex is not showing up for some reason, so where you see the . in the () and after the // just imagine a *, oh and I forgot for the en part add a /. at the end that way you don't end up with .wikipedia.org

Resources