New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

browser-extension-i18n

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-extension-i18n

I18N module for developing browser extensions and userscripts

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

browser-extension-i18n

I18N module for developing browser extensions and userscripts

Installation

npm i browser-extension-i18n
# or
pnpm add browser-extension-i18n
# or
yarn add browser-extension-i18n

Usage

Basic Setup

import { initAvailableLocales, initI18n } from "browser-extension-i18n"

// Define your message maps
const messageMaps = {
  en: {
    hello: "Hello",
    welcome: "Welcome, {1}!",
  },
  zh: {
    hello: "你好",
    welcome: "欢迎,{1}!",
  },
  "zh-tw": {
    hello: "您好",
  },
}

// Initialize available locales
initAvailableLocales(["en", "zh", "zh-tw"])

// Create translation function
const t = initI18n(messageMaps)

// Use translations
console.log(t("hello")) // Auto-detects browser language
console.log(t("welcome", "John")) // With parameters

API Reference

initAvailableLocales(locales: string[])

Initialize the list of supported locales.

initI18n(messageMaps: MessageMaps, language?: string): I18nFunction

Create a translation function. Auto-detects browser language if not specified.

getAvailableLocales(): readonly string[]

Get the list of currently available locales.

getBestMatchingLocale(preferredLanguage: string): string | undefined

Find the best matching locale for a given language preference.

isLocale(locale: string | undefined): boolean

Check if a string is a valid available locale.

extractLocaleFromNavigator(): string | undefined

Extract the best matching locale from browser language preferences.

License

Copyright (c) 2023 Pipecraft. Licensed under the MIT License.

>_

Pipecraft UTags

Keywords

extensions

FAQs

Package last updated on 23 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts