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

added Kurdish locale #254

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions __tests__/lang/ku.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { advanceTo, clear } from 'jest-date-mock';
import { register, format } from '../../src';
import ku from '../../src/lang/ku';

register('ku', ku);

let date = new Date();

beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('test kurdish dates', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'ku')).toEqual('هەر ئێستا');

advanceTo(30 * 1000);
expect(format(date, 'ku')).toEqual('٣٠ چرکە لەمەوپێش');

advanceTo(1000 * 60);
expect(format(date, 'ku')).toEqual('١ دەقە لەمەوپێش');

advanceTo(1000 * 60 * 30);
expect(format(date, 'ku')).toEqual('٣٠ دەقە لەمەوپێش');

advanceTo(1000 * 60 * 60);
expect(format(date, 'ku')).toEqual('١ کاتژمێر لەمەوپێش');

advanceTo(1000 * 60 * 60 * 6);
expect(format(date, 'ku')).toEqual('٦ کاتژمێر لەمەوپێش');

advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'ku')).toEqual('١ ڕۆژ لەمەوپێش');

advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'ku')).toEqual('٣ ڕۆژ لەمەوپێش');

advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'ku')).toEqual('١ هەفتە لەمەوپێش');

advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'ku')).toEqual('٣ هەفتە لەمەوپێش');

advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'ku')).toEqual('١ مانگ لەمەوپێش');

advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'ku')).toEqual('٤ مانگ لەمەوپێش');

advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'ku')).toEqual('١ ساڵ لەمەوپێش');

advanceTo(1000 * 60 * 60 * 24 * 366 * 11);
expect(format(date, 'ku')).toEqual('١١ ساڵ لەمەوپێش');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'ku')).toEqual('ئێستا');

advanceTo(-30 * 1000);
expect(format(date, 'ku')).toEqual('٣٠ چرکەیتر');

advanceTo(-1000 * 60);
expect(format(date, 'ku')).toEqual('١ دەقەیتر');

advanceTo(-1000 * 60 * 30);
expect(format(date, 'ku')).toEqual('٣٠ دەقەیتر');

advanceTo(-1000 * 60 * 60);
expect(format(date, 'ku')).toEqual('١ کاتژمێریتر');

advanceTo(-1000 * 60 * 60 * 6);
expect(format(date, 'ku')).toEqual('٦ کاتژمێریتر');

advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'ku')).toEqual('١ ڕۆژیتر');

advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'ku')).toEqual('٣ ڕۆژیتر');

advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'ku')).toEqual('١ هەفتەیتر');

advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'ku')).toEqual('٣ هەفتەیتر');

advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'ku')).toEqual('١ مانگیتر');

advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'ku')).toEqual('٤ مانگیتر');

advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'ku')).toEqual('١ ساڵیتر');

advanceTo(-1000 * 60 * 60 * 24 * 366 * 11);
expect(format(date, 'ku')).toEqual('١١ ساڵیتر');
});
});
1 change: 1 addition & 0 deletions src/lang/index.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ export { default as it } from './it';
export { default as ja } from './ja';
export { default as ka } from './ka';
export { default as ko } from './ko';
export { default as ku } from './ku';
export { default as ml } from './ml';
export { default as my } from './my';
export { default as nb_NO } from './nb_NO';
24 changes: 24 additions & 0 deletions src/lang/ku.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const kurdishDigits = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];

// change digits from English to Kurdish
function toKurdishNumeric(number: number): string {
return number.toString().replace(/\d/g, (x: string) => kurdishDigits[x]);
}

const kurdishFuzzyDates = [
['%s چرکە لەمەوپێش', '%s چرکەیتر'], // Seconds
['%s دەقە لەمەوپێش', '%s دەقەیتر'], // Minutes
['%s کاتژمێر لەمەوپێش', '%s کاتژمێریتر'], // Hours
['%s ڕۆژ لەمەوپێش', '%s ڕۆژیتر'], // Days
['%s هەفتە لەمەوپێش', '%s هەفتەیتر'], // Weeks
['%s مانگ لەمەوپێش', '%s مانگیتر'], // Months
['%s ساڵ لەمەوپێش', '%s ساڵیتر'], // Years
];

export default function(number: number, index: number): [string, string] {
if (index === 0) return ['هەر ئێستا', 'ئێستا'];
return [
kurdishFuzzyDates[Math.floor(index / 2)][0].replace('%s', toKurdishNumeric(number)),
kurdishFuzzyDates[Math.floor(index / 2)][1].replace('%s', toKurdishNumeric(number)),
];
}