Skip to content

Commit

Permalink
i18n: fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Oct 28, 2023
1 parent 08ddc16 commit e2c4a00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
32 changes: 16 additions & 16 deletions docs/modules/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ add keys and translations in the following format.

```json caption=locales/en-US.js
{
"welcome", "Hi and welcome, {username}",
"welcome": "Hi and welcome, {username}",
"message": "This is my website, feel at home here.",
"bye": "Bye",
"switch-language": "Switch language",
Expand All @@ -45,7 +45,7 @@ Add another locale.

```json caption=locales/de-DE.js
{
"welcome", "Hallo und willkommen, {username}",
"welcome": "Hallo und willkommen, {username}",
"message": "Das ist meine Website. Mache dich hier gemütlich.",
"bye": "Tschüss",
"switch-language": "Sprache wechseln",
Expand All @@ -63,31 +63,31 @@ That's all you need in terms of preparation.
Use the default export from `@primate/i18n/svelte` in your components. Since it
exposes a store, subscribe to it with `$`.

```js
```js caption=components/Home.svelte
<script>
import t from "@primate/i18n/svelte";

export let username;
</script>
<h1>{$t("welcome", {username}<h1/>
<h1>{$t("welcome", {username})}</h1>

<p>{$t("message")}<p>
<p>{$t("message")}</p>

{$t("bye")}~
```

To create a language switcher, import `locale` and call `locale.set` with the
new locale.

```js
```js caption=components/Home.svelte
<script>
import {default as t, locale} from "@primate/i18n/svelte";

export let username;
</script>
<h1>{$t("welcome", {username}<h1/>
<h1>{$t("welcome", {username})}</h1>

<p>{$t("message")}<p>
<p>{$t("message")}</p>

{$t("bye")}~

Expand All @@ -101,15 +101,15 @@ new locale.
Use the default export from `@primate/i18n/react` in your components. For
Solid, use `@primate/i18n/solid` instead.

```jsx
```jsx caption=components/Home.jsx
import t from "@primate/i18n/react";
// import t from "@primate/i18n/solid"; // for solid

export default function ({username}) {
return <>
<h1>{t("welcome", {username}<h1/>
<h1>{t("welcome", {username})}</h1>

<p>{t("message")}<p>
<p>{t("message")}</p>

{t("bye")}~
</>;
Expand All @@ -125,15 +125,15 @@ import {default as t, locale} from "@primate/i18n/react";

export default function ({username}) {
return <>
<h1>{t("welcome", {username}<h1/>
<h1>{t("welcome", {username})}</h1>

<p>{t("message")}<p>
<p>{t("message")}</p>

{t("bye")}~

<h3>{t("switch-language")}</h3>
<div><a onclick={() => locale.set("en-US")}>{t("English")}</a></div>
<div><a onclick={() => locale.set("de-DE")}>{t("German")}</a></div>
<div><a onClick={() => locale.set("en-US")}>{t("English")}</a></div>
<div><a onClick={() => locale.set("de-DE")}>{t("German")}</a></div>
</>;
}
```
Expand All @@ -156,7 +156,7 @@ locale using the locale switcher. In all cases, if the desired locale cannot be
found, this value will be used as a fallback.

Primate will issue a `MissingDefaultLocale` warning and disable this module if
a file doesn't exist for this locale in `directory`.
a translation file doesn't exist for this locale in `directory`.

## Error list

Expand Down
6 changes: 3 additions & 3 deletions packages/i18n/src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default ({
MissingLocaleDirectory.warn(app.log, root);
});

const locales = await Promise.all((await root.collect(/^.*.json$/u))
const locales = from(await Promise.all((await root.collect(/^.*.json$/u))
.map(async path => {
const depathed = `${path}`.replace(`${root}/`, () => "")
.slice(0, ending);
Expand All @@ -60,7 +60,7 @@ export default ({
`${path}`.replace(`${root}/`, () => "").slice(0, ending),
await path.file.json(),
];
}));
})));

disable(Object.keys(locales).length === 0, () => {
EmptyLocaleDirectory.warn(app.log, root);
Expand All @@ -72,7 +72,7 @@ export default ({

app.log.info("all locales nominal", { module });

env.locales = from(locales);
env.locales = locales;
} catch (_) {
active = false;
app.log.warn("module disabled", { module });
Expand Down

0 comments on commit e2c4a00

Please sign in to comment.