Skip to content

Commit

Permalink
improve translations
Browse files Browse the repository at this point in the history
  • Loading branch information
hviana committed Dec 15, 2024
1 parent 6177ed0 commit ee78a04
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ More details: [deno_kv_fs](https://github.com/hviana/deno_kv_fs)
- **Before Processing (`before?: RouteFn[]`):** List of middleware functions
(see: [faster](https://github.com/hviana/faster)). Use to check headers
(`ctx.req.headers`) or search params (`ctx.url.searchParams`), like tokens,
impose rate limits, etc.
impose rate limits etc.

> **Note:** To cancel page processing, do not call `await next()` at the end
> of a middleware function.
Expand Down Expand Up @@ -276,8 +276,10 @@ structure.
### 🌎 **Translations**

- **Organization:** Put the translation file in a json in `static/translations`.
For example `static/translations/en/index.json` It is relative to the
component in `frontend/components/index.tsx` for the `en` language.
For example `static/translations/en/general.json`. The i18next library
currently does not support nested namespaces. So don't use subdirectories. You
can, however, in the same file, use as many subkeys as you want
(`mykey1.mykey2` etc).
- **File Extensions:** Use `.json` files.
- **Usage:**

Expand All @@ -286,9 +288,9 @@ In `frontend/components/index.tsx`:
```jsx
import { useTranslation } from "@helpers/frontend/translations.ts";
const Home = () => {
const T = useTranslation({ ns: ["index"] });
const T = useTranslation({ ns: ["general"] });
//Any .init parameter of i18next is valid in useTranslation.
//Ex: useTranslation({ ns: ["index"], lng: ["es"], fallbackLng: "en" }), etc.
//Ex: useTranslation({ ns: ["general"], lng: ["es"], fallbackLng: "en" }) etc.
//On the client side, the language is automatically detected (if you don't specify).
//On the server, the language is "en" (if you don't specify).
return (
Expand All @@ -300,7 +302,7 @@ const Home = () => {
export default Home;
```

In `static/translations/en/index.json`:
In `static/translations/en/general.json`:

```json
{
Expand Down Expand Up @@ -535,7 +537,7 @@ deno task serve
Production:

```bash
deno serve main.ts #Add your permissions, port, certificate, etc. see: https://docs.deno.com/runtime/reference/cli/serve
deno serve main.ts #Add your permissions, port, certificate etc. see: https://docs.deno.com/runtime/reference/cli/serve
```

---
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { route } from "@helpers/frontend/route.ts";
import { useTranslation } from "@helpers/frontend/translations.tsx";

const Home = () => {
const T = useTranslation({ ns: ["index"] });
const T = useTranslation({ ns: ["general"] });
return (
<div className="min-h-screen flex flex-col bg-gradient-to-b from-white to-gray-50">
<script src="https://cdn.tailwindcss.com"></script>
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"lock": false,
"imports": {
"builder": "https://deno.land/x/faster_react_core@v4.6/builder.ts",
"@helpers/": "https://deno.land/x/faster_react_core@v4.6/helpers/",
"builder": "https://deno.land/x/faster_react_core@v4.8/builder.ts",
"@helpers/": "https://deno.land/x/faster_react_core@v4.8/helpers/",
"@core": "./main.ts",
"react": "https://esm.sh/[email protected]",
"react/": "https://esm.sh/[email protected]/",
Expand Down

0 comments on commit ee78a04

Please sign in to comment.