Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Commit

Permalink
Add Numerals to Psammead Locale (#1477)
Browse files Browse the repository at this point in the history
Add Numerals to Psammead Locale
  • Loading branch information
Drew McMillan authored Jul 30, 2019
2 parents 85f3614 + 182c6f1 commit 2f215af
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/utilities/psammead-locales/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

| Version | Description |
| ------- | ----------------------------------------------------------------------------------------------------------------- |
| 1.2.0 | [PR#1477](https://github.com/bbc/psammead/pull/1477) Add numerals as exports |
| 1.1.0 | [PR#1430](https://github.com/bbc/psammead/pull/1430) Adds some overrides for Yoruba |
| 1.0.2 | [PR#1365](https://github.com/bbc/psammead/pull/1365) Bump psammead-styles to 1.2.0 |
| 1.0.1 | [PR#1181](https://github.com/BBC-News/psammead/pull/1181) use `gel-foundations@3.0.3` and `psammead-styles@1.1.3` |
Expand Down
11 changes: 11 additions & 0 deletions packages/utilities/psammead-locales/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This package provides a collection of locale configs, used in BBC World Service
`/moment/ig` - A [moment.js](https://momentjs.com/) locale for Igbo. This can be used to localise timestamps generated using moment.js.
`/moment/pcm` - A [moment.js](https://momentjs.com/) locale for Pidgin. This can be used to localise timestamps generated using moment.js.
`/moment/yo` - A [moment.js](https://momentjs.com/) locale override for Yoruba. This replaces some translations as requested for BBC News World Service. Note that importing this will also cause the upstream `yo` locale to be loaded.
`/numerals` - Numerals in several different number systems, e.g. Bengali, Burmese, Eastern Arabic, Western Arabic. This can be used for localised numbers for components. Returns arrays of the format `['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];`


## Installation

Expand All @@ -16,13 +18,22 @@ npm install @bbc/psammead-locales --save

## Usage

### Moment locales

```jsx
import moment from 'moment';
import '@bbc/psammead-locales/moment/ig';

moment.locale('ig');
```

### Numerals

```jsx
import { Bengali } from '@bbc/psammead-locales/numerals';
```


## Contributing

Psammead is completely open source. We are grateful for any contributions, whether they be new components, bug fixes or general improvements. Please see our primary contributing guide which can be found at [the root of the Psammead respository](https://github.com/bbc/psammead/blob/latest/CONTRIBUTING.md).
Expand Down
4 changes: 2 additions & 2 deletions packages/utilities/psammead-locales/moment/index.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import './ig';
import './pcm';
import './yo';

const stories = storiesOf('Utilities|Moment Locales', module);
const stories = storiesOf('Utilities|Psammead Locales', module);

const locales = [
{ name: 'Igbo', locale: 'ig' },
Expand Down Expand Up @@ -77,7 +77,7 @@ const issueHref = localeName =>

locales.forEach(({ name, locale }) => {
stories.add(
`${name} - ${locale}`,
`Moment - ${name}(${locale})`,
() => (
<Fragment>
<Table>
Expand Down
30 changes: 30 additions & 0 deletions packages/utilities/psammead-locales/numerals/index.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import styled from 'styled-components';
import { GEL_SPACING } from '@bbc/gel-foundations/spacings';
import * as numerals from '../src/numerals';

const numeralSystems = Object.keys(numerals);
const stories = storiesOf('Utilities|Psammead Locales', module);

const Container = styled.div`
padding: ${GEL_SPACING};
`;

const Value = styled.div`
display: inline-block;
margin: ${GEL_SPACING};
`;

stories.add('Numerals', () => {
return (
<Container>
{numeralSystems.map(numeralSystem => (
<div>
<Value>{numeralSystem}</Value>
<Value>{numerals[numeralSystem].join(', ')}</Value>
</div>
))}
</Container>
);
});
7 changes: 7 additions & 0 deletions packages/utilities/psammead-locales/numerals/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@bbc/psammead-locales/numerals",
"private": "true",
"main": "../dist/numerals",
"module": "../esm/numerals",
"sideEffects": false
}
8 changes: 4 additions & 4 deletions packages/utilities/psammead-locales/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions packages/utilities/psammead-locales/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bbc/psammead-locales",
"version": "1.1.0",
"version": "1.2.0",
"description": "A collection of locale configs, used in BBC World Service sites",
"repository": {
"type": "git",
Expand All @@ -21,13 +21,15 @@
"moment",
"timestamp",
"locales",
"localization"
"localization",
"numerals",
"numbersystems"
],
"peerDependencies": {
"moment": "^2.24.0"
},
"devDependencies": {
"@bbc/gel-foundations": "^3.0.3",
"@bbc/gel-foundations": "^3.1.0",
"@bbc/psammead-styles": "^1.2.0",
"moment": "^2.24.0"
}
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Numerals should return Bengali numerals 1`] = `
Array [
"০",
"১",
"২",
"৩",
"৪",
"৫",
"৬",
"৭",
"৮",
"৯",
"১০",
]
`;

exports[`Numerals should return Burmese numerals 1`] = `
Array [
"၀",
"၁",
"၂",
"၃",
"၄",
"၅",
"၆",
"၇",
"၈",
"၉",
"၁၀",
]
`;

exports[`Numerals should return EasternArabic numerals 1`] = `
Array [
"۰",
"۱",
"۲",
"۳",
"۴",
"۵",
"۶",
"۷",
"۸",
"۹",
"۱۰",
]
`;

exports[`Numerals should return WesternArabic numerals 1`] = `
Array [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
]
`;
28 changes: 28 additions & 0 deletions packages/utilities/psammead-locales/src/numerals/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const Bengali = ['০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯', '১০'];
export const Burmese = ['၀', '၁', '၂', '၃', '၄', '၅', '၆', '၇', '၈', '၉', '၁၀'];
export const EasternArabic = [
'۰',
'۱',
'۲',
'۳',
'۴',
'۵',
'۶',
'۷',
'۸',
'۹',
'۱۰',
];
export const WesternArabic = [
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
];
10 changes: 10 additions & 0 deletions packages/utilities/psammead-locales/src/numerals/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as numerals from '.';

describe('Numerals', () => {
const numeralSystems = Object.keys(numerals);
numeralSystems.forEach(numeralSystem => {
it(`should return ${numeralSystem} numerals`, () => {
expect(numerals[numeralSystem]).toMatchSnapshot();
});
});
});

0 comments on commit 2f215af

Please sign in to comment.