Skip to content

Commit

Permalink
fix(ProgressBar): add translations (#859)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisa18289 authored Oct 18, 2024
1 parent cffbe35 commit 268cd5f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import type { FC, PropsWithChildren } from "react";
import React from "react";
import styles from "./ProgressBar.module.scss";
import clsx from "clsx";
import { useNumberFormatter } from "react-aria";
import { useLocalizedStringFormatter, useNumberFormatter } from "react-aria";
import type { PropsWithStatus } from "@/lib/types/props";
import type { PropsContext } from "@/lib/propsContext";
import { PropsContextProvider } from "@/lib/propsContext";
import locales from "./locales/*.locale.json";

export interface ProgressBarProps
extends PropsWithChildren<Omit<Aria.ProgressBarProps, "children">>,
Expand All @@ -33,6 +34,8 @@ export const ProgressBar: FC<ProgressBarProps> = (props) => {
styles[status],
);

const stringFormatter = useLocalizedStringFormatter(locales);

const formatter = useNumberFormatter(props.formatOptions);

const maxValueText =
Expand All @@ -53,7 +56,9 @@ export const ProgressBar: FC<ProgressBarProps> = (props) => {
<PropsContextProvider props={propsContext}>
{children}
<span className={styles.value}>
{maxValueText ? `${valueText} of ${maxValueText}` : valueText}
{maxValueText
? `${valueText} ${stringFormatter.format("progressBar.of")} ${maxValueText}`
: valueText}
</span>
<div className={styles.bar}>
<div className={styles.fill} style={{ width: percentage + "%" }} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"progressBar.of": "von"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"progressBar.of": "of"
}

0 comments on commit 268cd5f

Please sign in to comment.