I'm having difficulties in finding out how to translate the time axis. I'm using MMM YYYY for time displayFormats in xAxes.
It always displays date like May 2018. Does anyone know how to localize here?
For example, if the language is french, the month should be displayed as Mai instead of May. I searched everywhere, only find someone said it is possible to do that using time.parser, but I am not sure how to do that.
Any suggestions would be appreciated.
I was struggling with the same problem in my Ruby on Rails application.
We don't use angularjs, but I think the way of using Chart.js is very similar.
I will post the way I managed it to work in Ruby on Rails and polish locale. But you should be able to easy customize the solution to work with Angular.js
Include moment.js locale in the JavaScript bundle apart of moment.js library
//= require moment
//= require moment/pl.js
Add custom displayFormats to make it easier to parse date in callback function. And add callback function to parse and format date again.
options: {
...
scales: {
xAxes: [{
type: 'time',
time: {
displayFormats: {
'hour': 'HH:mm',
'day': 'DD-MM-YYYY',
'week': 'DD-MM-YYYY',
'month': 'DD-MM-YYYY',
},
unit: '<%= #report.scale %>',
},
ticks: {
callback: function(value, index) {
let displayFormats = {
'hour': 'HH:mm',
'day': 'DD-MM-YYYY',
'week': 'YYYY WW',
'month': 'MMMM YYYY',
};
let unit = '<%= #report.scale %>';
let format = displayFormats[unit];
return moment(value, 'DD-MM-YYYY').format(format, value);
}
}
}],
For some reason moment.js inside of Chart.js ignores locales. But when calling moment.js again inside of the callback function it works well.
I added guard return for all units other than month. I didn't want to reparse and reformat dates other than months.
Related
I am using react-i18next for the first time and I want to translate the string of date format. how can I do it using react-i18next?
this is the format the date is in
Sat Jul 27 2019 00:00:00 GMT+0300
how do I translate it into another language?
could someone help me with this? thanks.
You can format a date like so in your translations
"key": "Current date: {{date, dd/MM/yyyy}}"
Have a look at the i18next official docs about formatting.
You can initialise i18next providing a function for interpolation, like so;
i18next.init({
interpolation: {
formatSeparator: ',',
format: function(value, formatting, lng){
if(value instanceof Date) return moment(value).format(formatting);
return value.toString();
}
}
});
The result:
i18next.t('key', { date: new Date() }); // -> Current date: 13/07/2019
source: https://github.com/i18next/i18next/issues/774#issuecomment-232396505
I am using this example https://l-lin.github.io/angular-datatables/archives/#!/bootstrapIntegration to configure my data tables. The problem is it won't sort the date and double price.
So far I try to sort the date but failed. I did find a lot of answers but no one is working.
My javascript
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withPaginationType('full_numbers')
.withOption('order', [0, 'desc']);
$scope.dtColumnDefs = [
{ targets: 0, type: 'date' }
];
My html
<table datatable="" dt-options="dtOptions" dt-column-defs="dtColumnDefs" class="row-border hover"></table
I also tried something like
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0).withOption('type', 'date'),
];
And I did tried change the date to dd/MM/yy but not working. My date in column is showed as 23/03/19
DataTables' date sorting is based on Date.parse() so any not-parseable date (or timestamp) will break the sorting.
A date in north european notation ala 23/03/19 parses to NaN, and there you have your problem. You can parse the date in a render() callback :
DTColumnDefBuilder.newColumnDef(0).renderWidth(function(data) {
data = data.split('/')
return Date.parse(data[1]+'-'+data[0]+'-'+data[2]).valueOf()
})
or you can use a custom sorting plugin like date-eu -> https://datatables.net/plug-ins/sorting/date-eu
I am using DayPickerInput in my react application. I know how to use before and after to limit the date selection but those options doesn't work together (for me). However individually they do work well and restrict date selection.
<DayPickerInput
dayPickerProps={{
disabledDays: {
before: today,
after: afterDate
}
}}
/>
Can anyone please help?
You can disable days by following way with your DayPickerInput:
dayPickerProps={{
disabledDays: [
{ before: moment().subtract(1, 'months').toDate() },
{ after: moment().toDate() },
]
}}
So I'm using the BlueprintJS datetime package in a React project to render a birthday picker and I want to set the months names of the select to the Spanish version. In their documentation says they use react-day-picker in order to render the calendar and from the react-day-picker documentation there's a parameter to set the months names from an array but I don't get it to change the select names. This is what I've set in the component. The weekdaysLong and weekdaysShort works fine but not the months property.
<DateInput
formatDate={date => date.toLocaleString('es-ES', {year: "numeric", month: "2-digit", day: "numeric"})}
onChange={this.handleDateChange}
parseDate => new Date(str)}
placeholder={"DD/MM/YYYY"}
maxDate={now}
minDate={minDate}
value={this.state.date}
dayPickerProps={{
locale: 'es',
months: DateFormatString.months,
weekdaysLong: DateFormatString.weekDaysLong,
weekdaysShort: DateFormatString.weekDaysShort,
firstDayOfWeek: 1,
}}
/>
And this is the variable where I have the months and weekdays
const DateFormatString = {
months: [
'Enero',
'Febrero',
'Marzo',
'Abril',
'Mayo',
'Junio',
'Julio',
'Agosto',
'Septiembre',
'Octubre',
'Noviembre',
'Diciembre'
],
weekDaysLong: [
'Domingo',
'Lunes',
'Martes',
'Miercoles',
'Jueves',
'Viernes',
'Sabado'
],
weekDaysShort: [
'Do',
'Lu',
'Ma',
'Mi',
'Ju',
'Vi',
'Sa'
]
}
Anyone have an idea what is happening or know another way to set the whole component's language?
It seems to be a recently opened (and soon fixed) issue as per this github issue page: https://github.com/palantir/blueprint/issues/3265
Either you can wait for a fix to be merged (and then update your package.json to use the new version), or you must use some other library. Hope that helps!
I am working on a scheduling app using the Angular-Gantt.js module.
It is working fine --> except I'd like to customize the header to display "M,T,W,Th,F ..." for the columns in the day viewscale. Currently it displays like this demo version -->
https://www.angular-gantt.com/demo/
From the documentation for the module, there are events triggered after the headers are created and displayed and not when the header is being created. There is however a guide on how to write a plugin. I am wondering if anyone has tackled this issue and could point me in right direction.
Many Thanks,
Ravi
Yes, it is possible. Just add the headers-formats option on the gantt directive in the html and add the following code to your $scope.option:
In the html:
<div gantt
header-formats="options.headersFormats">
<div>
In the controller:
$scope.option: {
//other options
headersFormats: {
'year': 'YYYY',
'quarter': '[Q]Q YYYY',
month: 'MMMM YYYY',
week: function(column) {
return column.date.format('MMM D [-]') + column.endDate.format('[ ]MMM D');
},
day: 'ddd',
hour: 'H',
minute:'HH:mm'
},
}
Setting the 'day' property of the headersFormats to 'ddd' will make it to display the dates as 'Mon', 'Tue', 'Wed' e.t.c.