---
title: AcceptLanguage
source: https://github.com/remix-run/remix/blob/remix@3.0.0-beta.3/packages/headers/src/lib/accept-language.ts#L17
---

# AcceptLanguage

## Summary

The value of a `Accept-Language` HTTP header.

[MDN `Accept-Language` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language)

[HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.5)

## Signature

```ts
class AcceptLanguage {
  constructor(init: string | AcceptLanguageInit): AcceptLanguage;

  // Accessors
  get languages(): string[];
  get size(): number;
  get weights(): number[];

  // Methods
  [iterator](): IterableIterator<[string, number]>;
  accepts(language: string): boolean;
  clear(): void;
  delete(language: string): void;
  entries(): IterableIterator<[string, number]>;
  forEach(
    callback: (
      language: string,
      weight: number,
      header: AcceptLanguage,
    ) => void,
    thisArg: any,
  ): void;
  get(language: string): number | null;
  getPreferred<language extends string>(
    languages: readonly language[],
  ): language | null;
  getWeight(language: string): number;
  has(language: string): boolean;
  set(language: string, weight: number): void;
  toString(): string;
  from(value: string | AcceptLanguageInit | null): AcceptLanguage;
}

```

## Accessors

### `languages`

An array of all languages in the header.

### `size`

The number of languages in the header.

### `weights`

An array of all weights (q values) in the header.

## Methods

### `[iterator](): IterableIterator<[string, number]>`

Iterates over language and weight pairs in preference order.



### `accepts(language: string): boolean`

Returns `true` if the header matches the given language (i.e. it is "acceptable").

#### Parameters

##### `language`

The locale identifier of the language to check

### `clear(): void`

Removes all languages from the header.



### `delete(language: string): void`

Removes a language with the given locale identifier.

#### Parameters

##### `language`

The locale identifier of the language to remove

### `entries(): IterableIterator<[string, number]>`

Returns an iterator of all language and weight pairs.



### `forEach(callback: (language: string, weight: number, header: AcceptLanguage) => void, thisArg: any): void`

Invokes the callback for each language and weight pair.

#### Parameters

##### `callback`

The function to call for each pair

##### `thisArg`

The value to use as `this` when calling the callback

### `get(language: string): number | null`

Gets the weight of a language with the given locale identifier. If it is not in the header
verbatim, this returns `null`.

#### Parameters

##### `language`

The locale identifier of the language to get

### `getPreferred<language extends string>(languages: readonly language[]): language | null`

Returns the most preferred language from the given list of languages.

#### Parameters

##### `languages`

The locale identifiers of the languages to choose from

### `getWeight(language: string): number`

Gets the weight of a language with the given locale identifier. Performs wildcard and subtype
matching, so `en` matches `en-US` and `en-GB`, and `*` matches all languages.

#### Parameters

##### `language`

The locale identifier of the language to get

### `has(language: string): boolean`

Checks if the header contains a language with the given locale identifier.

#### Parameters

##### `language`

The locale identifier of the language to check

### `set(language: string, weight: number): void`

Sets a language with the given weight.

#### Parameters

##### `language`

The locale identifier of the language to set

##### `weight`

The weight of the language (default: `1`)

### `toString(): string`

Returns the string representation of the header value.



### `from(value: string | AcceptLanguageInit | null): AcceptLanguage`

Parse an Accept-Language header value.

#### Parameters

##### `value`

The header value (string, init object, or null)