@nextcloud/l10n
Version:
Nextcloud localization and translation helpers for apps and libraries
166 lines (165 loc) • 6.7 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 [
new Date(1970, 0, 4).toLocaleDateString(locale, { weekday: "long" }),
new Date(1970, 0, 5).toLocaleDateString(locale, { weekday: "long" }),
new Date(1970, 0, 6).toLocaleDateString(locale, { weekday: "long" }),
new Date(1970, 0, 7).toLocaleDateString(locale, { weekday: "long" }),
new Date(1970, 0, 8).toLocaleDateString(locale, { weekday: "long" }),
new Date(1970, 0, 9).toLocaleDateString(locale, { weekday: "long" }),
new Date(1970, 0, 10).toLocaleDateString(locale, { weekday: "long" })
];
}
function getDayNamesShort() {
if (typeof globalThis.dayNamesShort !== "undefined") {
return globalThis.dayNamesShort;
}
const locale = getCanonicalLocale();
return [
new Date(1970, 0, 4).toLocaleDateString(locale, { weekday: "short" }),
new Date(1970, 0, 5).toLocaleDateString(locale, { weekday: "short" }),
new Date(1970, 0, 6).toLocaleDateString(locale, { weekday: "short" }),
new Date(1970, 0, 7).toLocaleDateString(locale, { weekday: "short" }),
new Date(1970, 0, 8).toLocaleDateString(locale, { weekday: "short" }),
new Date(1970, 0, 9).toLocaleDateString(locale, { weekday: "short" }),
new Date(1970, 0, 10).toLocaleDateString(locale, { weekday: "short" })
];
}
function getDayNamesMin() {
if (typeof globalThis.dayNamesMin !== "undefined") {
return globalThis.dayNamesMin;
}
const locale = getCanonicalLocale();
return [
new Date(1970, 0, 4).toLocaleDateString(locale, { weekday: "narrow" }),
new Date(1970, 0, 5).toLocaleDateString(locale, { weekday: "narrow" }),
new Date(1970, 0, 6).toLocaleDateString(locale, { weekday: "narrow" }),
new Date(1970, 0, 7).toLocaleDateString(locale, { weekday: "narrow" }),
new Date(1970, 0, 8).toLocaleDateString(locale, { weekday: "narrow" }),
new Date(1970, 0, 9).toLocaleDateString(locale, { weekday: "narrow" }),
new Date(1970, 0, 10).toLocaleDateString(locale, { weekday: "narrow" })
];
}
function getMonthNames() {
if (typeof globalThis.monthNames !== "undefined") {
return globalThis.monthNames;
}
const locale = getCanonicalLocale();
return [
new Date(1970, 0).toLocaleDateString(locale, { month: "long" }),
new Date(1970, 1).toLocaleDateString(locale, { month: "long" }),
new Date(1970, 2).toLocaleDateString(locale, { month: "long" }),
new Date(1970, 3).toLocaleDateString(locale, { month: "long" }),
new Date(1970, 4).toLocaleDateString(locale, { month: "long" }),
new Date(1970, 5).toLocaleDateString(locale, { month: "long" }),
new Date(1970, 6).toLocaleDateString(locale, { month: "long" }),
new Date(1970, 7).toLocaleDateString(locale, { month: "long" }),
new Date(1970, 8).toLocaleDateString(locale, { month: "long" }),
new Date(1970, 9).toLocaleDateString(locale, { month: "long" }),
new Date(1970, 10).toLocaleDateString(locale, { month: "long" }),
new Date(1970, 11).toLocaleDateString(locale, { month: "long" })
];
}
function getMonthNamesShort() {
if (typeof globalThis.monthNamesShort !== "undefined") {
return globalThis.monthNamesShort;
}
const locale = getCanonicalLocale();
return [
new Date(1970, 0).toLocaleDateString(locale, { month: "short" }),
new Date(1970, 1).toLocaleDateString(locale, { month: "short" }),
new Date(1970, 2).toLocaleDateString(locale, { month: "short" }),
new Date(1970, 3).toLocaleDateString(locale, { month: "short" }),
new Date(1970, 4).toLocaleDateString(locale, { month: "short" }),
new Date(1970, 5).toLocaleDateString(locale, { month: "short" }),
new Date(1970, 6).toLocaleDateString(locale, { month: "short" }),
new Date(1970, 7).toLocaleDateString(locale, { month: "short" }),
new Date(1970, 8).toLocaleDateString(locale, { month: "short" }),
new Date(1970, 9).toLocaleDateString(locale, { month: "short" }),
new Date(1970, 10).toLocaleDateString(locale, { month: "short" }),
new Date(1970, 11).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