I have a model where I have this function:
public function showPrice(){
return money_format('%i€', $this->price);
}
Then in the view is used like:
<span>X {{$prod->pshowPrice()}}</span>
But instead of appear 10.00€ appear GBP10.00€.
Do you know why?
i formats the number based on the format used to describe the currency of the current locale
What you're seeing is expected if you're using a locale of en-gb
Something like money_format('%i!', $this->price) will show it with no currency info (where ! is a flag which suppresses the currency symbol)
Related
I have this in my controller
public function editProfile(Request $request){
$question1 = Question::where('group',1)->lists('question', 'id');
$question2 = Question::where('group',2)->lists('question', 'id');
return view('user', compact(''question1', 'question2'));
}
$question = {\"1\":\"What is the first name of your best friend in high school?\",\"2\":\"What was the name of your first pet?\",\"3\":\"What was the first thing you learned to cook?\",\"4\":\"What was the first film you saw in the theater?\"}
$question2 = {\"5\":\"Where did you go the first time you flew on a plane?\",\"6\":\"What is the last name of your favorite elementary school teacher?\",\"7\":\"In What city or town does your nearest sibling live?\"}
I would like to translate the value in both question 1 and question 2 and pass it to user blade without changing the key, Any suggestions?
As specified at the localization doc, you need to populate a lang file with translation strings. So, let's say you want to show both Spanish and English strings. In this case you'd need to create two files: /resources/lang/en/messages.php and /resources/lang/es/messages.php. The content of one of those files would be somewhat like this:
<?php
// resources/lang/es/messages.php
return [
'welcome' => 'Bienvenido'
];
This way, you could access the strings in there with the following method: __('messages.welcome'), which would return the string for the language set on your config/app.php -- the default entry is en, by the way, but you can set it to whatever you want. The value in there will define which language will be chosen when selecting strings.
Another method to create translation strings is using the string itself as key, storing them in a JSON file instead of PHP. For example, the following translation string:
{
"I love programming.": "Me encanta programar."
}
would be accessible through this: __('I love programming.').
Having said that, you may solve your problem through the two methods presented above. You could store in your DB keywords for the questions instead of the whole text, and create translation for as many languages as you want. Also, you could keep the questions in your database and create translation strings for those questions. Finally, you'd need to iterate over the fetched entries and translate each one of them, or use some Collection helper to do the hard work for you, like transform or map.
I am trying to format the date at the model using:
protected $dateFormat = "Y-m-d";
and I am getting this error:
"The separation symbol could not be found Trailing data" on line 582 of C:\wamp64\www\israplanet.com\vendor\nesbot\carbon\src\Carbon\Carbon.php
Using
protected $dateFormat = "Y";
causes this error:
"Trailing data" on line 582 of C:\wamp64\www\israplanet.com\vendor\nesbot\carbon\src\Carbon\Carbon.php
This example is from the October docs.
Whats is wrong here?
I'm not familiar with the example you have given (ie: using protected $dateFormat = "Y-m-d";) but when I do something like this I tend to use an accessor on the model:
public function getFormattedDateAttribute($value)
{
return $this->created_at->format('Y-m-d');
}
Obviously created_at would need to be replaced with the name of the date field. You'd then be able to access it in Twig as {{ array.formatted_date }}.
I cannot name this as good answer, but for now i at least can continue.
I simply changed format of the columns (created_at and updated_at) to date format and it stores the way i wanted it, but i always trying to fix problems (this habbit takes a lot of my time).
another option is to use handlebar helper for this.
But i want to understand the problem in the root.
(btw - thanks for answers)
Given this ApiController:
public string TestString() {
return "The value is: " + 1.23;
}
public double TestDouble() {
return 1.23;
}
With the browser's language set to "fr-FR", the following happens:
/apiController/TestString yields
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">The value is: 1,23</string>
/apiController/TestDouble yields
<double xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1.23</double>
I would expect TestDouble() to yield 1,23 in the XML. Can anyone explain why this isn't the case and, more importantly, how to make it so that it does?
It is because the conversion from double to string happens at different stage for each API. For the TestString API, double.ToString() is used to convert the number to a string using CurrentCulture of the current thread and it happens when the TestString method is called. Meanwhile, the double number which is returned by TestDouble is serialized to string during the serialization step which uses GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Culture.
In my opinion, both should use InvariantCulture. On the consumer side, the values will be parsed and be formatted with the correct culture.
Update: this is only used for JsonFormatter. XmlFormatter doesn't have such a setting.
Update 2:
It seems (decimal) numbers need special converter to make it culture-aware:
Handling decimal values in Newtonsoft.Json
Btw, if you want o change data format per action/request, you can try the last piece of code of the following link: http://tostring.it/2012/07/18/customize-json-result-in-web-api/
I have defined a form like this:
class RecordForm(Form):
rating = IntegerField('Rating')
If no value is inserted I get a default message like this:
Not a valid integer value
I would like to have a custom message instead, so I came up with this:
class RecordForm(Form):
rating = IntegerField('Rating',[validators.DataRequired("Helllo???")])
The custom message works now, but I get a side effect. 0 (zero) is no longer accepted as an integer value. What are my options here please?
Use InputRequired instead:
class RecordForm(Form):
rating = IntegerField('Rating',[validators.InputRequired("You got to enter some rating!")])
From the docs:
Note there is a distinction between this and DataRequired in that InputRequired looks that form-input data was provided, and DataRequired looks at the post-coercion data.
(Emphasis mine)
I'm searching how to hide the time and show only the date in the "new order" email:
I have seen that it's generated with this code :
({{var order.getCreatedAtFormated(''long'')}})
but I don't find a solution how to show only the date.
Thanks for help.
Supported formatting types are: long, medium , full, short
thanks for the comment:
HOW SHOULD I HELP MYSELF FINDING THIS OUT
first thing if you don't know how to interact wit method search for it in codebase as this reveals in what file the method is defined and you can see what parameters it takes in and how it processes the parameters
grep ' getCreatedAtFormated' app/code/ -rsn
app/code/core/Mage/Sales/Model/Order.php:1988: public function getCreatedAtFormated($format)
ok, now we found that file , open up and see the line 1988 has the method
/**
* Get formated order created date in store timezone
*
* #param string $format date format type (short|medium|long|full)
* #return string
*/
public function getCreatedAtFormated($format)
{
return Mage::helper('core')->formatDate($this->getCreatedAtStoreDate(), $format, true);
}
cool now you see it is actually using core helper's formatDate method. Go ahead open up that file
app/code/core/Mage/Core/Helper/Data.php:135: public function formatDate($date=null, $format='short', $showTime=false)
you can see from grep that it takes in third parameter that you can't pass to that method as it wraps this with forced in value.
So your solution is to use the helper and get the variable order.getCreatedAtStoreDate() and pass it to helpers formatting method