Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KishiTheMechanic committed Oct 26, 2024
1 parent 7612413 commit 2e625e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elsoul/fresh-i18n",
"version": "0.9.0",
"version": "0.9.1",
"description": "A simple and flexible internationalization (i18n) plugin for Deno's Fresh framework.",
"runtimes": ["deno", "browser"],
"exports": "./mod.ts",
Expand Down
17 changes: 7 additions & 10 deletions src/i18nPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// i18nPlugin.ts

import { join } from '@std/path'
import { pathname, translationData } from '@/src/store.ts'
import type { MiddlewareFn } from '@/src/types.ts'
import type { MiddlewareFn, TranslationState } from '@/src/types.ts'

/**
* Configuration options for the i18n plugin.
Expand Down Expand Up @@ -43,9 +41,7 @@ async function readJsonFile(filePath: string): Promise<Record<string, string>> {
*/
export const i18nPlugin = (
{ languages, defaultLanguage, localesDir }: I18nOptions,
): MiddlewareFn<
{ t: Record<string, Record<string, string>>; path: string; locale: string }
> => {
): MiddlewareFn<TranslationState & { [key: string]: unknown }> => {
return async (ctx) => {
const url = new URL(ctx.req.url)
const pathSegments = url.pathname.split('/').filter(Boolean)
Expand All @@ -58,11 +54,12 @@ export const i18nPlugin = (
? '/' + pathSegments.slice(1).join('/')
: url.pathname

// Set the current state values
ctx.state.path = rootPath
ctx.state.locale = lang

pathname.value = rootPath

// Set the current locale in the state
ctx.state.locale = lang
const translationDataSSR: Record<string, Record<string, string>> = {}

/**
Expand All @@ -81,10 +78,10 @@ export const i18nPlugin = (
}
}

// Load the common and metadata namespace and additional namespaces based on the URL path.
// Load the common namespaces and additional namespaces based on the URL path.
await loadTranslation('common')
await loadTranslation('error')
await loadTranslation('metadata')

for (
const segment of pathSegments.slice(lang === pathSegments[0] ? 1 : 0)
) {
Expand Down

0 comments on commit 2e625e5

Please sign in to comment.