Skip to content

Commit

Permalink
Remove undocumented PreloadTranslations (#200)
Browse files Browse the repository at this point in the history
This component was never documented but TypeDoc will try to document it,
since it's not considered ready to use I'm removing it
  • Loading branch information
sergiodxa authored Aug 5, 2024
1 parent c86637c commit a720631
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["biomejs.biome"]
}
24 changes: 24 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[javascriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[jsonc]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "explicit",
"quickfix.biome": "explicit"
}
}
48 changes: 0 additions & 48 deletions src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,6 @@ import { useMatches } from "@remix-run/react";
import * as React from "react";
import { useTranslation } from "react-i18next";

export interface PreloadTranslationsProps {
loadPath: string;
}

/**
* Preload the translations files for the current language and the namespaces
* required by the routes.
*
* It receives a single `loadPath` prop with the path to the translation files.
*
* @example
* <PreloadTranslations loadPath="/locales/{{lng}}/{{ns}}.json" />
*
*/
export function PreloadTranslations({ loadPath }: PreloadTranslationsProps) {
let { i18n } = useTranslation();

let namespaces = [
...new Set(
useMatches()
.filter(
(route) =>
(route.handle as { i18n?: string | string[] })?.i18n !== undefined,
)
.flatMap((route) => (route.handle as { i18n: string | string[] }).i18n),
),
];

let lang = i18n.language;

return (
<>
{namespaces.map((namespace) => {
return (
<link
key={namespace}
rel="preload"
as="fetch"
href={loadPath
.replace("{{lng}}", lang)
.replace("{{ns}}", namespace)}
/>
);
})}
</>
);
}

/**
* Get the locale returned by the root route loader under the `locale` key.
* @example
Expand Down

0 comments on commit a720631

Please sign in to comment.