Skip to content

Commit

Permalink
Merge pull request #269 from juanangosto/master
Browse files Browse the repository at this point in the history
Add Spanish locale (closes #268)
  • Loading branch information
leshakoss committed Dec 5, 2016
2 parents ca620ef + 48dc94f commit f192405
Show file tree
Hide file tree
Showing 8 changed files with 767 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ tmp
dist/compressed
test.espowered.js
.envrc
.idea/
1 change: 1 addition & 0 deletions docs/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ date-fns currently supports:
(`de`; kudos to Thomas [@DeMuu](https://github.com/DeMuu) Eilmsteiner)
6. [Japanese](https://github.com/date-fns/date-fns/tree/master/src/locale/ja)
(`ja`; kudos to Thomas [@DeMuu](https://github.com/DeMuu) Eilmsteiner)
7. [Spanish](https://github.com/date-fns/date-fns/tree/master/src/locale/es)

More is coming, help is welcome!

Expand Down
99 changes: 99 additions & 0 deletions src/locale/es/build_distance_in_words_locale/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
function buildDistanceInWordsLocale () {
var distanceInWordsLocale = {
lessThanXSeconds: {
one: 'menos de un segundo',
other: 'menos de {{count}} segundos'
},

xSeconds: {
one: '1 segundo',
other: '{{count}} segundos'
},

halfAMinute: 'medio minuto',

lessThanXMinutes: {
one: 'menos de un minuto',
other: 'menos de {{count}} minutos'
},

xMinutes: {
one: '1 minuto',
other: '{{count}} minutos'
},

aboutXHours: {
one: 'alrededor de 1 hora',
other: 'alrededor de {{count}} horas'
},

xHours: {
one: '1 hora',
other: '{{count}} horas'
},

xDays: {
one: '1 día',
other: '{{count}} días'
},

aboutXMonths: {
one: 'alrededor de 1 mes',
other: 'alrededor de {{count}} meses'
},

xMonths: {
one: '1 mes',
other: '{{count}} meses'
},

aboutXYears: {
one: 'alrededor de 1 año',
other: 'alrededor de {{count}} años'
},

xYears: {
one: '1 año',
other: '{{count}} años'
},

overXYears: {
one: 'más de 1 año',
other: 'más de {{count}} años'
},

almostXYears: {
one: 'casi 1 año',
other: 'casi {{count}} años'
}
}

function localize (token, count, options) {
options = options || {}

var result
if (typeof distanceInWordsLocale[token] === 'string') {
result = distanceInWordsLocale[token]
} else if (count === 1) {
result = distanceInWordsLocale[token].one
} else {
result = distanceInWordsLocale[token].other.replace('{{count}}', count)
}

if (options.addSuffix) {
if (options.comparison > 0) {
return 'en ' + result
} else {
return 'hace ' + result
}
}

return result
}

return {
localize: localize
}
}

module.exports = buildDistanceInWordsLocale
227 changes: 227 additions & 0 deletions src/locale/es/build_distance_in_words_locale/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
// @flow
/* eslint-env mocha */

var assert = require('power-assert')
var buildDistanceInWordsLocale = require('./')

describe('en locale > buildDistanceInWordsLocale', function () {
it('returns an object', function () {
assert(typeof buildDistanceInWordsLocale() === 'object')
})

it('localize property is a function', function () {
assert(typeof buildDistanceInWordsLocale().localize === 'function')
})

describe('lessThanXSeconds', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('lessThanXSeconds', 1) === 'menos de un segundo')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('lessThanXSeconds', 2) === 'menos de 2 segundos')
})
})
})

describe('xSeconds', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xSeconds', 1) === '1 segundo')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xSeconds', 2) === '2 segundos')
})
})
})

describe('halfAMinute', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('halfAMinute') === 'medio minuto')
})

it('ignores the second argument', function () {
assert(buildDistanceInWordsLocale().localize('halfAMinute', 123) === 'medio minuto')
})
})

describe('lessThanXMinutes', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('lessThanXMinutes', 1) === 'menos de un minuto')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('lessThanXMinutes', 2) === 'menos de 2 minutos')
})
})
})

describe('xMinutes', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xMinutes', 1) === '1 minuto')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xMinutes', 2) === '2 minutos')
})
})
})

describe('aboutXHours', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('aboutXHours', 1) === 'alrededor de 1 hora')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('aboutXHours', 2) === 'alrededor de 2 horas')
})
})
})

describe('xHours', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xHours', 1) === '1 hora')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xHours', 2) === '2 horas')
})
})
})

describe('xDays', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xDays', 1) === '1 día')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xDays', 2) === '2 días')
})
})
})

describe('aboutXMonths', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('aboutXMonths', 1) === 'alrededor de 1 mes')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('aboutXMonths', 2) === 'alrededor de 2 meses')
})
})
})

describe('xMonths', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xMonths', 1) === '1 mes')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xMonths', 2) === '2 meses')
})
})
})

describe('aboutXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('aboutXYears', 1) === 'alrededor de 1 año')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('aboutXYears', 2) === 'alrededor de 2 años')
})
})
})

describe('xYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xYears', 1) === '1 año')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('xYears', 2) === '2 años')
})
})
})

describe('overXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('overXYears', 1) === 'más de 1 año')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('overXYears', 2) === 'más de 2 años')
})
})
})

describe('almostXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('almostXYears', 1) === 'casi 1 año')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(buildDistanceInWordsLocale().localize('almostXYears', 2) === 'casi 2 años')
})
})
})

context('with a past suffix', function () {
it('adds `ago` to a string', function () {
var result = buildDistanceInWordsLocale().localize('aboutXYears', 1, {
addSuffix: true,
comparison: -1
})
assert(result === 'hace alrededor de 1 año')
})
})

context('with a future suffix', function () {
it('adds `in` to a string', function () {
var result = buildDistanceInWordsLocale().localize('halfAMinute', null, {
addSuffix: true,
comparison: 1
})
assert(result === 'en medio minuto')
})
})
})
Loading

0 comments on commit f192405

Please sign in to comment.