Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove .middleware() call #26

Merged
merged 5 commits into from
Sep 20, 2022
Merged
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
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,22 @@ Example bot
import { Bot, Context } from "https://deno.land/x/grammy/mod.ts";
import { I18n, I18nFlavor } from "https://deno.land/x/grammy_i18n/mod.ts";

// For proper typings and auto-completions in IDEs,
// customize the `Context` using `I18nFlavor`.
type MyContext = Context & I18nFlavor;

// Create a new I18n instance.
const i18n = new I18n({
const i18n = new I18n<MyContext>({
defaultLocale: "en",
directory: "locales",
});

// For proper typings and auto-completions in IDEs,
// extend the `Context` using `I18nFlavor`.
type MyContext = Context & I18nFlavor;

// Create a bot as usual, but use the modified Context type.
const bot = new Bot<MyContext>(""); // <- Put your bot token here

// Tell the bot to use the middleware from the instance.
// Remember to register this middleware before registering
// other middlewares.
bot.use(i18n.middleware());
// your handlers.
bot.use(i18n);

bot.command("start", async (ctx) => {
// Use the method `t` or `translate` from the context and pass
Expand Down
2 changes: 1 addition & 1 deletion examples/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bot.use(session({
initial: () => ({ apples: 0 }),
}));

const i18n = new I18n({
const i18n = new I18n<MyContext>({
defaultLocale: "en",
useSession: true,
directory: "locales",
Expand Down