Groovy gsp grails number format replace - grails

I have a German customer, he wants some numbers on his page to be
4,3
instead of
4.3
as I cant set the Number format globally for the project or controller because i have javascript depending on the english format, I'm looking for a simple replace method in gsp something like
${number.replace(/./,",")}
but that causes
No signature of method: java.lang.Double.replace() is applicable for
argument types: (java.lang.String, java.lang.String)
any idea ? thanks in advance

Instead of doing string conversion stuff, do it like this:
${formatNumber(number: number, locale: Locale.GERMAN, format: '##0.00')}

take a look at
http://grails.org/doc/2.3.x/ref/Tags/formatNumber.html
You should be able to format the number properly using the locale.

Related

Change Encoding in ModelState.ModelError

Here is my problem: I add a message to ModelError with addModelError(String.Empty,”My message”).
In my view I just call #Html.ValidationSummary().
The message is in German and the characters Ö, Ä, Ü are just shown as questionmark. How do I change that?
As I see it there are two options. One option is to write a custom validation summary helper which doesn't HTML encode the messages like described in the link that Kartikeya Khosla provided. Or, and that’s what I did, Just use the Unicode reference in the message string. The solution in Kartikeya is more elegant, but in my case it is a lot of code to change two characters. By the way here a link to look them up if anybody wants to do the same:
http://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=oct&unicodeinhtml=dec&htmlent=1

Need some help regarding .net mvc URL routing/rewriting

URL is something like
/home/rawstring13245/rawstring534533453
I want the rule that saves only 13245 to parameter and 534533454 to another but ignore raw strings before them.
how to achieve it in route.config file?
i want this because strings are not parameters , I need only parameters out of string
like:
url:"{controller}/rawstring{action}/rawstring{id}",
what to enter in place of raw string? I don't need those strings. and yeah each raw string is of same length= 10
You can get complete variables as strings and get your desired part by using the sub-string method. Its the quickest solution, i thought it solve your problem.

Change faker gem phone number format

Is there a way to control the format of the Phone number generated by faker?
When I call:
Faker::PhoneNumber.cell_phone.to_i
I end up getting the wrong value.
I also would like to not have extensions.
You can set custom format on the fly like this:
Faker::Base.numerify('+90(###) ### ####')
This will solve your problem.
Faker::PhoneNumber.cell_phone is basically just calling numerify with one of the predefined phone_number_formats.
So you could just use numerify with your own format. For e.g. If you want 10 digits number, you would do:
Faker.numerify('#########')
If you'd still like to use Faker::PhoneNumber.cell_phone but would like to get rid of the hyphens, you could use gsub to replace the hyphens as:
Faker::PhoneNumber.cell_phone.gsub(/-/, '')

Best format for adding a version id into a URL path

I'm currently re-working an application and want to add in a version number to the application URL paths. For example:
http://mydomain/app/VERSION-ID/resource/...
My question is, what is the correct or standard format to add a version id to a URL string? Is there any disadvantage to just having it numeric (1.1 or 1-1):
Example: https://api.twitter.com/1.1/account/verify_credentials.json
Or is it better to have a non numeric identifier to be more intuitive as the url is public facing?
Thanks.
Do not use dots in a URL unless you're defining domain spaces. Use either dashes or other truncated versions (that don't use disallowed characters in the URL).
EXAMPLE:
Example: https://api.twitter.com/v1-1/account/verify_credentials.json
UPDATE: Here is some more information in another thread. My preference is not to use dots if at all possible, but it is apparently OK to do.
Can urls contain dots in the path part?

Displaying text in differnt locales on one page

I need to display sentences in my GSP in differnt locales.
The following documentation states that g:message takes a locale param.
I can't find an example of this anywhere. Has anyone done this?
<p><g:message code="welcome.into.text1" locale="sv_SE"/></p>
<p><g:message code="welcome.into.text1" locale="en_US"/></p>
Obviosuly, I have messages_sv.properties & messages_en_US.properties.
Thanks
To specify locale explicitely use Locale object instead of String, e.g.:
<g:message code="welcome.into.text1" locale="${Locale.US}"/>
http://grails.org/doc/latest/guide/i18n.html
Grails how to change the current locale

Resources