From 502b8851b220400494494906205ca505bd18947b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ru=CC=84dolfs=20Puk=CC=A7i=CC=84tis?= Date: Thu, 16 May 2019 14:17:51 +0300 Subject: [PATCH] Add lv locale --- src/esm/locale/index.js | 1 + src/locale/index.js | 1 + src/locale/index.js.flow | 1 + src/locale/lv/_lib/formatDistance/index.js | 136 ++++++ src/locale/lv/_lib/formatDistance/test.js | 221 +++++++++ src/locale/lv/_lib/formatLong/index.js | 41 ++ src/locale/lv/_lib/formatRelative/index.js | 43 ++ src/locale/lv/_lib/localize/index.js | 250 +++++++++++ src/locale/lv/_lib/match/index.js | 140 ++++++ src/locale/lv/index.d.ts | 4 + src/locale/lv/index.js | 27 ++ src/locale/lv/index.js.flow | 33 ++ src/locale/lv/test.js | 492 +++++++++++++++++++++ typings.d.ts | 40 ++ 14 files changed, 1430 insertions(+) create mode 100644 src/locale/lv/_lib/formatDistance/index.js create mode 100644 src/locale/lv/_lib/formatDistance/test.js create mode 100644 src/locale/lv/_lib/formatLong/index.js create mode 100644 src/locale/lv/_lib/formatRelative/index.js create mode 100644 src/locale/lv/_lib/localize/index.js create mode 100644 src/locale/lv/_lib/match/index.js create mode 100644 src/locale/lv/index.d.ts create mode 100644 src/locale/lv/index.js create mode 100644 src/locale/lv/index.js.flow create mode 100644 src/locale/lv/test.js diff --git a/src/esm/locale/index.js b/src/esm/locale/index.js index af1af71501..734b09ba9d 100644 --- a/src/esm/locale/index.js +++ b/src/esm/locale/index.js @@ -18,6 +18,7 @@ export { default as hu } from './hu/index.js' export { default as it } from './it/index.js' export { default as ja } from './ja/index.js' export { default as lt } from './lt/index.js' +export { default as lv } from './lv/index.js' export { default as nb } from './nb/index.js' export { default as nl } from './nl/index.js' export { default as nn } from './nn/index.js' diff --git a/src/locale/index.js b/src/locale/index.js index 7f3e3de0f4..86db7976f4 100644 --- a/src/locale/index.js +++ b/src/locale/index.js @@ -19,6 +19,7 @@ module.exports = { it: require('./it/index.js'), ja: require('./ja/index.js'), lt: require('./lt/index.js'), + lv: require('./lv/index.js'), nb: require('./nb/index.js'), nl: require('./nl/index.js'), nn: require('./nn/index.js'), diff --git a/src/locale/index.js.flow b/src/locale/index.js.flow index 2bfbf876c0..16aa68dc33 100644 --- a/src/locale/index.js.flow +++ b/src/locale/index.js.flow @@ -64,6 +64,7 @@ declare module.exports: { ka: Locale, ko: Locale, lt: Locale, + lv: Locale, mk: Locale, ms: Locale, nb: Locale, diff --git a/src/locale/lv/_lib/formatDistance/index.js b/src/locale/lv/_lib/formatDistance/index.js new file mode 100644 index 0000000000..bd7df18d84 --- /dev/null +++ b/src/locale/lv/_lib/formatDistance/index.js @@ -0,0 +1,136 @@ +function buildLocalizeTokenFn(schema) { + return function(count, options) { + if (count === 1) { + if (options.addSuffix) { + return schema.one[0].replace('{{time}}', schema.one[2]) + } else { + return schema.one[0].replace('{{time}}', schema.one[1]) + } + } else { + var rem = count % 10 === 1 && count % 100 !== 11 + if (options.addSuffix) { + return schema.other[0] + .replace('{{time}}', rem ? schema.other[3] : schema.other[4]) + .replace('{{count}}', count) + } else { + return schema.other[0] + .replace('{{time}}', rem ? schema.other[1] : schema.other[2]) + .replace('{{count}}', count) + } + } + } +} + +var formatDistanceLocale = { + lessThanXSeconds: buildLocalizeTokenFn({ + one: ['mazāk par {{time}}', 'sekundi', 'sekundi'], + other: [ + 'mazāk nekā {{count}} {{time}}', + 'sekunde', + 'sekundes', + 'sekundes', + 'sekundēm' + ] + }), + + xSeconds: buildLocalizeTokenFn({ + one: ['1 {{time}}', 'sekunde', 'sekundes'], + other: ['{{count}} {{time}}', 'sekunde', 'sekundes', 'sekundes', 'sekundēm'] + }), + + halfAMinute: function(count, options) { + if (options.addSuffix) { + return 'pusminūtes' + } else { + return 'pusminūte' + } + }, + + lessThanXMinutes: buildLocalizeTokenFn({ + one: ['mazāk par {{time}}', 'minūti', 'minūti'], + other: [ + 'mazāk nekā {{count}} {{time}}', + 'minūte', + 'minūtes', + 'minūtes', + 'minūtēm' + ] + }), + + xMinutes: buildLocalizeTokenFn({ + one: ['1 {{time}}', 'minūte', 'minūtes'], + other: ['{{count}} {{time}}', 'minūte', 'minūtes', 'minūtes', 'minūtēm'] + }), + + aboutXHours: buildLocalizeTokenFn({ + one: ['apmēram 1 {{time}}', 'stunda', 'stundas'], + other: [ + 'apmēram {{count}} {{time}}', + 'stunda', + 'stundas', + 'stundas', + 'stundām' + ] + }), + + xHours: buildLocalizeTokenFn({ + one: ['1 {{time}}', 'stunda', 'stundas'], + other: ['{{count}} {{time}}', 'stunda', 'stundas', 'stundas', 'stundām'] + }), + + xDays: buildLocalizeTokenFn({ + one: ['1 {{time}}', 'diena', 'dienas'], + other: ['{{count}} {{time}}', 'diena', 'dienas', 'dienas', 'dienām'] + }), + + aboutXMonths: buildLocalizeTokenFn({ + one: ['apmēram 1 {{time}}', 'mēnesis', 'mēneša'], + other: [ + 'apmēram {{count}} {{time}}', + 'mēnesis', + 'mēneši', + 'mēneša', + 'mēnešiem' + ] + }), + + xMonths: buildLocalizeTokenFn({ + one: ['1 {{time}}', 'mēnesis', 'mēneša'], + other: ['{{count}} {{time}}', 'mēnesis', 'mēneši', 'mēneša', 'mēnešiem'] + }), + + aboutXYears: buildLocalizeTokenFn({ + one: ['apmēram 1 {{time}}', 'gads', 'gada'], + other: ['apmēram {{count}} {{time}}', 'gads', 'gadi', 'gada', 'gadiem'] + }), + + xYears: buildLocalizeTokenFn({ + one: ['1 {{time}}', 'gads', 'gada'], + other: ['{{count}} {{time}}', 'gads', 'gadi', 'gada', 'gadiem'] + }), + + overXYears: buildLocalizeTokenFn({ + one: ['ilgāk par 1 {{time}}', 'gadu', 'gadu'], + other: ['vairāk nekā {{count}} {{time}}', 'gads', 'gadi', 'gada', 'gadiem'] + }), + + almostXYears: buildLocalizeTokenFn({ + one: ['gandrīz 1 {{time}}', 'gads', 'gada'], + other: ['vairāk nekā {{count}} {{time}}', 'gads', 'gadi', 'gada', 'gadiem'] + }) +} + +export default function formatDistance(token, count, options) { + options = options || {} + var result = formatDistanceLocale[token](count, options) + + if (options.addSuffix) { + if (options.comparison > 0) { + return 'pēc ' + result + } else { + return 'pirms ' + result + } + } + + return result +} diff --git a/src/locale/lv/_lib/formatDistance/test.js b/src/locale/lv/_lib/formatDistance/test.js new file mode 100644 index 0000000000..4c4130f448 --- /dev/null +++ b/src/locale/lv/_lib/formatDistance/test.js @@ -0,0 +1,221 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'power-assert' +import formatDistance from '.' + +describe('lv locale > formatDistance', function() { + describe('lessThanXSeconds', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('lessThanXSeconds', 1) === 'mazāk par sekundi') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert( + formatDistance('lessThanXSeconds', 2) === 'mazāk nekā 2 sekundes' + ) + }) + }) + }) + + describe('xSeconds', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xSeconds', 1) === '1 sekunde') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xSeconds', 2) === '2 sekundes') + }) + }) + }) + + describe('halfAMinute', function() { + it('returns a proper string', function() { + assert(formatDistance('halfAMinute') === 'pusminūte') + }) + + it('ignores the second argument', function() { + assert(formatDistance('halfAMinute', 123) === 'pusminūte') + }) + }) + + describe('lessThanXMinutes', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('lessThanXMinutes', 1) === 'mazāk par minūti') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('lessThanXMinutes', 2) === 'mazāk nekā 2 minūtes') + }) + }) + }) + + describe('xMinutes', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xMinutes', 1) === '1 minūte') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xMinutes', 2) === '2 minūtes') + }) + }) + }) + + describe('aboutXHours', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXHours', 1) === 'apmēram 1 stunda') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXHours', 2) === 'apmēram 2 stundas') + }) + }) + }) + + describe('xHours', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xHours', 1) === '1 stunda') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xHours', 2) === '2 stundas') + }) + }) + }) + + describe('xDays', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xDays', 1) === '1 diena') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xDays', 2) === '2 dienas') + }) + }) + }) + + describe('aboutXMonths', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXMonths', 1) === 'apmēram 1 mēnesis') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXMonths', 2) === 'apmēram 2 mēneši') + }) + }) + }) + + describe('xMonths', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xMonths', 1) === '1 mēnesis') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xMonths', 2) === '2 mēneši') + }) + }) + }) + + describe('aboutXYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXYears', 1) === 'apmēram 1 gads') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('aboutXYears', 2) === 'apmēram 2 gadi') + }) + }) + }) + + describe('xYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xYears', 1) === '1 gads') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('xYears', 2) === '2 gadi') + }) + }) + }) + + describe('overXYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('overXYears', 1) === 'ilgāk par 1 gadu') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('overXYears', 2) === 'vairāk nekā 2 gadi') + }) + }) + }) + + describe('almostXYears', function() { + context('when the count equals 1', function() { + it('returns a proper string', function() { + assert(formatDistance('almostXYears', 1) === 'gandrīz 1 gads') + }) + }) + + context('when the count is more than 1', function() { + it('returns a proper string', function() { + assert(formatDistance('almostXYears', 2) === 'vairāk nekā 2 gadi') + }) + }) + }) + + context('with a past suffix', function() { + it('adds `pirms` to a string', function() { + var result = formatDistance('aboutXYears', 1, { + addSuffix: true, + comparison: -1 + }) + assert(result === 'pirms apmēram 1 gada') + }) + }) + + context('with a future suffix', function() { + it('adds `pēc` to a string', function() { + var result = formatDistance('halfAMinute', null, { + addSuffix: true, + comparison: 1 + }) + assert(result === 'pēc pusminūtes') + }) + }) +}) diff --git a/src/locale/lv/_lib/formatLong/index.js b/src/locale/lv/_lib/formatLong/index.js new file mode 100644 index 0000000000..5cb2aefae6 --- /dev/null +++ b/src/locale/lv/_lib/formatLong/index.js @@ -0,0 +1,41 @@ +import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js' + +var dateFormats = { + full: "y. 'gada' M. MMMM., EEEE", + long: "y. 'gada' M. MMMM", + medium: 'dd.MM.y.', + short: 'dd.MM.y.' +} + +var timeFormats = { + full: 'HH:mm:ss zzzz', + long: 'HH:mm:ss z', + medium: 'HH:mm:ss', + short: 'HH:mm' +} + +var dateTimeFormats = { + full: "{{date}} 'plkst.' {{time}}", + long: "{{date}} 'plkst.' {{time}}", + medium: '{{date}}, {{time}}', + short: '{{date}}, {{time}}' +} + +var formatLong = { + date: buildFormatLongFn({ + formats: dateFormats, + defaultWidth: 'full' + }), + + time: buildFormatLongFn({ + formats: timeFormats, + defaultWidth: 'full' + }), + + dateTime: buildFormatLongFn({ + formats: dateTimeFormats, + defaultWidth: 'full' + }) +} + +export default formatLong diff --git a/src/locale/lv/_lib/formatRelative/index.js b/src/locale/lv/_lib/formatRelative/index.js new file mode 100644 index 0000000000..821fbcd432 --- /dev/null +++ b/src/locale/lv/_lib/formatRelative/index.js @@ -0,0 +1,43 @@ +import isSameUTCWeek from '../../../../_lib/isSameUTCWeek/index.js' +var weekdays = [ + 'svētdienā', + 'pirmdienā', + 'otrdienā', + 'trešdienā', + 'ceturtdienā', + 'piektdienā', + 'sestdienā' +] + +var formatRelativeLocale = { + lastWeek: function(date, baseDate, options) { + if (isSameUTCWeek(date, baseDate, options)) { + return "eeee 'plkst.' p" + } + + var weekday = weekdays[date.getUTCDay()] + return "'Pagājušā' " + weekday + " 'plkst.' p" + }, + yesterday: "'Vakar plkst.' p", + today: "'Šodien plkst.' p", + tomorrow: "'Rīt plkst.' p", + nextWeek: function(date, baseDate, options) { + if (isSameUTCWeek(date, baseDate, options)) { + return "eeee 'plkst.' p" + } + + var weekday = weekdays[date.getUTCDay()] + return "'Nākamajā' " + weekday + " 'plkst.' p" + }, + other: 'P' +} + +export default function formatRelative(token, date, baseDate, options) { + var format = formatRelativeLocale[token] + + if (typeof format === 'function') { + return format(date, baseDate, options) + } + + return format +} diff --git a/src/locale/lv/_lib/localize/index.js b/src/locale/lv/_lib/localize/index.js new file mode 100644 index 0000000000..e88da4231d --- /dev/null +++ b/src/locale/lv/_lib/localize/index.js @@ -0,0 +1,250 @@ +import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js' + +var eraValues = { + narrow: ['p.m.ē', 'm.ē'], + abbreviated: ['p. m. ē.', 'm. ē.'], + wide: ['pirms mūsu ēras', 'mūsu ērā'] +} + +var quarterValues = { + narrow: ['1', '2', '3', '4'], + abbreviated: ['1. cet.', '2. cet.', '3. cet.', '4. cet.'], + wide: [ + 'pirmais ceturksnis', + 'otrais ceturksnis', + 'trešais ceturksnis', + 'ceturtais ceturksnis' + ] +} + +var formattingQuarterValues = { + narrow: ['1', '2', '3', '4'], + abbreviated: ['1. cet.', '2. cet.', '3. cet.', '4. cet.'], + wide: [ + 'pirmajā ceturksnī', + 'otrajā ceturksnī', + 'trešajā ceturksnī', + 'ceturtajā ceturksnī' + ] +} + +var monthValues = { + narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'], + abbreviated: [ + 'janv.', + 'febr.', + 'marts', + 'apr.', + 'maijs', + 'jūn.', + 'jūl.', + 'aug.', + 'sept.', + 'okt.', + 'nov.', + 'dec.' + ], + wide: [ + 'janvāris', + 'februāris', + 'marts', + 'aprīlis', + 'maijs', + 'jūnijs', + 'jūlijs', + 'augusts', + 'septembris', + 'oktobris', + 'novembris', + 'decembris' + ] +} + +var formattingMonthValues = { + narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'], + abbreviated: [ + 'janv.', + 'febr.', + 'martā', + 'apr.', + 'maijs', + 'jūn.', + 'jūl.', + 'aug.', + 'sept.', + 'okt.', + 'nov.', + 'dec.' + ], + wide: [ + 'janvārī', + 'februārī', + 'martā', + 'aprīlī', + 'maijā', + 'jūnijā', + 'jūlijā', + 'augustā', + 'septembrī', + 'oktobrī', + 'novembrī', + 'decembrī' + ] +} + +var dayValues = { + narrow: ['S', 'P', 'O', 'T', 'C', 'P', 'S'], + short: ['Sv', 'P', 'O', 'T', 'C', 'Pk', 'S'], + abbreviated: [ + 'svētd.', + 'pirmd.', + 'otrd.', + 'trešd.', + 'ceturtd.', + 'piektd.', + 'sestd.' + ], + wide: [ + 'svētdiena', + 'pirmdiena', + 'otrdiena', + 'trešdiena', + 'ceturtdiena', + 'piektdiena', + 'sestdiena' + ] +} + +var formattingDayValues = { + narrow: ['S', 'P', 'O', 'T', 'C', 'P', 'S'], + short: ['Sv', 'P', 'O', 'T', 'C', 'Pk', 'S'], + abbreviated: [ + 'svētd.', + 'pirmd.', + 'otrd.', + 'trešd.', + 'ceturtd.', + 'piektd.', + 'sestd.' + ], + wide: [ + 'svētdienā', + 'pirmdienā', + 'otrdienā', + 'trešdienā', + 'ceturtdienā', + 'piektdienā', + 'sestdienā' + ] +} + +var dayPeriodValues = { + narrow: { + am: 'am', + pm: 'pm', + midnight: 'pusn.', + noon: 'pusd.', + morning: 'rīts', + afternoon: 'diena', + evening: 'vakars', + night: 'nakts' + }, + abbreviated: { + am: 'am', + pm: 'pm', + midnight: 'pusn.', + noon: 'pusd.', + morning: 'rīts', + afternoon: 'pēcpusd.', + evening: 'vakars', + night: 'nakts' + }, + wide: { + am: 'am', + pm: 'pm', + midnight: 'pusnakts', + noon: 'pusdienlaiks', + morning: 'rīts', + afternoon: 'pēcpusdiena', + evening: 'vakars', + night: 'nakts' + } +} +var formattingDayPeriodValues = { + narrow: { + am: 'am', + pm: 'pm', + midnight: 'pusn.', + noon: 'pusd.', + morning: 'rītā', + afternoon: 'dienā', + evening: 'vakarā', + night: 'naktī' + }, + abbreviated: { + am: 'am', + pm: 'pm', + midnight: 'pusn.', + noon: 'pusd.', + morning: 'rītā', + afternoon: 'pēcpusd.', + evening: 'vakarā', + night: 'naktī' + }, + wide: { + am: 'am', + pm: 'pm', + midnight: 'pusnaktī', + noon: 'pusdienlaikā', + morning: 'rītā', + afternoon: 'pēcpusdienā', + evening: 'vakarā', + night: 'naktī' + } +} + +function ordinalNumber(dirtyNumber, dirtyOptions) { + return dirtyNumber + '.' +} + +var localize = { + ordinalNumber: ordinalNumber, + + era: buildLocalizeFn({ + values: eraValues, + defaultWidth: 'wide' + }), + + quarter: buildLocalizeFn({ + values: quarterValues, + defaultWidth: 'wide', + formattingValues: formattingQuarterValues, + defaultFormattingWidth: 'wide', + argumentCallback: function(quarter) { + return Number(quarter) - 1 + } + }), + + month: buildLocalizeFn({ + values: monthValues, + defaultWidth: 'wide', + formattingValues: formattingMonthValues, + defaultFormattingWidth: 'wide' + }), + + day: buildLocalizeFn({ + values: dayValues, + defaultWidth: 'wide', + formattingValues: formattingDayValues, + defaultFormattingWidth: 'wide' + }), + + dayPeriod: buildLocalizeFn({ + values: dayPeriodValues, + defaultWidth: 'wide', + formattingValues: formattingDayPeriodValues, + defaultFormattingWidth: 'wide' + }) +} + +export default localize diff --git a/src/locale/lv/_lib/match/index.js b/src/locale/lv/_lib/match/index.js new file mode 100644 index 0000000000..f7205bf591 --- /dev/null +++ b/src/locale/lv/_lib/match/index.js @@ -0,0 +1,140 @@ +import buildMatchPatternFn from '../../../_lib/buildMatchPatternFn/index.js' +import buildMatchFn from '../../../_lib/buildMatchFn/index.js' + +var matchOrdinalNumberPattern = /^(\d+)\./i +var parseOrdinalNumberPattern = /\d+/i + +var matchEraPatterns = { + narrow: /^(p\.m\.ē|m\.ē)/i, + abbreviated: /^(p\. m\. ē\.|m\. ē\.)/i, + wide: /^(pirms mūsu ēras|mūsu ērā)/i +} +var parseEraPatterns = { + any: [/^p/i, /^m/i] +} + +var matchQuarterPatterns = { + narrow: /^[1234]/i, + abbreviated: /^[1234](\. cet\.)/i, + wide: /^(pirma(is|jā)|otra(is|jā)|treša(is|jā)|ceturta(is|jā)) ceturksn(is|ī)/i +} +var parseQuarterPatterns = { + narrow: [/^1/i, /^2/i, /^3/i, /^4/i], + abbreviated: [/^1/i, /^2/i, /^3/i, /^4/i], + wide: [/^p/i, /^o/i, /^t/i, /^c/i] +} + +var matchMonthPatterns = { + narrow: /^[jfmasond]/i, + abbreviated: /^(janv\.|febr\.|marts|apr\.|maijs|jūn\.|jūl\.|aug\.|sept\.|okt\.|nov\.|dec\.)/i, + wide: /^(janvār(is|ī)|februār(is|ī)|mart[sā]|aprīl(is|ī)|maij[sā]|jūnij[sā]|jūlij[sā]|august[sā]|septembr(is|ī)|oktobr(is|ī)|novembr(is|ī)|decembr(is|ī))/i +} +var parseMonthPatterns = { + narrow: [ + /^j/i, + /^f/i, + /^m/i, + /^a/i, + /^m/i, + /^j/i, + /^j/i, + /^a/i, + /^s/i, + /^o/i, + /^n/i, + /^d/i + ], + any: [ + /^ja/i, + /^f/i, + /^mar/i, + /^ap/i, + /^mai/i, + /^jūn/i, + /^jūl/i, + /^au/i, + /^s/i, + /^o/i, + /^n/i, + /^d/i + ] +} + +var matchDayPatterns = { + narrow: /^[spotc]/i, + short: /^(sv|pi|o|t|c|pk|s)/i, + abbreviated: /^(svētd\.|pirmd\.|otrd.\|trešd\.|ceturtd\.|piektd\.|sestd\.)/i, + wide: /^(svētdien(a|ā)|pirmdien(a|ā)|otrdien(a|ā)|trešdien(a|ā)|ceturtdien(a|ā)|piektdien(a|ā)|sestdien(a|ā))/i +} +var parseDayPatterns = { + narrow: [/^s/i, /^p/i, /^o/i, /^t/i, /^c/i, /^p/i, /^s/i], + any: [/^sv/i, /^pi/i, /^o/i, /^t/i, /^c/i, /^p/i, /^se/i] +} + +var matchDayPeriodPatterns = { + narrow: /^(am|pm|pusn\.|pusd\.|rīt(s|ā)|dien(a|ā)|vakar(s|ā)|nakt(s|ī))/, + abbreviated: /^(am|pm|pusn\.|pusd\.|rīt(s|ā)|pēcpusd\.|vakar(s|ā)|nakt(s|ī))/, + wide: /^(am|pm|pusnakt(s|ī)|pusdienlaik(s|ā)|rīt(s|ā)|pēcpusdien(a|ā)|vakar(s|ā)|nakt(s|ī))/i +} +var parseDayPeriodPatterns = { + any: { + am: /^am/i, + pm: /^pm/i, + midnight: /^pusn/i, + noon: /^pusd/i, + morning: /^r/i, + afternoon: /^(d|pēc)/i, + evening: /^v/i, + night: /^n/i + } +} + +var match = { + ordinalNumber: buildMatchPatternFn({ + matchPattern: matchOrdinalNumberPattern, + parsePattern: parseOrdinalNumberPattern, + valueCallback: function(value) { + return parseInt(value, 10) + } + }), + + era: buildMatchFn({ + matchPatterns: matchEraPatterns, + defaultMatchWidth: 'wide', + parsePatterns: parseEraPatterns, + defaultParseWidth: 'any' + }), + + quarter: buildMatchFn({ + matchPatterns: matchQuarterPatterns, + defaultMatchWidth: 'wide', + parsePatterns: parseQuarterPatterns, + defaultParseWidth: 'any', + valueCallback: function(index) { + return index + 1 + } + }), + + month: buildMatchFn({ + matchPatterns: matchMonthPatterns, + defaultMatchWidth: 'wide', + parsePatterns: parseMonthPatterns, + defaultParseWidth: 'any' + }), + + day: buildMatchFn({ + matchPatterns: matchDayPatterns, + defaultMatchWidth: 'wide', + parsePatterns: parseDayPatterns, + defaultParseWidth: 'any' + }), + + dayPeriod: buildMatchFn({ + matchPatterns: matchDayPeriodPatterns, + defaultMatchWidth: 'any', + parsePatterns: parseDayPeriodPatterns, + defaultParseWidth: 'any' + }) +} + +export default match diff --git a/src/locale/lv/index.d.ts b/src/locale/lv/index.d.ts new file mode 100644 index 0000000000..4b90c83681 --- /dev/null +++ b/src/locale/lv/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import { lv } from 'date-fns/locale' +export = lv diff --git a/src/locale/lv/index.js b/src/locale/lv/index.js new file mode 100644 index 0000000000..64b1471a71 --- /dev/null +++ b/src/locale/lv/index.js @@ -0,0 +1,27 @@ +import formatDistance from './_lib/formatDistance/index.js' +import formatLong from './_lib/formatLong/index.js' +import formatRelative from './_lib/formatRelative/index.js' +import localize from './_lib/localize/index.js' +import match from './_lib/match/index.js' + +/** + * @type {Locale} + * @category Locales + * @summary Latvian locale (Latvia). + * @language Latvian + * @iso-639-2 lav + * @author Rūdolfs Puķītis [@prudolfs]{@link https://github.com/prudolfs} + */ +var locale = { + formatDistance: formatDistance, + formatLong: formatLong, + formatRelative: formatRelative, + localize: localize, + match: match, + options: { + weekStartsOn: 1 /* Monday */, + firstWeekContainsDate: 4 + } +} + +export default locale diff --git a/src/locale/lv/index.js.flow b/src/locale/lv/index.js.flow new file mode 100644 index 0000000000..1fb5c2c1c0 --- /dev/null +++ b/src/locale/lv/index.js.flow @@ -0,0 +1,33 @@ +// @flow +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +type Locale = { + formatDistance: Function, + formatRelative: Function, + localize: { + ordinalNumber: Function, + era: Function, + quarter: Function, + month: Function, + day: Function, + dayPeriod: Function + }, + formatLong: Object, + date: Function, + time: Function, + dateTime: Function, + match: { + ordinalNumber: Function, + era: Function, + quarter: Function, + month: Function, + day: Function, + dayPeriod: Function + }, + options?: { + weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, + firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7 + } +} + +declare module.exports: Locale diff --git a/src/locale/lv/test.js b/src/locale/lv/test.js new file mode 100644 index 0000000000..bccd8bf888 --- /dev/null +++ b/src/locale/lv/test.js @@ -0,0 +1,492 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'power-assert' +import locale from '.' + +import format from '../../format' +import formatDistance from '../../formatDistance' +import formatDistanceStrict from '../../formatDistanceStrict' +import formatRelative from '../../formatRelative' +import parse from '../../parse' + +describe('lv locale', function() { + context('with `format`', function() { + var date = new Date(1986, 3 /* Apr */, 5, 10, 32, 0, 900) + + it('era', function() { + var result = format(date, 'G, GGGG, GGGGG', { locale: locale }) + assert(result === 'm. ē., mūsu ērā, m.ē') + }) + + describe('year', function() { + it('ordinal regular year', function() { + var result = format(date, "yo 'gads'", { locale: locale }) + assert(result === '1986. gads') + }) + + it('ordinal local week-numbering year', function() { + var result = format(date, "Yo 'week-numbering year'", { + locale: locale + }) + assert(result === '1986. week-numbering year') + }) + }) + + describe('quarter', function() { + it('formatting quarter', function() { + var result = format(date, "Qo 'ceturksnī', QQQ, QQQQ, QQQQQ", { + locale: locale + }) + assert(result === '2. ceturksnī, 2. cet., otrajā ceturksnī, 2') + }) + + it('stand-alone quarter', function() { + var result = format(date, "qo 'ceturksnī', qqq, qqqq, qqqqq", { + locale: locale + }) + assert(result === '2. ceturksnī, 2. cet., otrais ceturksnis, 2') + }) + }) + + describe('month', function() { + it('formatting month', function() { + var result = format(date, 'do MMMM', { locale: locale }) + assert(result === '5. aprīlī') + }) + + it('stand-alone month', function() { + var result = format(date, "Lo 'mēnesis', LLL, LLLL, LLLLL", { + locale: locale + }) + assert(result === '4. mēnesis, apr., aprīlis, A') + }) + }) + + describe('week', function() { + it('ordinal local week of year', function() { + var date = new Date(1986, 3 /* Apr */, 6) + var result = format(date, "wo 'nedēļa'", { locale: locale }) + assert(result === '14. nedēļa') + }) + + it('ordinal ISO week of year', function() { + var date = new Date(1986, 3 /* Apr */, 6) + var result = format(date, "Io 'ISO nedēļa'", { locale: locale }) + assert(result === '14. ISO nedēļa') + }) + }) + + describe('day', function() { + it('ordinal date', function() { + var result = format(date, "'šodien ir' do 'datums'", { locale: locale }) + assert(result === 'šodien ir 5. datums') + }) + + it('ordinal day of year', function() { + var result = format(date, "Do 'gada diena'", { locale: locale }) + assert(result === '95. gada diena') + }) + }) + + describe('week day', function() { + it('day of week', function() { + var result = format(date, 'E, EEEE, EEEEE, EEEEEE', { locale: locale }) + assert(result === 'sestd., sestdienā, S, S') + }) + + it('ordinal day of week', function() { + var result = format(date, "eo 'nedēļas diena'", { locale: locale }) + assert(result === '6. nedēļas diena') + }) + }) + + describe('day period and hour', function() { + it('ordinal hour', function() { + var result = format(date, "ho 'stunda'", { locale: locale }) + assert(result === '10. stunda') + }) + + it('AM, PM', function() { + var result = format(date, 'h a, h aaaa, haaaaa', { locale: locale }) + assert(result === '10 am, 10 am, 10am') + }) + + it('AM, PM, noon, midnight', function() { + var result = format( + new Date(1986, 3 /* Apr */, 6, 0), + 'b, bbbb, bbbbb', + { locale: locale } + ) + assert(result === 'pusn., pusnaktī, pusn.') + }) + + it('flexible day periods', function() { + it('works as expected', function() { + var result = format(date, 'h B', { locale: locale }) + assert(result === '10 rītā') + }) + }) + }) + + it('ordinal minute', function() { + var result = format(date, "mo 'minūte'", { locale: locale }) + assert(result === '32. minūte') + }) + + it('ordinal second', function() { + var result = format(date, "so 'sekunde'", { locale: locale }) + assert(result === '0. sekunde') + }) + + describe('long format', function() { + it('short date', function() { + var result = format(date, 'P', { locale: locale }) + assert(result === '05.04.1986.') + }) + + it('medium date', function() { + var result = format(date, 'PP', { locale: locale }) + assert(result === '05.04.1986.') + }) + + it('long date', function() { + var result = format(date, 'PPP', { locale: locale }) + assert(result === '1986. gada 4. aprīlī') + }) + + it('full date', function() { + var result = format(date, 'PPPP', { locale: locale }) + assert(result === '1986. gada 4. aprīlī., sestdienā') + }) + + it('short time', function() { + var result = format(date, 'p', { locale: locale }) + assert(result === '10:32') + }) + + it('medium time', function() { + var result = format(date, 'pp', { locale: locale }) + assert(result === '10:32:00') + }) + + it('short date + time', function() { + var result = format(date, 'Pp', { locale: locale }) + assert(result === '05.04.1986., 10:32') + }) + + it('medium date + time', function() { + var result = format(date, 'PPpp', { locale: locale }) + assert(result === '05.04.1986., 10:32:00') + }) + + it('long date + time', function() { + var result = format(date, 'PPPp', { locale: locale }) + assert(result === '1986. gada 4. aprīlī plkst. 10:32') + }) + + it('full date + time', function() { + var result = format(date, 'PPPPp', { locale: locale }) + assert(result === '1986. gada 4. aprīlī., sestdienā plkst. 10:32') + }) + }) + }) + + context('with `formatDistance`', function() { + it('works as expected', function() { + var result = formatDistance( + new Date(1986, 3, 4, 10, 32, 25), + new Date(1986, 3, 4, 10, 32, 0), + { locale: locale, includeSeconds: true } + ) + assert(result === 'pusminūte') + }) + + context('when `addSuffix` option is true', function() { + it('adds a future suffix', function() { + var result = formatDistance( + new Date(1986, 3, 4, 10, 32, 7), + new Date(1986, 3, 4, 10, 32, 0), + { locale: locale, includeSeconds: true, addSuffix: true } + ) + assert(result === 'pēc mazāk nekā 10 sekundēm') + }) + + it('adds a past suffix', function() { + var result = formatDistance( + new Date(1986, 3, 4, 10, 32, 0), + new Date(1986, 3, 4, 11, 32, 0), + { locale: locale, addSuffix: true } + ) + assert(result === 'pirms apmēram 1 stundas') + }) + }) + }) + + context('with `formatDistanceStrict`', function() { + it('works as expected', function() { + var result = formatDistanceStrict( + new Date(1986, 3, 4, 10, 32, 0), + new Date(1986, 3, 4, 12, 32, 0), + { locale: locale, unit: 'minute' } + ) + assert(result === '120 minūtes') + }) + + describe('when `addSuffix` option is true', function() { + it('adds a future suffix', function() { + var result = formatDistanceStrict( + new Date(1986, 3, 4, 10, 32, 25), + new Date(1986, 3, 4, 10, 32, 0), + { locale: locale, addSuffix: true } + ) + assert(result === 'pēc 25 sekundēm') + }) + + it('adds a past suffix', function() { + var result = formatDistanceStrict( + new Date(1986, 3, 4, 10, 32, 0), + new Date(1986, 3, 4, 11, 32, 0), + { locale: locale, addSuffix: true } + ) + assert(result === 'pirms 1 stundas') + }) + }) + }) + + context('with `formatRelative`', function() { + var baseDate = new Date(1986, 3 /* Apr */, 4, 10, 32, 0, 900) + + it('last week', function() { + var result = formatRelative(new Date(1986, 3 /* Apr */, 1), baseDate, { + locale: locale + }) + assert(result === 'otrdienā plkst. 00:00') + }) + + it('yesterday', function() { + var result = formatRelative( + new Date(1986, 3 /* Apr */, 3, 22, 22), + baseDate, + { locale: locale } + ) + assert(result === 'Vakar plkst. 22:22') + }) + + it('today', function() { + var result = formatRelative( + new Date(1986, 3 /* Apr */, 4, 16, 50), + baseDate, + { locale: locale } + ) + assert(result === 'Šodien plkst. 16:50') + }) + + it('tomorrow', function() { + var result = formatRelative( + new Date(1986, 3 /* Apr */, 5, 7, 30), + baseDate, + { locale: locale } + ) + assert(result === 'Rīt plkst. 07:30') + }) + + it('next week', function() { + var result = formatRelative( + new Date(1986, 3 /* Apr */, 6, 12, 0), + baseDate, + { locale: locale } + ) + assert(result === 'svētdienā plkst. 12:00') + }) + + it('after the next week', function() { + var result = formatRelative( + new Date(1986, 3 /* Apr */, 11, 16, 50), + baseDate, + { locale: locale } + ) + assert(result === '11.04.1986.') + }) + }) + + context('with `parse`', function() { + var baseDate = new Date(1986, 3 /* Apr */, 4, 10, 32, 0, 900) + + describe('era', function() { + it('abbreviated', function() { + var result = parse('10000 p. m. ē.', 'yyyyy G', baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(-9999, 0 /* Jan */, 1)) + }) + + it('wide', function() { + var result = parse('2018 mūsu ērā', 'yyyy GGGG', baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(2018, 0 /* Jan */, 1)) + }) + + it('narrow', function() { + var result = parse('44 p.m.ē', 'y GGGGG', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(-43, 0 /* Jan */, 1)) + }) + }) + + it('ordinal year', function() { + var result = parse('2017.', 'yo', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(2017, 0 /* Jan */, 1)) + }) + + describe('quarter', function() { + it('ordinal', function() { + var result = parse('1.', 'Qo', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 0 /* Jan */, 1)) + }) + + it('abbreviated', function() { + var result = parse('3. cet.', 'QQQ', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 6 /* Jul */, 1)) + }) + + it('wide', function() { + var result = parse('ceturtajā ceturksnī', 'QQQQ', baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(1986, 9 /* Oct */, 1)) + }) + + it('narrow', function() { + var result = parse('1', 'QQQQQ', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 0 /* Jan */, 1)) + }) + }) + + describe('month', function() { + it('ordinal', function() { + var result = parse('6.', 'Mo', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 5 /* Jun */, 1)) + }) + + it('abbreviated', function() { + var result = parse('nov.', 'MMM', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 10 /* Nov */, 1)) + }) + + it('wide', function() { + var result = parse('februārī', 'MMMM', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 1 /* Feb */, 1)) + }) + + it('narrow', function() { + var result = parse('J', 'MMMMM', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 0 /* Jan */, 1)) + }) + }) + + it('ordinal week of year', function() { + var result = parse('48.', 'wo', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 10 /* Nov */, 24)) + }) + + it('ordinal day of month', function() { + var result = parse('28.', 'do', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 28)) + }) + + it('ordinal day of year', function() { + var result = parse('200.', 'Do', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 6 /* Jul */, 19)) + }) + + describe('day of week', function() { + it('abbreviated', function() { + var result = parse('P', 'E', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 2 /* Mar */, 31)) + }) + + it('wide', function() { + var result = parse('otrdiena', 'EEEE', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 1)) + }) + + it('narrow', function() { + var result = parse('T', 'EEEEE', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 2)) + }) + + it('short', function() { + var result = parse('C', 'EEEEEE', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 3)) + }) + }) + + it('ordinal local day of week', function() { + var result = parse('2. nedēļas diena', "eo 'nedēļas diena'", baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 1)) + }) + + describe('AM, PM', function() { + it('abbreviated', function() { + var result = parse('5 am', 'h a', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 5)) + }) + + it('wide', function() { + var result = parse('5 pm', 'h aaaa', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 17)) + }) + + it('narrow', function() { + var result = parse('11 am', 'h aaaaa', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 11)) + }) + }) + + describe('AM, PM, noon, midnight', function() { + it('abbreviated', function() { + var result = parse('pusd.', 'b', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 12)) + }) + + it('wide', function() { + var result = parse('pusnakts', 'bbbb', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 0)) + }) + + it('narrow', function() { + var result = parse('pusn.', 'bbbbb', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 0)) + }) + }) + + describe('flexible day period', function() { + it('abbreviated', function() { + var result = parse('2 nakts', 'h B', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 2)) + }) + + it('wide', function() { + var result = parse('12 pēcpusdienā', 'h BBBB', baseDate, { + locale: locale + }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 12)) + }) + + it('narrow', function() { + var result = parse('5 vakarā', 'h BBBBB', baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 17)) + }) + }) + + it('ordinal time', function() { + var dateString = '1. stunda, 2. minūte, 3. sekunde' + var formatString = "ho 'stunda', mo 'minūte', so 'sekunde'" + var result = parse(dateString, formatString, baseDate, { locale: locale }) + assert.deepEqual(result, new Date(1986, 3 /* Apr */, 4, 1, 2, 3)) + }) + }) +}) diff --git a/typings.d.ts b/typings.d.ts index 8a8b37aa11..21a950a987 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -14244,6 +14244,11 @@ declare module 'date-fns/locale' { } + const lv: Locale + namespace lv { + + } + const mk: Locale namespace mk { @@ -14515,6 +14520,11 @@ declare module 'date-fns/locale/lt' { export = lt } +declare module 'date-fns/locale/lv' { + import { lv } from 'date-fns/locale' + export = lv +} + declare module 'date-fns/locale/mk' { import { mk } from 'date-fns/locale' export = mk @@ -14785,6 +14795,11 @@ declare module 'date-fns/locale/lt/index' { export = lt } +declare module 'date-fns/locale/lv/index' { + import { lv } from 'date-fns/locale' + export = lv +} + declare module 'date-fns/locale/mk/index' { import { mk } from 'date-fns/locale' export = mk @@ -15055,6 +15070,11 @@ declare module 'date-fns/locale/lt/index.js' { export = lt } +declare module 'date-fns/locale/lv/index.js' { + import { lv } from 'date-fns/locale' + export = lv +} + declare module 'date-fns/locale/mk/index.js' { import { mk } from 'date-fns/locale' export = mk @@ -15328,6 +15348,11 @@ declare module 'date-fns/esm/locale' { } + const lv: Locale + namespace lv { + + } + const mk: Locale namespace mk { @@ -15599,6 +15624,11 @@ declare module 'date-fns/esm/locale/lt' { export default lt } +declare module 'date-fns/esm/locale/lv' { + import { lv } from 'date-fns/esm/locale' + export default lv +} + declare module 'date-fns/esm/locale/mk' { import { mk } from 'date-fns/esm/locale' export default mk @@ -15869,6 +15899,11 @@ declare module 'date-fns/esm/locale/lt/index' { export default lt } +declare module 'date-fns/esm/locale/lv/index' { + import { lv } from 'date-fns/esm/locale' + export default lv +} + declare module 'date-fns/esm/locale/mk/index' { import { mk } from 'date-fns/esm/locale' export default mk @@ -16139,6 +16174,11 @@ declare module 'date-fns/esm/locale/lt/index.js' { export default lt } +declare module 'date-fns/esm/locale/lv/index.js' { + import { lv } from 'date-fns/esm/locale' + export default lv +} + declare module 'date-fns/esm/locale/mk/index.js' { import { mk } from 'date-fns/esm/locale' export default mk