Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ProgressBar): add translations #859

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}