-
-
Notifications
You must be signed in to change notification settings - Fork 141
extract text to translation ready files -- Bill Detail Page #1860
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
Merged
Mephistic
merged 14 commits into
codeforboston:main
from
jicruz96:bill-detail-translation
Aug 15, 2025
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0e1c4f8
extract text to translation ready files -- Bill Detail Page
jicruz96 52cda15
create components/i18n.ts to prevent SSR build errors
jicruz96 7deb0c4
fix useTranslation-related build error
jicruz96 bf68e08
prettier formatting
jicruz96 d8d796e
adjust date formats
jicruz96 684b4b2
update components/search/bills/BillHit.tsx date formatting
jicruz96 3180694
update lead sponsor terminology in Sponsors component and add transla…
jicruz96 28e46db
add translation keys for court and sponsor details in BillHit component
jicruz96 6cd22eb
reorder translation keys
jicruz96 3f691f6
address bug in billHit sponsor d
jicruz96 5430aac
Merge branch 'main' into bill-detail-translation
jicruz96 b356e1a
Merge branch 'main' into bill-detail-translation
jicruz96 5c71426
use built-in i18next date formatting utils in lieu of wrapper
jicruz96 816c580
Merge branch 'main' into bill-detail-translation
jicruz96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { format as dateFormat } from "date-fns" | ||
import { enUS, es } from "date-fns/locale" | ||
import { useTranslation as _useTranslation } from "next-i18next" | ||
|
||
// Maps supported language codes to their corresponding date-fns locale objects. | ||
// Used by tDate to ensure date formatting respects the current language's locale. | ||
const localeMap: Record<string, Locale> = { | ||
en: enUS, | ||
es: es | ||
} | ||
jicruz96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* A wrapper around `next-i18next`'s `useTranslation` hook. | ||
* | ||
* Extends the default translation hook by adding `tDate`, a date formatting helper | ||
* that formats dates according to the active language's locale using date-fns. | ||
* | ||
* @returns The translation object from `next-i18next` plus `tDate` for localized date formatting. | ||
* | ||
* @example | ||
* const { t, tDate } = useTranslation("common"); | ||
* console.log(t("welcome")); | ||
* console.log(tDate(new Date(), "PP")); // e.g., "Sep 1, 2025" | ||
*/ | ||
export const useTranslation = (...args: Parameters<typeof _useTranslation>) => { | ||
const response = _useTranslation(...args) | ||
return { | ||
...response, | ||
/** | ||
* Formats a date or date string according to the active language's locale. | ||
* | ||
* Only supports localized format tokens from date-fns. | ||
* See: https://date-fns.org/v2.0.0-alpha.25/docs/format | ||
* | ||
* @param date - ISO date string or Date object to format. | ||
* @param format - A localized date-fns format string (e.g., "PPpp"). | ||
* @returns The localized, formatted date string. | ||
* | ||
* @example | ||
* tDate(new Date(), "PP"); // "Sep 1, 2025" in English, "1 sept 2025" in Spanish | ||
*/ | ||
tDate: (date: string | Date, format: string) => { | ||
jicruz96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
date = typeof date === "string" ? new Date(date) : date | ||
return dateFormat(date, format, { | ||
locale: localeMap[response.i18n.language] ?? enUS | ||
}) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.