Skip to content

Latest commit

 

History

History
92 lines (60 loc) · 2.4 KB

i18n.md

File metadata and controls

92 lines (60 loc) · 2.4 KB

i18n

Documentation: Chrome i18n API

A promise-based wrapper for the Chrome i18n API.

Methods


isAvailableI18n

isAvailableI18n(method?: ApiMethodName<typeof chrome.i18n>): boolean

The optional method is a native function name, for example isAvailableI18n("getMessage"). Import the public ApiMethodName type from @addon-core/browser for your own typed helpers. This checks callable presence without invoking the method; permissions and argument support still require handling.

Returns true when the i18n namespace is present on the API selected by browser() in the current context. Returns false if the namespace or WebExtension environment is absent, or if accessing it throws. The check is synchronous, does not log, and reads the current API on every call without caching. Without an argument, it checks namespace presence only. Pass a native method name to also check that it is callable. Neither form verifies permissions, argument support, or a successful operation. See method availability.

import {isAvailableI18n} from "@addon-core/browser";

if (isAvailableI18n()) {
    // The namespace is present; handle operation-specific failures when using it.
}

detectI18Language

detectI18Language(text: string): Promise<chrome.i18n.LanguageDetectionResult>

Detects the primary language of the provided text.

getI18nAcceptLanguages

getI18nAcceptLanguages(): Promise<string[]>

Retrieves the user's preferred accept languages list.

getI18nUILanguage

getI18nUILanguage(): string | undefined

Returns the browser's UI language code.

getI18nMessage

getI18nMessage(key: string): string | undefined

Retrieves the localized message for the specified key.

getDefaultLanguage

getDefaultLanguage(): string | undefined

Extracts the default locale as declared in the extension manifest.