-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
97239f1
Add .idea folder to .gitignore
juanangosto 7f2396e
Create es locale directory from en locale
juanangosto e4a6f74
Add es locale
juanangosto 475d960
Lowercase week days and months
juanangosto 48dc94f
Add spanish to supported language on docs
juanangosto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
insteadThere was a problem hiding this comment.
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.