Skip to content

Commit 0f8a6f3

Browse files
author
Adam Butterworth
committed
docs: add i18n documentation
1 parent 03f05b3 commit 0f8a6f3

8 files changed

+97
-46
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea
22
coverage
33
dist
4+
docs
45
node_modules
56
src/analytics/segment.js

jsdoc.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"destination": "./docs/api",
2323
"encoding": "utf8",
2424
"private": true,
25-
"recurse": true,
26-
"template": "./node_modules/minami"
25+
"recurse": true
2726
}
2827
}

package-lock.json

-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"enzyme-adapter-react-16": "1.15.1",
4343
"husky": "3.0.9",
4444
"jsdoc": "3.6.3",
45-
"minami": "1.2.3",
4645
"prop-types": "15.7.2",
4746
"react": "16.11.0",
4847
"react-dom": "16.11.0",

src/auth/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ export async function hydrateAuthenticatedUser() {
216216
* ```
217217
*
218218
* @name HttpClient
219-
* @
220219
* @property {function} get
221220
* @property {function} head
222221
* @property {function} options

src/i18n/countries.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ COUNTRIES.registerLocale(require('i18n-iso-countries/langs/uk.json'));
2828
/**
2929
* Provides a lookup table of country IDs to country names for the current locale.
3030
*
31-
* @memberof I18n
31+
* @memberof module:I18n
3232
*/
33-
export const getCountryMessages = (locale) => {
33+
export function getCountryMessages(locale) {
3434
const primaryLanguageSubtag = getPrimaryLanguageSubtag(locale);
3535
const languageCode = countryLangs().includes(primaryLanguageSubtag) ? primaryLanguageSubtag : 'en';
3636

3737
return COUNTRIES.getNames(languageCode);
38-
};
38+
}
3939

4040
/**
4141
* Provides a list of countries represented as objects of the following shape:
@@ -48,9 +48,9 @@ export const getCountryMessages = (locale) => {
4848
* TODO: ARCH-878: The list should be sorted alphabetically in the current locale.
4949
* This is useful for populating dropdowns.
5050
*
51-
* @memberof I18n
51+
* @memberof module:I18n
5252
*/
53-
export const getCountryList = (locale) => {
53+
export function getCountryList(locale) {
5454
const countryMessages = getCountryMessages(locale);
5555
return Object.entries(countryMessages).map(([code, name]) => ({ code, name }));
56-
};
56+
}

src/i18n/index.js

+61-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,68 @@
22
* The i18n module relies on react-intl and re-exports all of that package's exports.
33
*
44
* @module I18n
5+
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/Components.md|React Intl} for components exported from this module.
56
*
6-
*
7+
*/
8+
9+
/**
10+
* @name FormattedDate
11+
* @kind class
12+
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/Components.md#formatteddate|React Intl}
13+
*/
14+
15+
/**
16+
* @name FormattedTime
17+
* @kind class
18+
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/Components.md#formatteddate|React Intl}
19+
*/
20+
21+
/**
22+
* @name FormattedRelative
23+
* @kind class
24+
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/Components.md#formattedrelative|React Intl}
25+
*/
26+
27+
/**
28+
* @name FormattedNumber
29+
* @kind class
30+
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/Components.md#formattednumber|React Intl}
31+
*/
32+
33+
/**
34+
* @name FormattedPlural
35+
* @kind class
36+
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/Components.md#formattedplural|React Intl}
37+
*/
38+
39+
/**
40+
* @name FormattedMessage
41+
* @kind class
42+
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/Components.md#formattedmessage|React Intl}
43+
*/
44+
45+
/**
46+
* @name FormattedMessage
47+
* @kind class
48+
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/Components.md#formattedmessage|React Intl}
49+
*/
50+
51+
/**
52+
* @name IntlProvider
53+
* @kind class
54+
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/Components.md#intlprovider|React Intl}
55+
*/
56+
57+
/**
58+
* @name intlShape
59+
* @kind constant
60+
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/API.md#intlshape|React Intl}
61+
*/
62+
63+
/**
64+
* @name defineMessages
65+
* @kind function
66+
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/API.md#definemessages|React Intl}
767
*/
868

969
export {

src/i18n/lib.js

+28-29
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/**
2-
* The i18n module relies on react-intl and re-exports all of that package's exports.
3-
*
4-
* @module I18n
5-
*
6-
*
7-
*/
8-
91
import PropTypes from 'prop-types';
102
import { addLocaleData } from 'react-intl';
113
import arLocale from 'react-intl/locale-data/ar';
@@ -72,6 +64,7 @@ let messages = null;
7264

7365
/**
7466
*
67+
* @ignore
7568
* @returns {LoggingService}
7669
*
7770
*/
@@ -83,13 +76,13 @@ export const getLoggingService = () => loggingService;
8376
export const LOCALE_TOPIC = 'LOCALE';
8477

8578
/**
86-
* @memberof I18n
79+
* @memberof module:I18n
8780
*/
8881
export const LOCALE_CHANGED = `${LOCALE_TOPIC}.CHANGED`;
8982

9083
/**
9184
*
92-
* @memberof I18n
85+
* @memberof module:I18n
9386
* @returns {Cookies}
9487
*/
9588
export function getCookies() {
@@ -119,9 +112,11 @@ addLocaleData([
119112
* may be 2 or more characters.
120113
*
121114
* @param {string} code
122-
* @memberof I18n
115+
* @memberof module:I18n
123116
*/
124-
export const getPrimaryLanguageSubtag = code => code.split('-')[0];
117+
export function getPrimaryLanguageSubtag(code) {
118+
return code.split('-')[0];
119+
}
125120

126121
/**
127122
* Finds the closest supported locale to the one provided. This is done in three steps:
@@ -133,9 +128,9 @@ export const getPrimaryLanguageSubtag = code => code.split('-')[0];
133128
*
134129
* @param {string} locale
135130
* @returns {string}
136-
* @memberof I18n
131+
* @memberof module:I18n
137132
*/
138-
export const findSupportedLocale = (locale) => {
133+
export function findSupportedLocale(locale) {
139134
if (messages[locale] !== undefined) {
140135
return locale;
141136
}
@@ -145,7 +140,7 @@ export const findSupportedLocale = (locale) => {
145140
}
146141

147142
return 'en';
148-
};
143+
}
149144

150145
/**
151146
* Get the locale from the cookie or, failing that, the browser setting.
@@ -155,9 +150,9 @@ export const findSupportedLocale = (locale) => {
155150
* @param {string} locale If a locale is provided, returns the closest supported locale. Optional.
156151
* @throws An error if i18n has not yet been configured.
157152
* @returns {string}
158-
* @memberof I18n
153+
* @memberof module:I18n
159154
*/
160-
export const getLocale = (locale) => {
155+
export function getLocale(locale) {
161156
if (messages === null) {
162157
throw new Error('getLocale called before configuring i18n. Call configure with messages first.');
163158
}
@@ -176,38 +171,42 @@ export const getLocale = (locale) => {
176171
// Thus the toLowerCase, for consistency.
177172
// https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/language
178173
return findSupportedLocale(global.navigator.language.toLowerCase());
179-
};
174+
}
180175

181176
/**
182177
* Returns messages for the provided locale, or the user's preferred locale if no argument is
183178
* provided.
184179
*
185180
* @param {string} [locale=getLocale()]
186-
* @memberof I18n
181+
* @memberof module:I18n
187182
*/
188-
export const getMessages = (locale = getLocale()) => messages[locale];
183+
export function getMessages(locale = getLocale()) {
184+
return messages[locale];
185+
}
189186

190187
/**
191188
* Determines if the provided locale is a right-to-left language.
192189
*
193190
* @param {string} locale
194-
* @memberof I18n
191+
* @memberof module:I18n
195192
*/
196-
export const isRtl = locale => rtlLocales.includes(locale);
193+
export function isRtl(locale) {
194+
return rtlLocales.includes(locale);
195+
}
197196

198197
/**
199198
* Handles applying the RTL stylesheet and "dir=rtl" attribute to the html tag if the current locale
200199
* is a RTL language.
201200
*
202-
* @memberof I18n
201+
* @memberof module:I18n
203202
*/
204-
export const handleRtl = () => {
203+
export function handleRtl() {
205204
if (isRtl(getLocale())) {
206205
global.document.getElementsByTagName('html')[0].setAttribute('dir', 'rtl');
207206
} else {
208207
global.document.getElementsByTagName('html')[0].setAttribute('dir', 'ltr');
209208
}
210-
};
209+
}
211210

212211
const messagesShape = {
213212
ar: PropTypes.objectOf(PropTypes.string), // Arabic
@@ -242,7 +241,7 @@ const optionsShape = {
242241
*
243242
* @param {Array} [messagesArray=[]]
244243
* @returns {Object}
245-
* @memberof I18n
244+
* @memberof module:I18n
246245
*/
247246
export function mergeMessages(messagesArray = []) {
248247
return Array.isArray(messagesArray) ? merge({}, ...messagesArray) : {};
@@ -258,9 +257,9 @@ export function mergeMessages(messagesArray = []) {
258257
* @param {LoggingService} options.loggingService
259258
* @param {Object} options.config
260259
* @param {Object} options.messages
261-
* @memberof I18n
260+
* @memberof module:I18n
262261
*/
263-
export const configure = (options) => {
262+
export function configure(options) {
264263
PropTypes.checkPropTypes(optionsShape, options, 'property', 'i18n');
265264
// eslint-disable-next-line prefer-destructuring
266265
loggingService = options.loggingService;
@@ -283,4 +282,4 @@ export const configure = (options) => {
283282
}
284283

285284
handleRtl();
286-
};
285+
}

0 commit comments

Comments
 (0)