简体   繁体   English

Fullcalendar 语言环境不会更改 v5 中的 header 栏

[英]Fullcalendar locale not changing header bar in v5

I'm having issues changing the locale of the headerToolbar of the fullcalendar.我在更改 fullcalendar 的 headerToolbar 的语言环境时遇到问题。

What's weird is that it works on month and day names, just not the header.奇怪的是它适用于月份和日期名称,而不是 header。

在此处输入图像描述

Code looks like this:代码如下所示:

let calendar = new FullCalendar.Calendar(calendarEl, {
    headerToolbar: {
        locale: getLanguage(),
        left: 'prev,next',
        center: 'title',
        right: 'timeGridWeek,dayGridMonth,listWeek',
    },
    initialView: 'timeGridWeek',
    weekNumbers: true,
    weekText: "",
    weekends: false,
    firstDay: 1,
    slotMinTime: "07:00:00",
    slotMaxTime: "18:00:00",
    eventTimeFormat: {
        hour: '2-digit',
        minute: '2-digit',
        hour12: false, 
    },
    locale: getLanguage(),
    eventDisplay: "block",
    eventTextColor: "#fff"
});

getLanguage() returns the browsers language, in my case it should (and do) return no-NB. getLanguage() 返回浏览器语言,在我的情况下它应该(并且确实)返回 no-NB。

function getLanguage() {
    let result = window.localStorage[LANGUAGE];
    return result ? result : navigator.language || navigator.userLanguage || 'no';
}

How come it doesn't change the localization of the headerToolbar?为什么它不改变 headerToolbar 的本地化?

When you talk about the localisation of the header toolbar, I assume you're talking specifically about the names of the views in the buttons, because the date part of the header has clearly been localised already.当您谈论 header 工具栏的本地化时,我假设您是在专门讨论按钮中视图的名称,因为 header 的日期部分显然已经本地化。

The answer why that doesn't change in your case is simply because fullCalendar's locale file doesn't contain an entry for no or no-NB (Norway).在您的情况下为什么没有改变的答案仅仅是因为 fullCalendar 的语言环境文件不包含nono-NB (挪威)的条目。 Therefore there is no text fullCalendar can use to replace the names of the views and other buttons.因此没有文本 fullCalendar 可以用来替换视图和其他按钮的名称。

At the time of writing, you can view the latest version athttps://cdn.jsdelivr.net/npm/fullcalendar@5.10.1/locales-all.js and see there is no entry for that region code.在撰写本文时,您可以在https://cdn.jsdelivr.net/npm/fullcalendar@5.10.1/locales-all.js查看最新版本,并看到该区域代码没有条目。

There is, however an entry for nb , which I believe is Norwegian Bokmål.但是,有一个nb条目,我相信它是挪威 Bokmål。 So you could use that, if it's appropriate.因此,如果合适,您可以使用它。

One alternative solution is to modify the locales file to add your own entry for the language code(s) you want to support in your calendar.一种替代解决方案是修改语言环境文件,为您希望在日历中支持的语言代码添加您自己的条目。 (If you take this approach, you could also submit your contribution to the fullCalendar project as well, to see if they would accept it into the files supplied by default with the next release.) (如果你采用这种方法,你也可以将你的贡献提交给 fullCalendar 项目,看看他们是否会接受它到下一个版本默认提供的文件中。)

Another alternative solution is to create custom view settings for each view, where you can define your own button text, even for the built-in views.另一种替代解决方案是为每个视图创建自定义视图设置,您可以在其中定义自己的按钮文本,即使对于内置视图也是如此。

(PS The reason the dates are still localised in your example is because that's actually done by the JS Date library built in to your browser's JavaScript engine. FullCalendar merely uses the results of that. Its locale settings, when available, may override certain aspects of the presentation, but otherwise it will just use whatever the browser produces by default.) (PS 在您的示例中日期仍然本地化的原因是因为这实际上是由浏览器的 JavaScript 引擎中内置的 JS Date 库完成的。FullCalendar 仅使用结果。它的区域设置(如果可用)可能会覆盖演示文稿,否则它将仅使用浏览器默认生成的任何内容。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM