-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from juanangosto/master
Add Spanish locale (closes #268)
- Loading branch information
Showing
8 changed files
with
767 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ tmp | |
dist/compressed | ||
test.espowered.js | ||
.envrc | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.