Skip to content

Commit fe31f91

Browse files
authored
I18n improvements (#40)
Fixes # # Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. ## Type of change Please mark relevant options with an `x` in the brackets. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Algorithm update - updates algorithm documentation/questions/answers etc. - [ ] Other (please describe): # How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [ ] Integration tests - [ ] Unit tests - [ ] Manual tests - [ ] No tests required # Reviewer checklist Mark everything that needs to be checked before merging the PR. - [ ] Check if the UI is working as expected and is satisfactory - [ ] Check if the code is well documented - [ ] Check if the behavior is what is expected - [ ] Check if the code is well tested - [ ] Check if the code is readable and well formatted - [ ] Additional checks (document below if any) # Screenshots (if appropriate): # Questions (if appropriate):
1 parent a585f4e commit fe31f91

File tree

6 files changed

+31
-62
lines changed

6 files changed

+31
-62
lines changed

app/env.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let env: ServerEnv
1212
* Initializes and parses given environment variables using zod
1313
* @returns Initialized env vars
1414
*/
15-
export function initEnv() {
15+
function initEnv() {
1616
// biome-ignore lint/nursery/noProcessEnv: This should be the only place to use process.env directly
1717
const envData = envSchema.safeParse(process.env)
1818

app/localization/i18n.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { InitOptions } from "i18next"
12
import { supportedLanguages } from "./resource"
23

34
export default {
@@ -8,4 +9,4 @@ export default {
89
fallbackLng: "en",
910
// The default namespace of i18next is "translation", but you can customize it here
1011
defaultNS: "common",
11-
}
12+
} satisfies Omit<InitOptions, "react" | "detection">

app/localization/resource.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@ export const resources: Record<Language, Resource> = {
1919
common: bosnian,
2020
},
2121
}
22+
23+
declare module "i18next" {
24+
export interface CustomTypeOptions {
25+
defaultNS: "common"
26+
fallbackNS: "common"
27+
// custom resources type
28+
resources: Resource
29+
}
30+
}

app/root.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,24 @@ export const Layout = ({ children }: { children: React.ReactNode }) => {
5555
export const ErrorBoundary = () => {
5656
const error = useRouteError()
5757
const { t } = useTranslation()
58-
59-
const errorStatusCode = isRouteErrorResponse(error) ? error.status : "500"
58+
// Constrain the generic type so we don't provide a non-existent key
59+
const statusCode = () => {
60+
if (!isRouteErrorResponse(error)) {
61+
return "500"
62+
}
63+
// Supported error code messages
64+
switch (error.status) {
65+
case 200:
66+
return "200"
67+
case 403:
68+
return "403"
69+
case 404:
70+
return "404"
71+
default:
72+
return "500"
73+
}
74+
}
75+
const errorStatusCode = statusCode()
6076

6177
return (
6278
<div className="placeholder-index relative h-full min-h-screen w-screen flex items-center bg-gradient-to-b from-gray-50 to-gray-100 dark:from-blue-950 dark:to-blue-900 justify-center dark:bg-white sm:pb-16 sm:pt-8">

app/utils/dates.test.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

app/utils/dates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getTimeZone } from "../services/client-hints"
22

3-
export function convertTz(date: string | Date, tzString: string) {
3+
function convertTz(date: string | Date, tzString: string) {
44
const dateToConvert = typeof date === "string" ? new Date(date) : date
55
// Convert to the target timezone
66
const convertedDate = new Date(dateToConvert.toLocaleString("en-US", { timeZone: tzString }))

0 commit comments

Comments
 (0)