2020-10-20 21:57:09 +00:00
|
|
|
// License: LGPL-3.0-or-later
|
|
|
|
import * as React from "react";
|
2020-10-24 19:46:36 +00:00
|
|
|
import type { FormatNumberOptions, IntlShape as ParentIntlShape } from "react-intl";
|
2020-10-20 21:57:09 +00:00
|
|
|
import { Money } from "../common/money";
|
|
|
|
|
2020-10-24 19:46:36 +00:00
|
|
|
export type FormatMoneyOptions = Omit<FormatNumberOptions,'style'|'unit'|'unitDisplay'|'currency'>;
|
2020-10-20 21:57:09 +00:00
|
|
|
|
2020-10-24 19:46:36 +00:00
|
|
|
export type IntlShape = ParentIntlShape & {
|
2020-10-20 21:57:09 +00:00
|
|
|
/**
|
|
|
|
* Format a monetary value as a string given the locale
|
|
|
|
*
|
|
|
|
* @param {Money} amount the monetary value to convert to a string
|
|
|
|
* @param {FormatMoneyOptions} [opts] options for controlling how the string should be formatted
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
formatMoney(amount: Money, opts?: FormatMoneyOptions): string;
|
|
|
|
};
|
|
|
|
|
2020-10-24 19:46:36 +00:00
|
|
|
export const IntlContext = React.createContext<IntlShape>(null as IntlShape);
|
2020-10-20 21:57:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use just like `useIntl` for getting strings for the current locale.
|
|
|
|
*
|
|
|
|
* @export
|
2020-10-24 19:46:36 +00:00
|
|
|
* @returns {IntlShape}
|
2020-10-20 21:57:09 +00:00
|
|
|
*/
|
2020-10-24 19:46:36 +00:00
|
|
|
export default function useIntl() : IntlShape {
|
|
|
|
const context = React.useContext(IntlContext);
|
2020-10-20 21:57:09 +00:00
|
|
|
return context;
|
|
|
|
}
|