mirror of
https://github.com/flameshikari/outline-ru.git
synced 2026-06-13 04:05:10 +03:00
remove shared dir
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
import { locales } from "../utils/date";
|
||||
|
||||
type LanguageOption = {
|
||||
label: string;
|
||||
value: keyof typeof locales;
|
||||
};
|
||||
|
||||
// Note: Updating the available languages? Make sure to also update the
|
||||
// locales array in shared/utils/date.ts to enable translation for timestamps.
|
||||
export const languageOptions: LanguageOption[] = [
|
||||
{
|
||||
label: "Русский (Russian)",
|
||||
value: "ru_RU",
|
||||
},
|
||||
{
|
||||
label: "English (US)",
|
||||
value: "en_US",
|
||||
},
|
||||
{
|
||||
label: "Čeština (Czech)",
|
||||
value: "cs_CZ",
|
||||
},
|
||||
{
|
||||
label: "简体中文 (Chinese, Simplified)",
|
||||
value: "zh_CN",
|
||||
},
|
||||
{
|
||||
label: "繁體中文 (Chinese, Traditional)",
|
||||
value: "zh_TW",
|
||||
},
|
||||
{
|
||||
label: "Deutsch (German)",
|
||||
value: "de_DE",
|
||||
},
|
||||
{
|
||||
label: "Español (Spanish)",
|
||||
value: "es_ES",
|
||||
},
|
||||
{
|
||||
label: "Français (French)",
|
||||
value: "fr_FR",
|
||||
},
|
||||
{
|
||||
label: "Italiano (Italian)",
|
||||
value: "it_IT",
|
||||
},
|
||||
{
|
||||
label: "日本語 (Japanese)",
|
||||
value: "ja_JP",
|
||||
},
|
||||
{
|
||||
label: "한국어 (Korean)",
|
||||
value: "ko_KR",
|
||||
},
|
||||
{
|
||||
label: "Nederland (Dutch, Netherlands)",
|
||||
value: "nl_NL",
|
||||
},
|
||||
{
|
||||
label: "Norsk Bokmål (Norwegian)",
|
||||
value: "nb_NO",
|
||||
},
|
||||
{
|
||||
label: "Português (Portuguese, Brazil)",
|
||||
value: "pt_BR",
|
||||
},
|
||||
{
|
||||
label: "Português (Portuguese, Portugal)",
|
||||
value: "pt_PT",
|
||||
},
|
||||
{
|
||||
label: "Polskie (Polish)",
|
||||
value: "pl_PL",
|
||||
},
|
||||
{
|
||||
label: "فارسی (Persian)",
|
||||
value: "fa_IR",
|
||||
},
|
||||
{
|
||||
label: "Svenska (Swedish)",
|
||||
value: "sv_SE",
|
||||
},
|
||||
{
|
||||
label: "Türkçe (Turkish)",
|
||||
value: "tr_TR",
|
||||
},
|
||||
{
|
||||
label: "Українська (Ukrainian)",
|
||||
value: "uk_UA",
|
||||
},
|
||||
{
|
||||
label: "Tiếng Việt (Vietnamese)",
|
||||
value: "vi_VN",
|
||||
},
|
||||
];
|
||||
|
||||
export const languages = languageOptions.map((i) => i.value);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,198 +0,0 @@
|
||||
/* eslint-disable import/no-duplicates */
|
||||
import {
|
||||
Locale,
|
||||
addSeconds,
|
||||
formatDistanceToNow,
|
||||
subDays,
|
||||
subMonths,
|
||||
subWeeks,
|
||||
subYears,
|
||||
} from "date-fns";
|
||||
import {
|
||||
cs,
|
||||
de,
|
||||
enUS,
|
||||
es,
|
||||
faIR,
|
||||
fr,
|
||||
it,
|
||||
ja,
|
||||
ko,
|
||||
nb,
|
||||
nl,
|
||||
ptBR,
|
||||
pt,
|
||||
pl,
|
||||
ru,
|
||||
sv,
|
||||
tr,
|
||||
vi,
|
||||
uk,
|
||||
zhCN,
|
||||
zhTW,
|
||||
} from "date-fns/locale";
|
||||
import type { DateFilter } from "../types";
|
||||
|
||||
export function subtractDate(date: Date, period: DateFilter) {
|
||||
switch (period) {
|
||||
case "day":
|
||||
return subDays(date, 1);
|
||||
|
||||
case "week":
|
||||
return subWeeks(date, 1);
|
||||
|
||||
case "month":
|
||||
return subMonths(date, 1);
|
||||
|
||||
case "year":
|
||||
return subYears(date, 1);
|
||||
|
||||
default:
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a humanized relative time string for the given date.
|
||||
*
|
||||
* @param date The date to convert
|
||||
* @param options The options to pass to date-fns
|
||||
* @returns The relative time string
|
||||
*/
|
||||
export function dateToRelative(
|
||||
date: Date | number,
|
||||
options?: {
|
||||
includeSeconds?: boolean;
|
||||
addSuffix?: boolean;
|
||||
locale?: Locale | undefined;
|
||||
shorten?: boolean;
|
||||
}
|
||||
) {
|
||||
const now = new Date();
|
||||
const parsedDateTime = new Date(date);
|
||||
|
||||
// Protect against "in less than a minute" when users computer clock is off.
|
||||
const normalizedDateTime =
|
||||
parsedDateTime > now && parsedDateTime < addSeconds(now, 60)
|
||||
? now
|
||||
: parsedDateTime;
|
||||
|
||||
const output = formatDistanceToNow(normalizedDateTime, options);
|
||||
|
||||
// Some tweaks to make english language shorter.
|
||||
if (options?.shorten) {
|
||||
return output
|
||||
.replace("about", "")
|
||||
.replace("less than a minute ago", "just now")
|
||||
.replace("minute", "min");
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a locale string from Unicode CLDR format to BCP47 format.
|
||||
*
|
||||
* @param locale The locale string to convert
|
||||
* @returns The converted locale string
|
||||
*/
|
||||
export function unicodeCLDRtoBCP47(locale: string) {
|
||||
return locale.replace("_", "-").replace("root", "und");
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a locale string from BCP47 format to Unicode CLDR format.
|
||||
*
|
||||
* @param locale The locale string to convert
|
||||
* @returns The converted locale string
|
||||
*/
|
||||
export function unicodeBCP47toCLDR(locale: string) {
|
||||
return locale.replace("-", "_").replace("und", "root");
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a locale string from Unicode CLDR format to ISO 639 format.
|
||||
*
|
||||
* @param locale The locale string to convert
|
||||
* @returns The converted locale string
|
||||
*/
|
||||
export function unicodeCLDRtoISO639(locale: string) {
|
||||
return locale.split("_")[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current date as a string formatted depending on current locale.
|
||||
*
|
||||
* @returns The current date
|
||||
*/
|
||||
export function getCurrentDateAsString(locale?: Intl.LocalesArgument) {
|
||||
return new Date().toLocaleDateString(locale, {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current time as a string formatted depending on current locale.
|
||||
*
|
||||
* @returns The current time
|
||||
*/
|
||||
export function getCurrentTimeAsString(locale?: Intl.LocalesArgument) {
|
||||
return new Date().toLocaleTimeString(locale, {
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current date and time as a string formatted depending on current
|
||||
* locale.
|
||||
*
|
||||
* @returns The current date and time
|
||||
*/
|
||||
export function getCurrentDateTimeAsString(locale?: Intl.LocalesArgument) {
|
||||
return new Date().toLocaleString(locale, {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
});
|
||||
}
|
||||
|
||||
const locales = {
|
||||
cs_CZ: cs,
|
||||
de_DE: de,
|
||||
en_US: enUS,
|
||||
es_ES: es,
|
||||
fa_IR: faIR,
|
||||
fr_FR: fr,
|
||||
it_IT: it,
|
||||
ja_JP: ja,
|
||||
ko_KR: ko,
|
||||
nb_NO: nb,
|
||||
nl_NL: nl,
|
||||
pt_BR: ptBR,
|
||||
pt_PT: pt,
|
||||
pl_PL: pl,
|
||||
ru_RU: ru,
|
||||
sv_SE: sv,
|
||||
tr_TR: tr,
|
||||
uk_UA: uk,
|
||||
vi_VN: vi,
|
||||
zh_CN: zhCN,
|
||||
zh_TW: zhTW,
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the date-fns locale object for the given user language preference.
|
||||
*
|
||||
* @param language The user language
|
||||
* @returns The date-fns locale.
|
||||
*/
|
||||
export function dateLocale(language: keyof typeof locales | undefined | null) {
|
||||
return language ? locales[language] : undefined;
|
||||
}
|
||||
|
||||
export { locales };
|
||||
Reference in New Issue
Block a user