# detectFromPath

**Kind:** Function

**Source:** [`src/middleware/language/language.ts`](https://github.com/honojs/hono/blob/main/src/middleware/language/language.ts#L176)

**Part of:** [Middleware](subsystem-src-middleware)

Detects language from URL path

`detectFromPath` reads a URL path and determines the language encoded in that path. It is used by the language middleware to select the request language before downstream handlers process the request.

## Signature

```ts
function detectFromPath(c: Context, options: DetectorOptions): string | undefined
```

## Parameters

| Name | Type |
|---|---|
| `c` | `Context` |
| `options` | `DetectorOptions` |

**Returns:** `string | undefined`

## Diagram

```mermaid
graph LR
  A[Request URL path] --> B[detectFromPath]
  B --> C[Detected language]
  C --> D[Language middleware]
  D --> E[Request handling]
```

## Usage

```ts
import { detectFromPath } from './middleware/language/language';

const language = detectFromPath('/en/docs/getting-started');

if (language) {
  console.log(`Detected language: ${language}`);
}
```

## AI Coding Instructions

- Pass the URL pathname rather than the full URL when calling `detectFromPath`.
- Keep path parsing rules consistent with the language prefixes supported by the middleware.
- Handle cases where no language is detected before selecting localized content.
- Update related routing and middleware behavior when changing language path formats.
