Skip to content

Commit

Permalink
chore: copy nb locale
Browse files Browse the repository at this point in the history
  • Loading branch information
audunru committed Mar 4, 2024
1 parent 6f44a16 commit 87016c1
Show file tree
Hide file tree
Showing 7 changed files with 991 additions and 0 deletions.
110 changes: 110 additions & 0 deletions src/locale/se/_lib/formatDistance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import type { FormatDistanceFn, FormatDistanceLocale } from "../../../types.js";

type FormatDistanceTokenValue =
| string
| {
one: string;
other: string;
};

const formatDistanceLocale: FormatDistanceLocale<FormatDistanceTokenValue> = {
lessThanXSeconds: {
one: "mindre enn ett sekund",
other: "mindre enn {{count}} sekunder",
},

xSeconds: {
one: "ett sekund",
other: "{{count}} sekunder",
},

halfAMinute: "et halvt minutt",

lessThanXMinutes: {
one: "mindre enn ett minutt",
other: "mindre enn {{count}} minutter",
},

xMinutes: {
one: "ett minutt",
other: "{{count}} minutter",
},

aboutXHours: {
one: "omtrent en time",
other: "omtrent {{count}} timer",
},

xHours: {
one: "en time",
other: "{{count}} timer",
},

xDays: {
one: "en dag",
other: "{{count}} dager",
},

aboutXWeeks: {
one: "omtrent en uke",
other: "omtrent {{count}} uker",
},

xWeeks: {
one: "en uke",
other: "{{count}} uker",
},

aboutXMonths: {
one: "omtrent en måned",
other: "omtrent {{count}} måneder",
},

xMonths: {
one: "en måned",
other: "{{count}} måneder",
},

aboutXYears: {
one: "omtrent ett år",
other: "omtrent {{count}} år",
},

xYears: {
one: "ett år",
other: "{{count}} år",
},

overXYears: {
one: "over ett år",
other: "over {{count}} år",
},

almostXYears: {
one: "nesten ett år",
other: "nesten {{count}} år",
},
};

export const formatDistance: FormatDistanceFn = (token, count, options) => {
let result;

const tokenValue = formatDistanceLocale[token];
if (typeof tokenValue === "string") {
result = tokenValue;
} else if (count === 1) {
result = tokenValue.one;
} else {
result = tokenValue.other.replace("{{count}}", String(count));
}

if (options?.addSuffix) {
if (options.comparison && options.comparison > 0) {
return "om " + result;
} else {
return result + " siden";
}
}

return result;
};
40 changes: 40 additions & 0 deletions src/locale/se/_lib/formatLong/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { FormatLong } from "../../../types.js";
import { buildFormatLongFn } from "../../../_lib/buildFormatLongFn/index.js";

const dateFormats = {
full: "EEEE d. MMMM y",
long: "d. MMMM y",
medium: "d. MMM y",
short: "dd.MM.y",
};

const timeFormats = {
full: "'kl'. HH:mm:ss zzzz",
long: "HH:mm:ss z",
medium: "HH:mm:ss",
short: "HH:mm",
};

const dateTimeFormats = {
full: "{{date}} 'kl.' {{time}}",
long: "{{date}} 'kl.' {{time}}",
medium: "{{date}} {{time}}",
short: "{{date}} {{time}}",
};

export const formatLong: FormatLong = {
date: buildFormatLongFn({
formats: dateFormats,
defaultWidth: "full",
}),

time: buildFormatLongFn({
formats: timeFormats,
defaultWidth: "full",
}),

dateTime: buildFormatLongFn({
formats: dateTimeFormats,
defaultWidth: "full",
}),
};
17 changes: 17 additions & 0 deletions src/locale/se/_lib/formatRelative/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { FormatRelativeFn } from "../../../types.js";

const formatRelativeLocale = {
lastWeek: "'forrige' eeee 'kl.' p",
yesterday: "'i går kl.' p",
today: "'i dag kl.' p",
tomorrow: "'i morgen kl.' p",
nextWeek: "EEEE 'kl.' p",
other: "P",
};

export const formatRelative: FormatRelativeFn = (
token,
_date,
_baseDate,
_options,
) => formatRelativeLocale[token];
129 changes: 129 additions & 0 deletions src/locale/se/_lib/localize/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import type { Localize, LocalizeFn } from "../../../types.js";
import { buildLocalizeFn } from "../../../_lib/buildLocalizeFn/index.js";

const eraValues = {
narrow: ["f.Kr.", "e.Kr."] as const,
abbreviated: ["f.Kr.", "e.Kr."] as const,
wide: ["før Kristus", "etter Kristus"] as const,
};

const quarterValues = {
narrow: ["1", "2", "3", "4"] as const,
abbreviated: ["Q1", "Q2", "Q3", "Q4"] as const,
wide: ["1. kvartal", "2. kvartal", "3. kvartal", "4. kvartal"] as const,
};

const monthValues = {
narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"] as const,
abbreviated: [
"jan.",
"feb.",
"mars",
"apr.",
"mai",
"juni",
"juli",
"aug.",
"sep.",
"okt.",
"nov.",
"des.",
] as const,
wide: [
"januar",
"februar",
"mars",
"april",
"mai",
"juni",
"juli",
"august",
"september",
"oktober",
"november",
"desember",
] as const,
};

const dayValues = {
narrow: ["S", "M", "T", "O", "T", "F", "L"] as const,
short: ["sø", "ma", "ti", "on", "to", "fr", "lø"] as const,
abbreviated: ["søn", "man", "tir", "ons", "tor", "fre", "lør"] as const,
wide: [
"søndag",
"mandag",
"tirsdag",
"onsdag",
"torsdag",
"fredag",
"lørdag",
] as const,
};

const dayPeriodValues = {
narrow: {
am: "a",
pm: "p",
midnight: "midnatt",
noon: "middag",
morning: "på morg.",
afternoon: "på etterm.",
evening: "på kvelden",
night: "på natten",
},
abbreviated: {
am: "a.m.",
pm: "p.m.",
midnight: "midnatt",
noon: "middag",
morning: "på morg.",
afternoon: "på etterm.",
evening: "på kvelden",
night: "på natten",
},
wide: {
am: "a.m.",
pm: "p.m.",
midnight: "midnatt",
noon: "middag",
morning: "på morgenen",
afternoon: "på ettermiddagen",
evening: "på kvelden",
night: "på natten",
},
};

const ordinalNumber: LocalizeFn<number> = (dirtyNumber, _options) => {
const number = Number(dirtyNumber);
return number + ".";
};

export const localize: Localize = {
ordinalNumber,

era: buildLocalizeFn({
values: eraValues,
defaultWidth: "wide",
}),

quarter: buildLocalizeFn({
values: quarterValues,
defaultWidth: "wide",
argumentCallback: (quarter) => quarter - 1,
}),

month: buildLocalizeFn({
values: monthValues,
defaultWidth: "wide",
}),

day: buildLocalizeFn({
values: dayValues,
defaultWidth: "wide",
}),

dayPeriod: buildLocalizeFn({
values: dayPeriodValues,
defaultWidth: "wide",
}),
};

0 comments on commit 87016c1

Please sign in to comment.