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

@dzangolab/vue-locale-switcher

v0.12.1

Published

A locale switcher component for vue.js

Downloads

127

Readme

@dzangolab/locale-switcher

LocaleSwitcher component for Vue. Supports SSR apps.

Requirements

  • vue.js >= 3.0
  • vue-router >= 4.0
  • bootstrap >= 4.3.1

This component assumes that your app's route follow a naming convention. See Route naming convention.

Usage

Add the package to your app via npm:

npm install @dzangolab/vue-locale-switcher --save

or yarn:

yarn add @dzangolab/vue-locale-switcher

Add LocaleSwitcher globally

# main.js

import LocaleSwitcher from '@dzangolab/vue-locale-switcher'
import '@dzangolab/vue-locale-switcher/dist/localeSwitcher.css' // import stylesheet

app.use('LocaleSwitcher', LocaleSwitcher)

Add LocaleSwitcher inside a component

# MyComponent.vue

<script>
import LocaleSwitcher from '@dzangolab/vue-locale-switcher'
import '@dzangolab/vue-locale-switcher/dist/localeSwitcher.css' // import stylesheet

export default {
  components: {
    LocaleSwitcher
  }
}
</script>

PWA/SPA

<template>
  <LocaleSwitcher
    :locale="locale"
    :locales="locales" />
</template>

SSR mode

<template>
  <LocaleSwitcher
    :locale="locale"
    :locales="locales"
    :mode="ssr" />
</template>

Route naming convention

This component assumes that your app's route follow a specific naming convention, whereby each route name is defined as <basename>_<locale_code>.

For example your home page routes are defined as home_en for the en locale, home_fr for the fr locale, etc.

Props

locale

The current locale.

This setting is required.

locales

The available locales. An array of locales, in the following format:

[
  {
    code: 'en',
    name: 'English'
  },
  {
    code: 'fr',
    name: 'Français'
  },
  {
    code: '<locale identifyer>',
    name: '<locale name>'
  }
]

The locale code is whatever your app uses to identify the locale. We recommend the stanard ISO code, eg en, en_us`, etc.

The locale name is used to display the locale. We recommend using the localized locale name, eg 'English', 'Français', 'Deutsch', etc.

This setting is required.

mode

Determines the behavior of the component when a different locale is selected.

pwa (default)

When a different locale is selected, the vue-router will load the route associated with the selected locale.

Use this mode if your app has different routes for each page in different locales, such as /aboutus (en) vs /apropos (fr), or /home (en) vs /de (de).

spa

When a different locale is selected, the current route remains unchanged and the page is not reloaded. This assumes that your app will listen to the locale-switcher:localeChanged event and updates its locale somehow.

ssr

Set the mode to ssr if your app uses server side rendering.

When a different locale is selected, the url associated with this locale will be loaded.

theme

Specifies the theme to use to style the component. Currently 2 themes are provided:

bootstrap (default)

If this theme is selected, then the appropriate bootstrap classes will be set on the component. It is assumed that the component will be placed inside a bootstrap Navbar.

Custom styling is provided for device width below 992px.

custom

If this theme is selected, then custom BEM classes will be set on the component. Currently these classes are styled to resemble bootstrap, but they can easily be overridden inside your own stylesheet.

Events

The component fires the following events:

locale-switcher:localeChanged

Fired after a new locale has been set. The event includes the new locale value.

SCSS

Instead of importing the css file in component or main.js, you can also import scss file into your app scss file.

@import '~@dzangolab/vue-locale-switcher/src/assets/scss/locale-switcher.scss';