@nextcloud/l10n
Version:
Nextcloud localization and translation helpers for apps and libraries
165 lines (164 loc) • 8.91 kB
JavaScript
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const translation = require("./chunks/translation-oV9XBOJH.cjs");
/*!
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
function getFirstDay() {
if (typeof globalThis.firstDay !== "undefined") {
return globalThis.firstDay;
}
const intl = new Intl.Locale(translation.getCanonicalLocale());
const weekInfo = intl.getWeekInfo?.() ?? intl.weekInfo;
if (weekInfo) {
return weekInfo.firstDay % 7;
}
return 1;
}
function getDayNames() {
if (typeof globalThis.dayNames !== "undefined") {
return globalThis.dayNames;
}
const locale = translation.getCanonicalLocale();
return [
(/* @__PURE__ */ new Date("1970-01-04T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "long" }),
(/* @__PURE__ */ new Date("1970-01-05T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "long" }),
(/* @__PURE__ */ new Date("1970-01-06T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "long" }),
(/* @__PURE__ */ new Date("1970-01-07T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "long" }),
(/* @__PURE__ */ new Date("1970-01-08T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "long" }),
(/* @__PURE__ */ new Date("1970-01-09T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "long" }),
(/* @__PURE__ */ new Date("1970-01-10T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "long" })
];
}
function getDayNamesShort() {
if (typeof globalThis.dayNamesShort !== "undefined") {
return globalThis.dayNamesShort;
}
const locale = translation.getCanonicalLocale();
return [
(/* @__PURE__ */ new Date("1970-01-04T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "short" }),
(/* @__PURE__ */ new Date("1970-01-05T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "short" }),
(/* @__PURE__ */ new Date("1970-01-06T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "short" }),
(/* @__PURE__ */ new Date("1970-01-07T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "short" }),
(/* @__PURE__ */ new Date("1970-01-08T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "short" }),
(/* @__PURE__ */ new Date("1970-01-09T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "short" }),
(/* @__PURE__ */ new Date("1970-01-10T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "short" })
];
}
function getDayNamesMin() {
if (typeof globalThis.dayNamesMin !== "undefined") {
return globalThis.dayNamesMin;
}
const locale = translation.getCanonicalLocale();
return [
(/* @__PURE__ */ new Date("1970-01-04T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "narrow" }),
(/* @__PURE__ */ new Date("1970-01-05T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "narrow" }),
(/* @__PURE__ */ new Date("1970-01-06T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "narrow" }),
(/* @__PURE__ */ new Date("1970-01-07T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "narrow" }),
(/* @__PURE__ */ new Date("1970-01-08T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "narrow" }),
(/* @__PURE__ */ new Date("1970-01-09T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "narrow" }),
(/* @__PURE__ */ new Date("1970-01-10T00:00:00.000Z")).toLocaleDateString(locale, { weekday: "narrow" })
];
}
function getMonthNames() {
if (typeof globalThis.monthNames !== "undefined") {
return globalThis.monthNames;
}
const locale = translation.getCanonicalLocale();
return [
(/* @__PURE__ */ new Date("1970-01-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" }),
(/* @__PURE__ */ new Date("1970-02-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" }),
(/* @__PURE__ */ new Date("1970-03-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" }),
(/* @__PURE__ */ new Date("1970-04-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" }),
(/* @__PURE__ */ new Date("1970-05-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" }),
(/* @__PURE__ */ new Date("1970-06-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" }),
(/* @__PURE__ */ new Date("1970-07-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" }),
(/* @__PURE__ */ new Date("1970-08-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" }),
(/* @__PURE__ */ new Date("1970-09-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" }),
(/* @__PURE__ */ new Date("1970-10-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" }),
(/* @__PURE__ */ new Date("1970-11-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" }),
(/* @__PURE__ */ new Date("1970-12-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "long" })
];
}
function getMonthNamesShort() {
if (typeof globalThis.monthNamesShort !== "undefined") {
return globalThis.monthNamesShort;
}
const locale = translation.getCanonicalLocale();
return [
(/* @__PURE__ */ new Date("1970-01-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" }),
(/* @__PURE__ */ new Date("1970-02-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" }),
(/* @__PURE__ */ new Date("1970-03-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" }),
(/* @__PURE__ */ new Date("1970-04-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" }),
(/* @__PURE__ */ new Date("1970-05-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" }),
(/* @__PURE__ */ new Date("1970-06-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" }),
(/* @__PURE__ */ new Date("1970-07-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" }),
(/* @__PURE__ */ new Date("1970-08-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" }),
(/* @__PURE__ */ new Date("1970-09-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" }),
(/* @__PURE__ */ new Date("1970-10-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" }),
(/* @__PURE__ */ new Date("1970-11-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" }),
(/* @__PURE__ */ new Date("1970-12-01T00:00:00.000Z")).toLocaleDateString(locale, { month: "short" })
];
}
/*!
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
function formatRelativeTime(timestamp = Date.now(), opts = {}) {
const options = {
ignoreSeconds: false,
language: translation.getLanguage(),
relativeTime: "long",
...opts
};
const date = new Date(timestamp);
const formatter = new Intl.RelativeTimeFormat([options.language, translation.getLanguage()], { numeric: "auto", style: options.relativeTime });
const diff = date.getTime() - Date.now();
const seconds = diff / 1e3;
if (Math.abs(seconds) < 59.5) {
return options.ignoreSeconds || formatter.format(Math.round(seconds), "second");
}
const minutes = seconds / 60;
if (Math.abs(minutes) <= 59) {
return formatter.format(Math.round(minutes), "minute");
}
const hours = minutes / 60;
if (Math.abs(hours) < 23.5) {
return formatter.format(Math.round(hours), "hour");
}
const days = hours / 24;
if (Math.abs(days) < 6.5) {
return formatter.format(Math.round(days), "day");
}
if (Math.abs(days) < 27.5) {
const weeks = days / 7;
return formatter.format(Math.round(weeks), "week");
}
const months = days / 30;
const format = Math.abs(months) < 11 ? { month: options.relativeTime, day: "numeric" } : { year: options.relativeTime === "narrow" ? "2-digit" : "numeric", month: options.relativeTime };
const dateTimeFormatter = new Intl.DateTimeFormat([options.language, translation.getLanguage()], format);
return dateTimeFormatter.format(date);
}
exports.getCanonicalLocale = translation.getCanonicalLocale;
exports.getLanguage = translation.getLanguage;
exports.getLocale = translation.getLocale;
exports.getPlural = translation.getPlural;
exports.isRTL = translation.isRTL;
exports.loadTranslations = translation.loadTranslations;
exports.n = translation.translatePlural;
exports.register = translation.register;
exports.setLanguage = translation.setLanguage;
exports.setLocale = translation.setLocale;
exports.t = translation.translate;
exports.translate = translation.translate;
exports.translatePlural = translation.translatePlural;
exports.unregister = translation.unregister;
exports.formatRelativeTime = formatRelativeTime;
exports.getDayNames = getDayNames;
exports.getDayNamesMin = getDayNamesMin;
exports.getDayNamesShort = getDayNamesShort;
exports.getFirstDay = getFirstDay;
exports.getMonthNames = getMonthNames;
exports.getMonthNamesShort = getMonthNamesShort;
//# sourceMappingURL=index.cjs.map