Skip to content

Commit

Permalink
feat(date-fns#3343) Add support for Filipino locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Adityan Kannan authored and Adityan Kannan committed Apr 12, 2023
1 parent fadbd4e commit cfa445e
Show file tree
Hide file tree
Showing 7 changed files with 1,062 additions and 0 deletions.
112 changes: 112 additions & 0 deletions src/locale/fil/_lib/formatDistance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import type { FormatDistanceFn, FormatDistanceLocale } from '../../../types'

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

const formatDistanceLocale: FormatDistanceLocale<FormatDistanceTokenValue> = {
lessThanXSeconds: {
one: 'wala pang isang segundo',
other: 'wala pang {{count}} na segundo',
},

xSeconds: {
one: 'isang segundo',
other: '{{count}} segundo',
},

halfAMinute: 'kalahating minuto',

lessThanXMinutes: {
one: 'wala pang isang minuto',
other: 'wala pang {{count}} na minuto',
},

xMinutes: {
one: 'isang minuto',
other: '{{count}} minuto',
},

aboutXHours: {
one: 'mga isang oras',
other: 'mga {{count}} na oras',
},

xHours: {
one: 'isang oras',
other: '{{count}} na oras',
},

xDays: {
one: 'isang araw',
other: '{{count}} na araw',
},

aboutXWeeks: {
one: 'mga isang linggo',
other: 'mga {{count}} na linggo',
},

xWeeks: {
one: 'isang linggo',
other: '{{count}} na linggo',
},

aboutXMonths: {
one: 'mga isang buwan',
other: 'mga {{count}} na buwan',
},

xMonths: {
one: 'isang buwan',
other: '{{count}} na buwan',
},

aboutXYears: {
one: 'mga isang taon',
other: 'mga {{count}} na taon',
},

xYears: {
one: 'isang taon',
other: '{{count}} na taon',
},

overXYears: {
one: 'mahigit isang taon',
other: 'mahigit {{count}} na taon',
},

almostXYears: {
one: 'halos isang taon',
other: 'halos {{count}} na taon',
},
}

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}}', count.toString())
}

if (options?.addSuffix) {
if (options.comparison && options.comparison > 0) {
return 'sa ' + result
} else {
return result + ' nakaraan'
}
}

return result
}

export default formatDistance
42 changes: 42 additions & 0 deletions src/locale/fil/_lib/formatLong/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index'
import type { FormatLong } from '../../../types'

const dateFormats = {
full: 'EEEE, MMMM do, y',
long: 'MMMM do, y',
medium: 'MMM d, y',
short: 'MM/dd/yyyy',
}

const timeFormats = {
full: 'h:mm:ss a zzzz',
long: 'h:mm:ss a z',
medium: 'h:mm:ss a',
short: 'h:mm a',
}

const dateTimeFormats = {
full: "{{date}} 'at' {{time}}",
long: "{{date}} 'at' {{time}}",
medium: '{{date}}, {{time}}',
short: '{{date}}, {{time}}',
}

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

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

dateTime: buildFormatLongFn({
formats: dateTimeFormats,
defaultWidth: 'full',
}),
}

export default formatLong
15 changes: 15 additions & 0 deletions src/locale/fil/_lib/formatRelative/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { FormatRelativeFn } from '../../../types'

const formatRelativeLocale = {
lastWeek: "'last' eeee 'at' p",
yesterday: "'yesterday at' p",
today: "'today at' p",
tomorrow: "'tomorrow at' p",
nextWeek: "eeee 'at' p",
other: 'P',
}

const formatRelative: FormatRelativeFn = (token, _date, _baseDate, _options) =>
formatRelativeLocale[token]

export default formatRelative
199 changes: 199 additions & 0 deletions src/locale/fil/_lib/localize/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import type { Quarter } from '../../../../types'
import type { Localize, LocalizeFn } from '../../../types'
import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index'

const eraValues = {
narrow: ['B', 'A'] as const,
abbreviated: ['BC', 'AD'] as const,
wide: ['Before Christ', 'Anno Domini'] as const,
}

