Skip to content

Commit afbd420

Browse files
committed
docs: Update API docs
1 parent d77cd5d commit afbd420

22 files changed

+192
-131
lines changed

fluent-bundle/src/builtins.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ const NUMBER_ALLOWED = [
5050
*
5151
* pi = The value of π is {NUMBER($pi, maximumFractionDigits: 2)}.
5252
*
53-
* The implementation expects an array of `FluentValues` representing the
54-
* positional arguments, and an object of named `FluentValues` representing the
53+
* The implementation expects an array of {@link FluentValue | FluentValues} representing the
54+
* positional arguments, and an object of named {@link FluentValue | FluentValues} representing the
5555
* named parameters.
5656
*
5757
* The following options are recognized:
@@ -121,8 +121,8 @@ const DATETIME_ALLOWED = [
121121
*
122122
* now = It's {DATETIME($today, month: "long")}.
123123
*
124-
* The implementation expects an array of `FluentValues` representing the
125-
* positional arguments, and an object of named `FluentValues` representing the
124+
* The implementation expects an array of {@link FluentValue | FluentValues} representing the
125+
* positional arguments, and an object of named {@link FluentValue | FluentValues} representing the
126126
* named parameters.
127127
*
128128
* The following options are recognized:

fluent-bundle/src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/**
2-
* @module fluent
3-
* @overview
4-
*
5-
* `fluent` is a JavaScript implementation of Project Fluent, a localization
2+
* A JavaScript implementation of Project Fluent, a localization
63
* framework designed to unleash the expressive power of the natural language.
74
*
5+
* @module
86
*/
97

108
export type { Message } from "./ast.js";

fluent-bundle/src/resolver.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
/* global Intl */
2-
31
/**
4-
* @overview
5-
*
62
* The role of the Fluent resolver is to format a `Pattern` to an instance of
73
* `FluentValue`. For performance reasons, primitive strings are considered
84
* such instances, too.

fluent-bundle/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export abstract class FluentType<T> {
6363
}
6464

6565
/**
66-
* A `FluentType` representing no correct value.
66+
* A {@link FluentType} representing no correct value.
6767
*/
6868
export class FluentNone extends FluentType<string> {
6969
/**
@@ -83,7 +83,7 @@ export class FluentNone extends FluentType<string> {
8383
}
8484

8585
/**
86-
* A `FluentType` representing a number.
86+
* A {@link FluentType} representing a number.
8787
*
8888
* A `FluentNumber` instance stores the number value of the number it
8989
* represents. It may also store an option bag of options which will be passed
@@ -120,7 +120,7 @@ export class FluentNumber extends FluentType<number> {
120120
}
121121

122122
/**
123-
* A `FluentType` representing a date and time.
123+
* A {@link FluentType} representing a date and time.
124124
*
125125
* A `FluentDateTime` instance stores a Date object, Temporal object, or a number
126126
* as a numerical timestamp in milliseconds. It may also store an

fluent-langneg/src/index.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
/*
2-
* @module fluent-langneg
3-
* @overview
4-
*
5-
* `fluent-langneg` provides language negotiation API that fits into
1+
/**
2+
* A language negotiation API that fits into the
63
* Project Fluent localization composition and fallbacking strategy.
74
*
5+
* @module
86
*/
97

10-
export {
11-
negotiateLanguages,
12-
NegotiateLanguagesOptions,
13-
} from "./negotiate_languages.js";
8+
export { negotiateLanguages } from "./negotiate_languages.js";
149
export { acceptedLanguages } from "./accepted_languages.js";
1510
export { filterMatches } from "./matches.js";

fluent-langneg/src/locale.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint no-magic-numbers: 0 */
2-
31
const languageCodeRe = "([a-z]{2,3}|\\*)";
42
const scriptCodeRe = "(?:-([a-z]{4}|\\*))";
53
const regionCodeRe = "(?:-([a-z]{2}|\\*))";

fluent-langneg/src/matches.ts

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint no-magic-numbers: 0 */
2-
31
import { Locale } from "./locale.js";
42

53
/**
@@ -9,68 +7,68 @@ import { Locale } from "./locale.js";
97
* The algorithm is based on the BCP4647 3.3.2 Extended Filtering algorithm,
108
* with several modifications:
119
*
12-
* 1) available locales are treated as ranges
10+
* ### 1. Available locales are treated as ranges
1311
*
14-
* This change allows us to match a more specific request against
15-
* more generic available locale.
12+
* This change allows us to match a more specific request against
13+
* more generic available locale.
1614
*
17-
* For example, if the available locale list provides locale `en`,
18-
* and the requested locale is `en-US`, we treat the available locale as
19-
* a locale that matches all possible english requests.
15+
* For example, if the available locale list provides locale `en`,
16+
* and the requested locale is `en-US`, we treat the available locale as
17+
* a locale that matches all possible english requests.
2018
*
21-
* This means that we expect available locale ID to be as precize as
22-
* the matches they want to cover.
19+
* This means that we expect available locale ID to be as precize as
20+
* the matches they want to cover.
2321
*
24-
* For example, if there is only `sr` available, it's ok to list
25-
* it in available locales. But once the available locales has both,
26-
* Cyrl and Latn variants, the locale IDs should be `sr-Cyrl` and `sr-Latn`
27-
* to avoid any `sr-*` request to match against whole `sr` range.
22+
* For example, if there is only `sr` available, it's ok to list
23+
* it in available locales. But once the available locales has both,
24+
* Cyrl and Latn variants, the locale IDs should be `sr-Cyrl` and `sr-Latn`
25+
* to avoid any `sr-*` request to match against whole `sr` range.
2826
*
29-
* What it does ([requested] * [available] = [supported]):
27+
* What it does ([requested] * [available] = [supported]):
3028
*
31-
* ['en-US'] * ['en'] = ['en']
29+
* ['en-US'] * ['en'] = ['en']
3230
*
33-
* 2) likely subtags from LDML 4.3 Likely Subtags has been added
31+
* ### 2. Likely subtags from LDML 4.3 Likely Subtags has been added
3432
*
35-
* The most obvious likely subtag that can be computed is a duplication
36-
* of the language field onto region field (`fr` => `fr-FR`).
33+
* The most obvious likely subtag that can be computed is a duplication
34+
* of the language field onto region field (`fr` => `fr-FR`).
3735
*
38-
* On top of that, likely subtags may use a list of mappings, that
39-
* allow the algorithm to handle non-obvious matches.
40-
* For example, making sure that we match `en` to `en-US` or `sr` to
41-
* `sr-Cyrl`, while `sr-RU` to `sr-Latn-RU`.
36+
* On top of that, likely subtags may use a list of mappings, that
37+
* allow the algorithm to handle non-obvious matches.
38+
* For example, making sure that we match `en` to `en-US` or `sr` to
39+
* `sr-Cyrl`, while `sr-RU` to `sr-Latn-RU`.
4240
*
43-
* This list can be taken directly from CLDR Supplemental Data.
41+
* This list can be taken directly from CLDR Supplemental Data.
4442
*
45-
* What it does ([requested] * [available] = [supported]):
43+
* What it does ([requested] * [available] = [supported]):
4644
*
47-
* ['fr'] * ['fr-FR'] = ['fr-FR']
48-
* ['en'] * ['en-US'] = ['en-US']
49-
* ['sr'] * ['sr-Latn', 'sr-Cyrl'] = ['sr-Cyrl']
45+
* ['fr'] * ['fr-FR'] = ['fr-FR']
46+
* ['en'] * ['en-US'] = ['en-US']
47+
* ['sr'] * ['sr-Latn', 'sr-Cyrl'] = ['sr-Cyrl']
5048
*
51-
* 3) variant/region range check has been added
49+
* ### 3. Variant/region range check has been added
5250
*
53-
* Lastly, the last form of check is against the requested locale ID
54-
* but with the variant/region field replaced with a `*` range.
51+
* Lastly, the last form of check is against the requested locale ID
52+
* but with the variant/region field replaced with a `*` range.
5553
*
56-
* The rationale here laid out in LDML 4.4 Language Matching:
57-
* "(...) normally the fall-off between the user's languages is
58-
* substantially greated than regional variants."
54+
* The rationale here laid out in LDML 4.4 Language Matching:
55+
* "(...) normally the fall-off between the user's languages is
56+
* substantially greated than regional variants."
5957
*
60-
* In other words, if we can't match for the given region, maybe
61-
* we can match for the same language/script but other region, and
62-
* it will in most cases be preferred over falling back on the next
63-
* language.
58+
* In other words, if we can't match for the given region, maybe
59+
* we can match for the same language/script but other region, and
60+
* it will in most cases be preferred over falling back on the next
61+
* language.
6462
*
65-
* What it does ([requested] * [available] = [supported]):
63+
* What it does ([requested] * [available] = [supported]):
6664
*
67-
* ['en-AU'] * ['en-US'] = ['en-US']
68-
* ['sr-RU'] * ['sr-Latn-RO'] = ['sr-Latn-RO'] // sr-RU -> sr-Latn-RU
65+
* ['en-AU'] * ['en-US'] = ['en-US']
66+
* ['sr-RU'] * ['sr-Latn-RO'] = ['sr-Latn-RO'] // sr-RU -> sr-Latn-RU
6967
*
70-
* It works similarly to getParentLocales algo, except that we stop
71-
* after matching against variant/region ranges and don't try to match
72-
* ignoring script ranges. That means that `sr-Cyrl` will never match
73-
* against `sr-Latn`.
68+
* It works similarly to getParentLocales algo, except that we stop
69+
* after matching against variant/region ranges and don't try to match
70+
* ignoring script ranges. That means that `sr-Cyrl` will never match
71+
* against `sr-Latn`.
7472
*/
7573
export function filterMatches(
7674
requestedLocales: Array<string>,

fluent-langneg/src/negotiate_languages.ts

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,57 @@
11
import { filterMatches } from "./matches.js";
22

3-
export interface NegotiateLanguagesOptions {
4-
strategy?: "filtering" | "matching" | "lookup";
5-
defaultLocale?: string;
6-
}
7-
83
/**
94
* Negotiates the languages between the list of requested locales against
105
* a list of available locales.
116
*
127
* It accepts three arguments:
138
*
14-
* requestedLocales:
15-
* an Array of strings with BCP47 locale IDs sorted
16-
* according to user preferences.
9+
* - `requestedLocales`:
10+
* an Array of strings with BCP47 locale IDs sorted
11+
* according to user preferences.
1712
*
18-
* availableLocales:
19-
* an Array of strings with BCP47 locale IDs of locale for which
20-
* resources are available. Unsorted.
13+
* - `availableLocales`:
14+
* an Array of strings with BCP47 locale IDs of locale for which
15+
* resources are available. Unsorted.
2116
*
22-
* options:
23-
* An object with the following, optional keys:
17+
* - `options`:
18+
* An object with the following, optional keys:
2419
*
25-
* strategy: 'filtering' (default) | 'matching' | 'lookup'
20+
* - `strategy`: `'filtering'` (default) | `'matching'` | `'lookup'`
2621
*
27-
* defaultLocale:
28-
* a string with BCP47 locale ID to be used
29-
* as a last resort locale.
22+
* - `defaultLocale`:
23+
* a string with BCP47 locale ID to be used
24+
* as a last resort locale.
3025
*
3126
*
3227
* It returns an Array of strings with BCP47 locale IDs sorted according to the
3328
* user preferences.
3429
*
3530
* The exact list will be selected differently depending on the strategy:
3631
*
37-
* 'filtering': (default)
38-
* In the filtering strategy, the algorithm will attempt to match
39-
* as many keys in the available locales in order of the requested locales.
32+
* - `'filtering'`: (default)<br>
33+
* In the filtering strategy, the algorithm will attempt to match
34+
* as many keys in the available locales in order of the requested locales.
4035
*
41-
* 'matching':
42-
* In the matching strategy, the algorithm will attempt to find the
43-
* best possible match for each element of the requestedLocales list.
36+
* - `'matching'`:<br>
37+
* In the matching strategy, the algorithm will attempt to find the
38+
* best possible match for each element of the requestedLocales list.
4439
*
45-
* 'lookup':
46-
* In the lookup strategy, the algorithm will attempt to find a single
47-
* best available locale based on the requested locales list.
40+
* - `'lookup'`:<br>
41+
* In the lookup strategy, the algorithm will attempt to find a single
42+
* best available locale based on the requested locales list.
4843
*
49-
* This strategy requires defaultLocale option to be set.
44+
* This strategy requires defaultLocale option to be set.
5045
*/
5146
export function negotiateLanguages(
5247
requestedLocales: Readonly<Array<string>>,
5348
availableLocales: Readonly<Array<string>>,
54-
{ strategy = "filtering", defaultLocale }: NegotiateLanguagesOptions = {}
49+
options?: {
50+
strategy?: "filtering" | "matching" | "lookup";
51+
defaultLocale?: string;
52+
}
5553
): Array<string> {
54+
const { strategy = "filtering", defaultLocale } = options ?? {};
5655
const supportedLocales = filterMatches(
5756
Array.from(requestedLocales ?? []).map(String),
5857
Array.from(availableLocales ?? []).map(String),

fluent-react/src/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
/**
2-
* @module fluent-react
3-
* @overview
2+
* React bindings for Fluent.
3+
* Takes advantage of React's Components system and the virtual DOM.
4+
* Translations are exposed to components via the provider pattern.
45
*
5-
6-
* `fluent-react` provides React bindings for Fluent. It takes advantage of
7-
* React's Components system and the virtual DOM. Translations are exposed to
8-
* components via the provider pattern.
9-
*
10-
* Consult the documentation of the `LocalizationProvider` and the `Localized`
6+
* Consult the documentation of the {@link LocalizationProvider} and the {@link Localized}
117
* components for more information.
128
*
139
* @example
@@ -18,6 +14,8 @@
1814
* </Localized>
1915
* </LocalizationProvider>
2016
* ```
17+
*
18+
* @module
2119
*/
2220

2321
export { ReactLocalization } from "./localization.js";

fluent-react/src/localization.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ const defaultReportError = (error: Error): void => {
2525
* `ReactLocalization` handles translation formatting and fallback.
2626
*
2727
* The current negotiated fallback chain of languages is stored in the
28-
* `ReactLocalization` instance in form of an iterable of `FluentBundle`
28+
* `ReactLocalization` instance in form of an iterable of {@link FluentBundle}
2929
* instances. This iterable is used to find the best existing translation for
3030
* a given identifier.
3131
*
32-
* The `ReactLocalization` class instances are exposed to `Localized` elements
33-
* via the `LocalizationProvider` component.
32+
* The `ReactLocalization` class instances are exposed to {@link Localized} elements
33+
* via the {@link LocalizationProvider} component.
3434
*/
3535
export class ReactLocalization {
3636
public bundles: Iterable<FluentBundle>;

fluent-react/src/provider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { FluentContext } from "./context.js";
33
import { ReactLocalization } from "./localization.js";
44

55
/**
6-
* The Provider component for the `ReactLocalization` class.
6+
* The Provider component for the {@link ReactLocalization} class.
77
*
8-
* Exposes a `ReactLocalization` instance to all descendants via React's
8+
* Exposes a {@link ReactLocalization} instance to all descendants via React's
99
* context feature. It makes translations available to all localizable
1010
* elements in the descendant's render tree without the need to pass them
1111
* explicitly.
1212
*
13-
* `LocalizationProvider` takes an instance of `ReactLocalization` in the
14-
* `l10n` prop. This instance will be made available to `Localized` components
13+
* `LocalizationProvider` takes an instance of {@link ReactLocalization} in the
14+
* `l10n` prop. This instance will be made available to {@link Localized} components
1515
* under the provider.
1616
*
1717
* @example

fluent-react/src/use_localization.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import { useContext } from "react";
22
import { FluentContext } from "./context.js";
33
import { ReactLocalization } from "./localization.js";
44

5-
/**
6-
* The `useLocalization` hook returns the FluentContext
7-
*/
8-
type useLocalization = () => { l10n: ReactLocalization };
9-
export const useLocalization: useLocalization = () => {
5+
export function useLocalization(): { l10n: ReactLocalization } {
106
const l10n = useContext(FluentContext);
117

128
if (!l10n) {
@@ -17,4 +13,4 @@ export const useLocalization: useLocalization = () => {
1713
}
1814

1915
return { l10n };
20-
};
16+
}

0 commit comments

Comments
 (0)