@nextcloud/l10n
Version:
Nextcloud localization and translation helpers for apps and libraries
165 lines (164 loc) • 7.31 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 [
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 = translation.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 = translation.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 = translation.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 = translation.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: 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