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 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-vue-chrome-i18n

v0.0.7

Published

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua)

Downloads

12

Readme

Stand With Ukraine


vite-plugin-vue-chrome-i18n

A plugin for the Vite that extracts and scope translations from Vue Single File Component and combines them into a localization file for browser extensions.

Terms of use[?]

By using this project or its source code, for any purpose and in any shape or form, you grant your implicit agreement to all the following statements:

  • You condemn Russia and its military aggression against Ukraine
  • You recognize that Russia is an occupant that unlawfully invaded a sovereign state
  • You support Ukraine's territorial integrity, including its claims over temporarily occupied territories of Crimea and Donbas
  • You reject false narratives perpetuated by Russian state propaganda

Installation

npm i -D vite-plugin-vue-chrome-i18n

Usage

First add plugin to your vite configuration.

Note: This plugin was designed to be used alongside with @vitejs/plugin-vue.

// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueChromeI18n from "vite-plugin-vue-chrome-i18n";

export default defineConfig({
    plugins: [
        vue(),
        VueChromeI18n({
            // Optional. 
            // You can define any global localisation messages with will be defined for all components 
            initialLocales: {
                en: {
                    APP_NAME: {
                        message: 'My App'
                    }
                },
                uk: {
                    APP_NAME: {
                        message: 'Мій застосунок'
                    }
                }
            }
        }),
    ],
})

To add localized messages, use the <chrome-i18n> block with the locale attribute. One for each locale you need.

Inside of this block, enter the message in JSON format according to the Localization message formats.

Note that:

  1. All messages inside the component will be isolated from other messages. So, in most cases, you don't have to worry about naming conflicts.
  2. '$schema' will be automatically excluded from merged messages. So you can safely use it to get hints in your IDE.

To get access to translated message use getMessage function from vite-plugin-vue-chrome-i18n/getMessage.js. This function is synonymous with notifications. Under the hood, it automatically searches for messages in an isolated scope of a component or in global scope.

<!-- Any vue single file component -->
<script setup>
import { getMessage } from "vite-plugin-vue-chrome-i18n/getMessage.js";

console.log( getMessage('title') ) // 'Hello!' | 'Привіт!' // messages from local scope
console.log( getMessage('APP_NAME') ) // 'My App' | 'Мій застосунок' // messages from global scope
</script>

<chrome-i18n locale="uk">
{
  "$schema": "https://json.schemastore.org/browser.i18n.json",
  "title": {
    "message": "Привіт!"
  }
}
</chrome-i18n>

<chrome-i18n locale="en">
{
  "$schema": "https://json.schemastore.org/browser.i18n.json",
  "title": {
    "message": "Hello!"
  }
}
</chrome-i18n>

After build, you should get _locales/en/messages.json and _locales/uk/messages.json files with all extracted and scoped messages.