如何在 angular 7 的 fullcalendar 中使用语言环境 [英] how to use locale in fullcalendar in angular 7
问题描述
我需要在 angular 版本 7 中更改日历的语言.我没有找到太多关于此的文档.主要是更改日历上显示的日期的语言.
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.
!-- 开始片段:js hide: false console: true babel: false -->
!-- 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: []
};
}
}
我尝试在 calendarOptions 中添加属性 locale = 'es',但它不起作用,将此添加到我的 angular json,但我不知道如何实现它
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"
]
推荐答案
感谢 Gabriel 我用这种方法让它工作
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';
在您的 html 文件中,在完整日历选择器中,您应该为区域设置和区域设置选项分配值.
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];
这篇关于如何在 angular 7 的 fullcalendar 中使用语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!