@nextcloud/l10n
Version:
Nextcloud localization and translation helpers for apps and libraries
166 lines (165 loc) • 8.3 kB
JavaScript
import { g as getCanonicalLocale, a as getLanguage } from "./chunks/translation-DoG5ZELJ.mjs";
import { b, e, i, l, d, r, c, s, t, t as t2, d as d2, u } from "./chunks/translation-DoG5ZELJ.mjs";
/*!
* 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(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 = 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 = 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 = 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 = 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 = 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: getLanguage(),
relativeTime: "long",
...opts
};
const date = new Date(timestamp);
const formatter = new Intl.RelativeTimeFormat([options.language, 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, getLanguage()], format);
return dateTimeFormatter.format(date);
}
export {
formatRelativeTime,
getCanonicalLocale,
getDayNames,
getDayNamesMin,
getDayNamesShort,
getFirstDay,
getLanguage,
b as getLocale,
getMonthNames,
getMonthNamesShort,
e as getPlural,
i as isRTL,
l as loadTranslations,
d as n,
r as register,
c as setLanguage,
s as setLocale,
t,
t2 as translate,
d2 as translatePlural,
u as unregister
};
//# sourceMappingURL=index.mjs.map