Skip to content
Draft

hi18n #653

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"fix:lint": "next lint --fix",
"fix:prettier": "prettier --write .",
"env": "vc env pull .env.local",
"prepare": "husky install"
"prepare": "husky install",
"i18n:sync": "hi18n sync 'pages/**/*.ts' 'pages/**/*.tsx' 'src/**/*.ts' 'src/**/*.tsx'"
},
"postcss": {
"plugins": {
Expand All @@ -27,12 +28,16 @@
}
},
"dependencies": {
"@hi18n/core": "^0.1.4",
"@hi18n/react": "^0.1.2",
"@hi18n/react-context": "^0.1.0",
"next": "12.1.6",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-error-boundary": "3.1.4"
},
"devDependencies": {
"@hi18n/cli": "^0.1.5",
"@playwright/test": "1.22.2",
"@tailwindcss/forms": "0.5.2",
"@tailwindcss/line-clamp": "0.4.0",
Expand Down
5 changes: 3 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "../src/style/index.css";

import { LocaleProvider } from "@hi18n/react";
import type { CustomAppPage } from "next/app";
import Head from "next/head";

Expand All @@ -11,12 +12,12 @@ const App: CustomAppPage = ({ Component, pageProps }) => {
});

return (
<>
<LocaleProvider locales="ja">
<Head>
<title>nexst</title>
</Head>
{getLayout(<Component {...pageProps} />)}
</>
</LocaleProvider>
);
};

Expand Down
19 changes: 19 additions & 0 deletions src/locale/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Message } from "@hi18n/core";
import { Book, Catalog, msg } from "@hi18n/core";

type Vocabulary = {
"example/greeting": Message;
};

const catalogEn = new Catalog<Vocabulary>({
"example/greeting": msg("Hello"),
});

const catalogJa = new Catalog<Vocabulary>({
"example/greeting": msg("こんにちは"),
});

export const book = new Book<Vocabulary>({
ja: catalogJa,
en: catalogEn,
});
6 changes: 5 additions & 1 deletion src/pages/index/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { useI18n } from "@hi18n/react";
import type { FC } from "react";
import { Button } from "src/component/Button";
import { book } from "src/locale";

export const Index: FC = () => {
const { t } = useI18n(book);

const handleClick = () => {
window.alert("Hello, World!");
window.alert(t("example/greeting"));
};

return (
Expand Down
Loading