const quarterValues = {
narrow: ['1', '2', '3', '4'] as const,
abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'] as const,
wide: [
'Unang sangkapat',
'Ikalawang sangkapat',
'Ikatlong sangkapat',
'Ikaapat sangkapat',
] as const,
}

// Note: in English, the names of days of the week and months are capitalized.
// If you are making a new locale based on this one, check if the same is true for the language you're working on.
// Generally, formatted dates should look like they are in the middle of a sentence,
// e.g. in Spanish language the weekdays and months should be in the lowercase.
const monthValues = {
narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'] as const,
abbreviated: [
'Enero',
'Peb',
'Marso',
'Abr',
'Mayo',
'Hun',
'Hul',
'Agosto',
'Set',
'Okt',
'Nob',
'Dis',
] as const,
wide: [
'Enero',
'Pebrero',
'Marso',
'Abril',
'Mayo',
'Hunyo',
'Hulyo',
'Agosto',
'Setyembre',
'Oktubre',
'Nobyembre',
'Disyembre',
] as const,
}

const dayValues = {
narrow: ['L', 'L', 'M', 'M', 'H', 'B', 'S'] as const,
short: ['Li', 'Lu', 'Ma', 'Mi', 'Hu', 'Bi', 'Sa'] as const,
abbreviated: ['Lin', 'Lun', 'Mar', 'Miy', 'Huw', 'Biy', 'Sab'] as const,
wide: [
'Linggo',
'Lunes',
'Martes',
'Miyerkules',
'Huwebes',
'Biyernes',
'Sabado',
] as const,
}

const dayPeriodValues = {
narrow: {
am: 'a',
pm: 'p',
midnight: 'mi',
noon: 'n',
morning: 'umaga',
afternoon: 'hapon',
evening: 'gabi',
night: 'gabi',
},
abbreviated: {
am: 'AM',
pm: 'PM',
midnight: 'hatinggabi',
noon: 'tanghali',
morning: 'umaga',
afternoon: 'hapon',
evening: 'gabi',
night: 'gabi',
},
wide: {
am: 'a.m.',
pm: 'p.m.',
midnight: 'hatinggabi',
noon: 'tanghali',
morning: 'umaga',
afternoon: 'hapon',
evening: 'gabi',
night: 'gabi',
},
}

const formattingDayPeriodValues = {
narrow: {
am: 'a',
pm: 'p',
midnight: 'mi',
noon: 'n',
morning: 'sa umaga',
afternoon: 'sa hapon',
evening: 'sa gabi',
night: 'sa gabi',
},
abbreviated: {
am: 'AM',
pm: 'PM',
midnight: 'midnight',
noon: 'noon',
morning: 'sa umaga',
afternoon: 'sa hapon',
evening: 'sa gabi',
night: 'sa gabi',
},
wide: {
am: 'a.m.',
pm: 'p.m.',
midnight: 'midnight',
noon: 'noon',
morning: 'sa umaga',
afternoon: 'sa hapon',
evening: 'sa gabi',
night: 'sa gabi',
},
}

const ordinalNumber: LocalizeFn<number, undefined> = (
dirtyNumber,
_options
) => {
const number = Number(dirtyNumber)

// If ordinal numbers depend on context, for example,
// if they are different for different grammatical genders,
// use `options.unit`.
//
// `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
// 'day', 'hour', 'minute', 'second'.

// const rem100 = number % 100
// if (rem100 > 20 || rem100 < 10) {
// switch (rem100 % 10) {
// case 1:
// return number + 'st'
// case 2:
// return number + 'nd'
// case 3:
// return number + 'rd'
// }
// }

return 'ika-' + number
}

const localize: Localize = {
ordinalNumber,

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

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

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

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

dayPeriod: buildLocalizeFn({
values: dayPeriodValues,
defaultWidth: 'wide',
formattingValues: formattingDayPeriodValues,
defaultFormattingWidth: 'wide',
}),
}

export default localize
Loading

0 comments on commit cfa445e

Please sign in to comment.