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 locale nn for Norwegian Nynorsk #1172

Merged
merged 1 commit into from Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -78,6 +78,9 @@ for the list of changes made since `v2.0.0-alpha.1`.
- is locale [is updated for v2 format](https://github.com/date-fns/date-fns/pull/1026).
Kudos to [@lamayg](https://github.com/lamayg).

- [Norwegian Nynorsk locale (nn)](https://github.com/date-fns/date-fns/pull/1172)
(thanks to Mats Byrkjeland)[@draperunner](https://github.com/draperunner)

- [Ukrainian locale (ua)](https://github.com/date-fns/date-fns/pull/532)
(thanks to Andrii Korzh [@korzhyk](https://github.com/korzhyk))

Expand Down
1 change: 1 addition & 0 deletions src/esm/locale/index.js
Expand Up @@ -20,6 +20,7 @@ export { default as ja } from './ja/index.js'
export { default as lt } from './lt/index.js'
export { default as nb } from './nb/index.js'
export { default as nl } from './nl/index.js'
export { default as nn } from './nn/index.js'
export { default as pt } from './pt/index.js'
export { default as ptBR } from './pt-BR/index.js'
export { default as ru } from './ru/index.js'
Expand Down
3 changes: 2 additions & 1 deletion src/format/index.js.flow
Expand Up @@ -42,6 +42,7 @@ declare module.exports: (
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
firstWeekContainsDate?: number,
locale?: Locale,
awareOfUnicodeTokens?: boolean
useAdditionalWeekYearTokens?: boolean,
useAdditionalDayOfYearTokens?: boolean
}
) => string
6 changes: 4 additions & 2 deletions src/index.js.flow
Expand Up @@ -224,7 +224,8 @@ declare module.exports: {
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
firstWeekContainsDate?: number,
locale?: Locale,
awareOfUnicodeTokens?: boolean
useAdditionalWeekYearTokens?: boolean,
useAdditionalDayOfYearTokens?: boolean
}
) => string,

Expand Down Expand Up @@ -437,7 +438,8 @@ declare module.exports: {
locale?: Locale,
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7,
awareOfUnicodeTokens?: boolean
useAdditionalWeekYearTokens?: boolean,
useAdditionalDayOfYearTokens?: boolean
}
) => Date,

Expand Down
1 change: 1 addition & 0 deletions src/locale/index.js
Expand Up @@ -21,6 +21,7 @@ module.exports = {
lt: require('./lt/index.js'),
nb: require('./nb/index.js'),
nl: require('./nl/index.js'),
nn: require('./nn/index.js'),
pt: require('./pt/index.js'),
ptBR: require('./pt-BR/index.js'),
ru: require('./ru/index.js'),
Expand Down
1 change: 1 addition & 0 deletions src/locale/index.js.flow
Expand Up @@ -69,6 +69,7 @@ declare module.exports: {
nb: Locale,
nl: Locale,
nlBE: Locale,
nn: Locale,
pl: Locale,
pt: Locale,
ptBR: Locale,
Expand Down
117 changes: 117 additions & 0 deletions src/locale/nn/_lib/formatDistance/index.js
@@ -0,0 +1,117 @@
var formatDistanceLocale = {
lessThanXSeconds: {
singular: 'mindre enn eitt sekund',
plural: 'mindre enn {{count}} sekund'
},

xSeconds: {
singular: 'eitt sekund',
plural: '{{count}} sekund'
},

halfAMinute: 'eit halvt minutt',

lessThanXMinutes: {
singular: 'mindre enn eitt minutt',
plural: 'mindre enn {{count}} minutt'
},

xMinutes: {
singular: 'eitt minutt',
plural: '{{count}} minutt'
},

aboutXHours: {
singular: 'omtrent ein time',
plural: 'omtrent {{count}} timar'
},

xHours: {
singular: 'ein time',
plural: '{{count}} timar'
},

xDays: {
singular: 'ein dag',
plural: '{{count}} dagar'
},

aboutXMonths: {
singular: 'omtrent ein månad',
plural: 'omtrent {{count}} månader'
},

xMonths: {
singular: 'ein månad',
plural: '{{count}} månader'
},

aboutXYears: {
singular: 'omtrent eitt år',
plural: 'omtrent {{count}} år'
},

xYears: {
singular: 'eitt år',
plural: '{{count}} år'
},

overXYears: {
singular: 'over eitt år',
plural: 'over {{count}} år'
},

almostXYears: {
singular: 'nesten eitt år',
plural: 'nesten {{count}} år'
}
}

var wordMapping = [
'null',
'ein',
'to',
'tre',
'fire',
'fem',
'seks',
'sju',
'åtte',
'ni',
'ti',
'elleve',
'tolv'
]

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

var translation = formatDistanceLocale[token]
var result
if (typeof translation === 'string') {
result = translation
} else if (count === 0 || count > 1) {
if (options.onlyNumeric) {
result = translation.plural.replace('{{count}}', count)
} else {
result = translation.plural.replace(
'{{count}}',
count < 13 ? wordMapping[count] : count
)
}
} else {
result = translation.singular
}

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

return result
}