how to use locale in fullcalendar in angular 7

牧云@^-^@ 提交于 2020-01-23 12:31:46

问题


I need to change the language of my calendar in the angular version 7. I have not found much documentation about this. The main thing is to change the language of the days that appear on the calendar.

!-- begin snippet: js hide: false console: true babel: false -->

import { Component, OnInit, ViewChild } from '@angular/core';
import { CalendarComponent } from 'ng-fullcalendar';
import { Options } from 'fullcalendar';

@Component({
  selector: 'app-calendario',
  templateUrl: './calendario.component.html',
  styleUrls: ['./calendario.component.css']
})
export class CalendarioComponent implements OnInit {
  //calendario
  calendarOptions: Options;
  displayEvent: any;
  @ViewChild(CalendarComponent) ucCalendar: CalendarComponent;

  constructor() { }

  ngOnInit() {

    this.calendarOptions = {
      editable: true,
      eventLimit: false,
      header: {
        left: '',
        center: 'title',
        right: 'month'
      },

      events: []
    };
  }      

}

I try to add the property locale = 'es' in the calendarOptions, but it does not work, add this to my angular json, but I do not know how to implement it

     "scripts": [
              "node_modules/fullcalendar/dist/locale/es.js"
            ]

回答1:


You can do that using the FullCalendarComponent, setting the locale code.

@ViewChild('calendar') calendarComponent: FullCalendarComponent;

and in the ngOnInit, like that:

this.calendarComponent.locales = [ { code: 'pt-br' } ];

I hope that works for you.




回答2:


Thanks Gabriel I make it work with this approach

First make sure you have the import of your desire lenguage

import esLocale from '@fullcalendar/core/locales/es';
import frLocale from '@fullcalendar/core/locales/fr';

In your html file, in the full-calendar selector, you should assign values to locales and locale options.

    <full-calendar
    defaultView="dayGridMonth"
    [locales]="locales"
    locale="es"
    [weekends]="false"
    [plugins]="calendarPlugins"></full-calendar>

Then a variable that holds all the languages that you need

locales = [esLocale, frLocale];


来源:https://stackoverflow.com/questions/56889727/how-to-use-locale-in-fullcalendar-in-angular-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!