Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Spanish locale (closes #268) #269

Merged
merged 5 commits into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say you should put this into your global .gitignore instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok, considering the number of JetBrains users.

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