3.2.0 • Published 8 months ago

os-lang v3.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

os-lang

Get the system lang

NPM version Codacy Badge Test coverage npm download License

Sonar

Install

# use pnpm
$ pnpm install -D os-lang

# use yarn
$ yarn add -D os-lang

# use npm
$ npm install -D os-lang

Usage

use import

import {
  // getWinLang, // get windows lang
  // getWinLangSync,// get windows lang sync
  // getMacLang, // get mac os lang
  // getMacLangSync, // get mac os lang sync
  // getUnixLang, // get unix lang
  // getUnixLangSync, // get unix lang sync
  getEnvLang,
  osLang,
  osLangSync
} from 'os-lang'

osLang()
// or
osLangSync()

use require

const { osLang, osLangSync } = require('os-lang')

osLang()
// or
osLangSync()

API reference

  • Usage: osLang(options) & osLangSync(options)
  • Parameters: none

  • Types:

declare function getEnvLang(env?: NodeJS.ProcessEnv): string | undefined

declare function getMacLang(): Promise<string>

declare function getMacLangSync(): string

declare function getUnixLang(): Promise<string | undefined>

declare function getUnixLangSync(): string | undefined

declare function getWinLang(): Promise<string | undefined>

declare function getWinLangSync(): string | undefined

declare type Lang = 'en-US' | 'zh-CN' | string

declare function osLang(options?: OsLangOptions): Promise<any>

declare function osLangSync(options?: OsLangOptions): any
  • Demos:
  1. simple use
import { osLang, osLangSync } from 'os-lang'

const lang = osLangSync()
// lang => zh-CN
  1. Only resolve the locale from environment variables.
import { getEnvLang } from 'os-lang'

const lang = getEnvLang()
// lang => zh-CN

Issues & Support

Please open an issue here.

License

MIT