-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 initial version of Latin locale #966
Open
tukusejssirs
wants to merge
7
commits into
iamkun:dev
Choose a base branch
from
tukusejssirs:latin
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
12a2f14
Add initial version of Latin locale
tukusejssirs 2ecfece
Use Arabic numerals for days of month
tukusejssirs 3c98c0f
Fix some issues and add some tests
tukusejssirs cf85d6a
Fix some issues and add more tests
tukusejssirs 2e26255
Remove a number test from the `romanise()` function (it contained `NaN`)
tukusejssirs 049bf1d
Update la.js to fully comply with .eslintrc.json config
tukusejssirs 40d4d4e
Fix some issues raised by @igneus
tukusejssirs 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Latin [la] | ||
import dayjs from 'dayjs' | ||
|
||
const monthFormat = 'ianuarii_februarii_martii_aprilis_maii_iunii_iulii_augusti_septembris_octobris_novembris_decembris'.split('_') | ||
const monthStandalone = 'ianuarius_februarius_martius_aprilis_maius_iunius_iulius_augustus_september_october_november_december'.split('_') | ||
const MONTHS_IN_FORMAT = /D[oD.ᵒ]?(\[[^[\]]*\]|\s)+MMMM?|MMMM?(\[[^[\]]*\]|\s)+D[oD.ᵒ]?/ | ||
const months = (dayjsInstance, format) => { | ||
if (MONTHS_IN_FORMAT.test(format)) { | ||
return monthFormat[dayjsInstance.month()] | ||
} | ||
return monthStandalone[dayjsInstance.month()] | ||
} | ||
months.s = monthStandalone | ||
months.f = monthFormat | ||
|
||
// src: https://stackoverflow.com/a/9083076 | ||
function romanise(num) { | ||
const key = [ | ||
'', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', | ||
'', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', | ||
'', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX' | ||
] | ||
const digits = String(+num).split('') | ||
let roman = '' | ||
let i = 3 | ||
while (i > 0) { | ||
i -= 1 | ||
roman = (key[+digits.pop() + (i * 10)] || '') + roman | ||
} | ||
return Array(+digits.join('') + 1).join('M') + roman | ||
} | ||
|
||
const locale = { | ||
name: 'la', | ||
weekdays: 'dominica_feria secunda_feria tertia_feria quarta_feria quinta_feria sexta_sabbato'.split('_'), | ||
weekdaysShort: 'dominica_feria II_feria III_feria IV_feria V_feria VI_sabbato'.split('_'), | ||
weekdaysMin: 'dom._II_III_IV_V_VI_sab.'.split('_'), | ||
months, | ||
monthsShort: 'ian._feb._mar._apr._mai._iun._iul._aug._sep._oct._nov._dec.'.split('_'), | ||
weekStart: 0, | ||
yearStart: 4, | ||
ordinal: n => romanise(n), | ||
// The relative time variables are in nominative case only | ||
relativeTime: { | ||
future: 'ad %s', | ||
past: 'abhinc %s', | ||
s: 'paucæ secundæ', | ||
m: 'minuta', | ||
mm: '%d minutæ', | ||
h: 'hora', | ||
hh: '%d horæ', | ||
d: 'dies', | ||
dd: '%d dies', | ||
M: 'mensis', | ||
MM: '%d menses', | ||
y: 'annus', | ||
yy: '%d anni' | ||
}, | ||
formats: { | ||
LT: 'HH:mm', | ||
LTS: 'HH:mm:ss', | ||
L: 'D. MM. YYYY', | ||
LL: 'D MMMM YYYY', | ||
LLL: 'D MMMM YYYY, HH:mm', | ||
LLLL: 'dddd, D MMMM YYYY, HH:mm' | ||
} | ||
} | ||
|
||
dayjs.locale(locale, null, true) | ||
|
||
export default locale |
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,172 @@ | ||
import MockDate from 'mockdate' | ||
import dayjs from '../../src' | ||
import advancedFormat from '../../src/plugin/advancedFormat' | ||
import localizedFormat from '../../src/plugin/localizedFormat' | ||
import relativeTime from '../../src/plugin/relativeTime' | ||
import '../../src/locale/la' | ||
|
||
dayjs.extend(advancedFormat) | ||
dayjs.extend(localizedFormat) | ||
dayjs.extend(relativeTime) | ||
dayjs.locale('la') | ||
|
||
beforeEach(() => { | ||
MockDate.set(new Date()) | ||
}) | ||
|
||
afterEach(() => { | ||
MockDate.reset() | ||
}) | ||
|
||
describe('Latin: Test output of month names:', () => { | ||
const T = [ | ||
[1, 'ianuarius', 'ianuarii', 'ian.'], | ||
[2, 'februarius', 'februarii', 'feb.'], | ||
[3, 'martius', 'martii', 'mar.'], | ||
[4, 'aprilis', 'aprilis', 'apr.'], | ||
[5, 'maius', 'maii', 'mai.'], | ||
[6, 'iunius', 'iunii', 'iun.'], | ||
[7, 'iulius', 'iulii', 'iul.'], | ||
[8, 'augustus', 'augusti', 'aug.'], | ||
[9, 'september', 'septembris', 'sep.'], | ||
[10, 'october', 'octobris', 'oct.'], | ||
[11, 'november', 'novembris', 'nov.'], | ||
[12, 'december', 'decembris', 'dec.'] | ||
] | ||
|
||
it('in genitive case if day of month is output', () => { | ||
T.forEach((t) => { | ||
const dayjsDay = dayjs(['2020-', t[0], '-01'].join('')).locale('la').format('D MMMM') | ||
const expected = ['1 ', t[2]].join('') | ||
expect(dayjsDay).toBe(expected) | ||
}) | ||
}) | ||
|
||
it('in nominative if day of month is not output', () => { | ||
T.forEach((t) => { | ||
const dayjsDay = dayjs(['2020-', t[0], '-01'].join('')).locale('la').format('MMMM') | ||
const expected = t[1] | ||
expect(dayjsDay).toBe(expected) | ||
}) | ||
}) | ||
|
||
it('also as a shortcut', () => { | ||
T.forEach((t) => { | ||
const dayjsDay = dayjs(['2020-', t[0], '-01'].join('')).locale('la').format('MMM') | ||
const expected = t[3] | ||
expect(dayjsDay).toBe(expected) | ||
}) | ||
}) | ||
}) | ||
|
||
it('Latin: Test relative time', () => { | ||
const T = [ | ||
[44.4, 'second', 'paucæ secundæ'], // a few seconds | ||
[89.5, 'second', 'minuta'], // a minute | ||
[2, 'minute', '2 minutæ'], // 2 minutes | ||
[43, 'minute', '43 minutæ'], // 43 minutes | ||
[45, 'minute', 'hora'], // an hour | ||
[3, 'hour', '3 horæ'], // 3 hours | ||
[21, 'hour', '21 horæ'], // 21 hours | ||
[1, 'day', 'dies'], // a day | ||
[3, 'day', '3 dies'], // 3 day | ||
[25, 'day', '25 dies'], // 25 days | ||
[1, 'month', 'mensis'], // a month | ||
[2, 'month', '2 menses'], // 2 month | ||
[10, 'month', '10 menses'], // 10 month | ||
[1, 'year', 'annus'], // a year | ||
[2, 'year', '2 anni'], // 2 year | ||
[5, 'year', '5 anni'], // 5 year | ||
[18, 'month', '2 anni'] // 2 years | ||
] | ||
|
||
T.forEach((t) => { | ||
// dayjs.locale('la') | ||
const dayjsDay = dayjs() | ||
const dayjsCompare = dayjs().add(t[0], t[1]) | ||
const expectedFrom = ['abhinc ', t[2]].join('') | ||
const expectedTo = ['ad ', t[2]].join('') | ||
const expectedFromTrue = t[2] | ||
|
||
expect(dayjsDay.from(dayjsCompare)).toBe(expectedFrom) | ||
expect(dayjsDay.to(dayjsCompare)).toBe(expectedTo) | ||
expect(dayjsDay.from(dayjsCompare, true)).toBe(expectedFromTrue) | ||
}) | ||
}) | ||
|
||
it('Latin: Test ordinal numbers in day of months', () => { | ||
const T = [ | ||
[1, 'I'], | ||
[2, 'II'], | ||
[3, 'III'], | ||
[4, 'IV'], | ||
[5, 'V'], | ||
[6, 'VI'], | ||
[7, 'VII'], | ||
[8, 'VIII'], | ||
[9, 'IX'], | ||
[10, 'X'], | ||
[20, 'XX'], | ||
[30, 'XXX'], | ||
[31, 'XXXI'] | ||
] | ||
|
||
T.forEach((t) => { | ||
const dayjsDay = dayjs(['2020-01-', t[0]].join('')).locale('la').format('Do') | ||
const expected = t[1] | ||
expect(dayjsDay).toBe(expected) | ||
}) | ||
}) | ||
|
||
describe('Latin: Test weeday names:', () => { | ||
const T = [ | ||
['2020-01-05', 'dominica', 'dominica', 'dom.'], | ||
['2020-01-06', 'feria secunda', 'feria II', 'II'], | ||
['2020-01-07', 'feria tertia', 'feria III', 'III'], | ||
['2020-01-01', 'feria quarta', 'feria IV', 'IV'], | ||
['2020-01-02', 'feria quinta', 'feria V', 'V'], | ||
['2020-01-03', 'feria sexta', 'feria VI', 'VI'], | ||
['2020-01-04', 'sabbato', 'sabbato', 'sab.'] | ||
] | ||
|
||
it('full weekday names', () => { | ||
T.forEach((t) => { | ||
const dayjsDay = dayjs(t[0]).format('dddd') | ||
const expected = t[1] | ||
expect(dayjsDay).toBe(expected) | ||
}) | ||
}) | ||
|
||
it('short weekday names', () => { | ||
T.forEach((t) => { | ||
const dayjsDay = dayjs(t[0]).format('ddd') | ||
const expected = t[2] | ||
expect(dayjsDay).toBe(expected) | ||
}) | ||
}) | ||
|
||
it('minimal weekday names', () => { | ||
T.forEach((t) => { | ||
const dayjsDay = dayjs(t[0]).format('dd') | ||
const expected = t[3] | ||
expect(dayjsDay).toBe(expected) | ||
}) | ||
}) | ||
}) | ||
|
||
it('minimal weekday names', () => { | ||
const T = [ | ||
['LT', '15:15'], | ||
['LTS', '15:15:32'], | ||
['L', '1. 01. 2020'], | ||
['LL', '1 ianuarii 2020'], | ||
['LLL', '1 ianuarii 2020, 15:15'], | ||
['LLLL', 'feria quarta, 1 ianuarii 2020, 15:15'] | ||
] | ||
|
||
T.forEach((t) => { | ||
const dayjsDay = dayjs('2020-01-01 15:15:32').format(t[0]) | ||
const expected = t[1] | ||
expect(dayjsDay).toBe(expected) | ||
}) | ||
}) |
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.
(Yes, I'm lazy to install the library, understand it and try myself.)
@tukusejssirs would you please post one (preferably non-trivial) example for both relative time in future and in the past?
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.
You can see the output in the locale test (L64-80), in the
T
constant (it is a multi-dimensional array consisting of[number, 'English word', 'number Latin word']
; I think it is quite readable 😉).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.
No, it isn't readable. It's code, DRY as a desert.
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.
Okay, here’s a simple ‘conversion‘ table:
Update: I have updated the table to better reflect that the plural forms are used for any number from
2-∞
interval.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.
Just pinging you, @igneus. When you find some time, please check the table above if it is sufficiently readable for you. All other issues you raised were fixed in the latest commit.
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'm not sure I'll manage to communicate what I really wanted to see, so I cloned your repo and checked out the
latin
branch with hope that I will be able to play with the code myself, but it turns out that my NodeJS skills don't suffice to load the package from development sources.I ran
npm run-script build
, managed to loaddayjs.min.js
in the interactive console (var dayjs = require('dayjs.min.js');
), but attempts to load locales fail, probably due to my lack of understanding of some basic NodeJS concepts.Since I personally don't care much about dayjs' Latin locale, I probably just give up and 🙈
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’m sorry I didn’t understand you. Anyway, I still think that you proofed everything in the Latin locale except for those string in the ‘conversion’ table.
Anyway, in the Czech locale, they use different inflection of those strings when they are used in the past (e.g.
a few seconds ago
) or future tense (in a few seconds
). If any of the strings fromrelativeTime
should be in different grammar case in the past and future tenses, we would need to update it accordingly.All you should need to do after cloning the repo is as follows:
I think the easiest way to test things without any deeper knowledge of Node.js, it to modify the
test/locale/la.test.js
to includeconsole.log()
command(s), where you put the output of whatever you want to see.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.
Pinging @igneus. Are you determined to give up on this review? As I understand it, you have not reviewed only one part, the
relativeTime
.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.
Ping, @igneus. No answer from you for more than a month. I presume you are occupied with some other stuff, however, I’d be very happy if you at least say something. 😉 Thanks in advance with all your help! 😃