Skip to content

Commit

Permalink
Add lv locale
Browse files Browse the repository at this point in the history
  • Loading branch information
prudolfs authored and kossnocorp committed Jun 3, 2019
1 parent dd852d4 commit 502b885
Show file tree
Hide file tree
Showing 14 changed files with 1,430 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/esm/locale/index.js
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions src/locale/index.js
Expand Up @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions src/locale/index.js.flow
Expand Up @@ -64,6 +64,7 @@ declare module.exports: {
ka: Locale,
ko: Locale,
lt: Locale,
lv: Locale,
mk: Locale,
ms: Locale,
nb: Locale,
Expand Down
136 changes: 136 additions & 0 deletions 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
}
221 changes: 221 additions & 0 deletions 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')
})
})
})

0 comments on commit 502b885

Please sign in to comment.