npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tauri-plugin-sys-locale-api

v0.1.2

Published

JS/TS bindings for tauri-plugin-sys-locale

Readme

tauri-plugin-sys-locale

A Tauri v2 plugin that reads the current operating system locale/language. Works cross-platform (Windows, macOS, Linux, and thanks to the sys-locale crate also iOS/Android), without needing any custom native Swift/Kotlin code.

1. Installation (Rust side)

In your Tauri app's Cargo.toml (src-tauri/Cargo.toml):

[dependencies]
tauri-plugin-sys-locale = tauri-plugin-sys-locale = "*"

In src-tauri/src/main.rs:

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_sys_locale::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

2. Enable the capability

In src-tauri/capabilities/default.json (or whichever capability file applies), add the permission:

{
  "identifier": "default",
  "windows": ["main"],
  "permissions": ["sys-locale:default"]
}

3. Installation (frontend side)

npm install tauri-plugin-sys-locale-api

4. Usage in the frontend

import { getLocale, getLocaleInfo } from "tauri-plugin-sys-locale-api";

const locale = await getLocale();
console.log(locale); // e.g. "de-DE"

const info = await getLocaleInfo();
console.log(info.language); // e.g. "de"

5. Using the functions directly from Rust (no JS/invoke needed)

The core logic lives in plain pub fns in src/api.rs (not tagged with #[tauri::command]), so you can call them from any Rust code — inside a Tauri command, a background task, setup(), etc. — without going through the frontend at all:

use tauri_plugin_sys_locale::api;

fn some_backend_logic() {
    match api::get_locale() {
        Ok(locale) => println!("System locale: {locale}"),
        Err(e) => eprintln!("Could not determine locale: {e}"),
    }

    // or with locale + language split apart:
    if let Ok(info) = api::get_locale_info() {
        println!("locale={}, language={}", info.locale, info.language);
    }
}

You can even call it directly inside main.rs, e.g. to set an initial window title or pick a translation file before the app finishes starting:

fn main() {
    let locale = tauri_plugin_sys_locale::api::get_locale()
        .unwrap_or_else(|_| "en-US".into());
    println!("Starting app with locale: {locale}");

    tauri::Builder::default()
        .plugin(tauri_plugin_sys_locale::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

The commands.rs module just wraps these same functions with #[tauri::command] so the frontend can reach them via invoke() — both paths call identical logic.

Why sys-locale instead of custom native code?

The sys-locale crate already wraps the platform-specific APIs:

  • Windows: GetUserDefaultLocaleName
  • macOS/iOS: NSLocale
  • Linux: environment variables (LANG, LC_ALL, ...)
  • Android: JNI call to Locale.getDefault()

That means you don't need a separate android/ or ios/ directory with Kotlin/Swift code, unlike many other Tauri plugins.

Building the JS bindings

npm install
npm run build

This compiles guest-js/index.ts into dist-js/index.js, dist-js/index.cjs, and the corresponding .d.ts type declarations.