Skip to content

Commit

Permalink
Add pt-BR locale (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
duailibe authored and leshakoss committed Feb 15, 2018
1 parent 21c2c63 commit 7f1c7bb
Show file tree
Hide file tree
Showing 9 changed files with 914 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/locale/pt-BR/_lib/formatDistance/index.js
@@ -0,0 +1,91 @@
var formatDistanceLocale = {
lessThanXSeconds: {
one: 'menos de um segundo',
other: 'menos de {{count}} segundos'
},

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

halfAMinute: 'meio minuto',

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

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

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

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

xDays: {
one: '1 dia',
other: '{{count}} dias'
},

aboutXMonths: {
one: 'cerca de 1 mês',
other: 'cerca de {{count}} meses'
},

xMonths: {
one: '1 mês',
other: '{{count}} meses'
},

aboutXYears: {
one: 'cerca de 1 ano',
other: 'cerca de {{count}} anos'
},

xYears: {
one: '1 ano',
other: '{{count}} anos'
},

overXYears: {
one: 'mais de 1 ano',
other: 'mais de {{count}} anos'
},

almostXYears: {
one: 'quase 1 ano',
other: 'quase {{count}} anos'
}
}

export default function formatDistance (token, count, options) {
options = options || {}

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

if (options.addSuffix) {
if (options.comparison > 0) {
return 'em ' + result
} else {
return 'há ' + result
}
}

return result
}
219 changes: 219 additions & 0 deletions src/locale/pt-BR/_lib/formatDistance/test.js
@@ -0,0 +1,219 @@
// @flow
/* eslint-env mocha */

import assert from 'power-assert'
import formatDistance from '.'

describe('pt-BR locale > formatDistance', function () {
describe('lessThanXSeconds', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXSeconds', 1) === 'menos de um segundo')
})
})

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

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

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

describe('halfAMinute', function () {
it('returns a proper string', function () {
assert(formatDistance('halfAMinute') === 'meio minuto')
})

it('ignores the second argument', function () {
assert(formatDistance('halfAMinute', 123) === 'meio minuto')
})
})

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

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

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

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

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

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

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

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

describe('xDays', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xDays', 1) === '1 dia')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xDays', 2) === '2 dias')
})
})
})

describe('aboutXMonths', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXMonths', 1) === 'cerca de 1 mês')
})
})

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

describe('xMonths', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xMonths', 1) === '1 mês')
})
})

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

describe('aboutXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXYears', 1) === 'cerca de 1 ano')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXYears', 2) === 'cerca de 2 anos')
})
})
})

describe('xYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xYears', 1) === '1 ano')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xYears', 2) === '2 anos')
})
})
})

describe('overXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('overXYears', 1) === 'mais de 1 ano')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('overXYears', 2) === 'mais de 2 anos')
})
})
})

describe('almostXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('almostXYears', 1) === 'quase 1 ano')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('almostXYears', 2) === 'quase 2 anos')
})
})
})

context('with a past suffix', function () {
it('adds `ago` to a string', function () {
var result = formatDistance('aboutXYears', 1, {
addSuffix: true,
comparison: -1
})
assert(result === 'há cerca de 1 ano')
})
})

context('with a future suffix', function () {
it('adds `in` to a string', function () {
var result = formatDistance('halfAMinute', null, {
addSuffix: true,
comparison: 1
})
assert(result === 'em meio minuto')
})
})
})
12 changes: 12 additions & 0 deletions src/locale/pt-BR/_lib/formatLong/index.js
@@ -0,0 +1,12 @@
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js'

var formatLong = buildFormatLongFn({
LT: 'h:mm aa',
LTS: 'h:mm:ss aa',
L: 'DD/MM/YYYY',
LL: 'D [de] MMMM [de] YYYY',
LLL: 'D [de] MMMM [de] YYYY [às] h:mm aa',
LLLL: 'dddd, D [de] MMMM [de] YYYY [às] h:mm aa'
})

export default formatLong
22 changes: 22 additions & 0 deletions src/locale/pt-BR/_lib/formatRelative/index.js
@@ -0,0 +1,22 @@
var formatRelativeLocale = {
lastWeek: function (date, baseDate, options) {
var weekday = date.getUTCDay()
var last = weekday === 0 || weekday === 6 ? 'último' : 'última'
return '[' + last + '] dddd [às] LT'
},
yesterday: '[ontem às] LT',
today: '[hoje às] LT',
tomorrow: '[amanhã às] LT',
nextWeek: 'dddd [às] LT',
other: 'L'
}

export default function formatRelative (token, date, baseDate, options) {
var format = formatRelativeLocale[token]

if (typeof format === 'function') {
return format(date, baseDate, options)
}

return format
}
44 changes: 44 additions & 0 deletions src/locale/pt-BR/_lib/localize/index.js
@@ -0,0 +1,44 @@
import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js'
import buildLocalizeArrayFn from '../../../_lib/buildLocalizeArrayFn/index.js'

var weekdayValues = {
narrow: ['do', 'sg', 'te', 'qa', 'qi', 'sx', 'sa'],
short: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'],
long: ['domingo', 'segunda', 'terça', 'quarta', 'quinta', 'sexta', 'sábado']
}

var monthValues = {
short: ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'],
long: ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro']
}

var timeOfDayValues = {
uppercase: ['AM', 'PM'],
lowercase: ['am', 'pm'],
long: ['a.m.', 'p.m.']
}

function ordinalNumber (dirtyNumber, dirtyOptions) {
var number = Number(dirtyNumber)
var options = dirtyOptions || {}
var unit = String(options.unit)

if (unit === 'week' || unit === 'isoWeek') {
return number + 'ª'
}
return number + 'º'
}

var localize = {
ordinalNumber: ordinalNumber,
weekday: buildLocalizeFn(weekdayValues, 'long'),
weekdays: buildLocalizeArrayFn(weekdayValues, 'long'),
month: buildLocalizeFn(monthValues, 'long'),
months: buildLocalizeArrayFn(monthValues, 'long'),
timeOfDay: buildLocalizeFn(timeOfDayValues, 'long', function (hours) {
return (hours / 12) >= 1 ? 1 : 0
}),
timesOfDay: buildLocalizeArrayFn(timeOfDayValues, 'long')
}

export default localize

0 comments on commit 7f1c7bb

Please sign in to comment.