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

nuxt-i18n-module

v0.4.0

Published

nuxt-i18n-module ================

Downloads

728

Readme

nuxt-i18n-module

Build Status npm

Internationalization module for Nuxt, with support for generating dynamic routes (SSR).

About

Adds the vue-i18n plugin, language-specific routes and html headers.

Given a page "foo":

└── pages
    └── foo.vue

This module will dynamically generate routes for a set of languages:

  • /en/foo: English version of the "foo" page.
  • /de/foo: German version of the "foo" page.
  • /foo: This page will detect the user's language on the client side and redirect to the appropriate language-URL if redirectDefaultLang is set to true.

Those routes will also be generated when rendering in SSR mode.

What about nuxt-community/nuxt-i18n?

The only advantage of this module over the official nuxt-community/nuxt-i18n is that it can generate translated versions of dynamic routes. See nuxt-i18n#21 for more details.

If you don't need to generate dynamic routes I recommend using the official module instead.

Installation & Configuration

Setup

1: Add nuxt-i18n-module dependency to your project using yarn or npm.

2: Add nuxt-i18n-module to the modules section of nuxt.config.js and configure as desired:

{
  modules: [
    ['nuxt-i18n-module', {
      languages: ['en', 'de']
    }]
  ]
}

The available options are:

| Name | Type | Default | Description | | ---- | --- | --- | --- | | languages | string[] | ["en"] | List of languages | | defaultLanguage | string | First language | Default language | | dateTimeFormats | Object | {} | Date time formats, see vue-i18n | | numberFormats | Object | {} | Number formats, see vue-i18n | | redirectDefaultLang | boolean | true | Redirect default lang to localized url (eg: redirect / to /en when en is your default language) | | rootUrl | ?string | null | Root URL to prepend to alternate links. Required by Google. |

3: Create files assets/locale/en.json and assets/locale/de.json with your global translation phrases. For example:

{
  "hello-world": "Hallo Welt!"
}

Usage

Localized Links (localePath())

URLs within the application need to be localized. To link to a URL in the current language, use localePath():

<nuxt-link :to="localePath('/foo')">Foo</nuxt-link>

Translate Phrases ($t())

To translate a phrase, use vue-i18n's $t():

<h1>{{ $t('hello-world') }}</h1>

Language Switcher (i18n-switcher)

The language switcher prints a list of links leading to translations of the current page in other languages:

<i18n-switcher/>

Vuex Store

This module registers a Vuex store module with the name i18n. It exposes the following functionality:

  • Mutation setLanguage(lang)
  • Getter getLanguage()

Development

Install dependencies:

yarn install

Run tests:

yarn run test

Tests build and generate Nuxt sites and check their HTML output. Sometimes it can be useful to inspect the generated sites manually. For that just serve the test's output folder, for example using the "serve" package:

npx serve test/tmp/nuxt.config-default/nuxt-generate/

Release a new version:

  1. Bump the version in package.json
  2. Commit, tag and push to master:
git commit -am 'version <version>'
git tag --annotate v<version>
git push --follow-tags
  1. Travis will deploy to NPM