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

elderjs-plugin-i18n

v0.0.4

Published

i18n support for your Elder.js powered website.

Downloads

28

Readme

Elder.js Plugin: i18n

npm version

i18n (internationalization) for elderjs. You will need elderjs v1.2.5 or higher.

Features

  • [x] 0kb js in the build.
  • [x] Automatic routes generation and custom paths.
  • [x] Search engine optimisation.
  • [x] Support language (in ISO 639-1 format) and optionally a region (in ISO 3166-1 Alpha 2 format).
  • [x] Access permalink/routes for alternative locales.
  • [ ] integration with svelte-i18n ( PR#3 )
  • [ ] Redirection

TODO

  • [ ] site example
  • [ ] Better documentation
  • [ ] More examples

Install

npm i -s elderjs-plugin-i18n # or yarn add elderjs-plugin-i18n

Config

Once installed, open your elder.config.js and configure the plugin by adding 'elder-plugin-i18n' to your plugin object.

plugins: {
  'elderjs-plugin-i18n': {
      locales: {
        default: 'fr',
        all: ['fr', { code: 'en', iso: 'en' }],
        excludes: ['en'],
      },
      permalink: {
        prefix: true,
        prefixDefault: false,
        lastSlash: true
      },
      seo: {
        hreflang: true,
        lang: true,
      }
  },

}

Locales

A locale in this plugin is defined like this:

{
  code: 'en', // your local code. It's used as an id and prefix for permalink.
  iso: 'en', // your iso code, e.g: `en` or `en-GB`.
  origin: 'https://different-origin.uk' // ( Optional ). Set a diffent domains/subdomains.
  }

In the configuration: all: An array containing all your locales as define previously.

You can also use a simple string as a shortcut, e.g: 'fr' become { code: 'fr', iso: 'fr'} .

default: The default locale code.

excludes: An array of locale code to excludes from generation, but keeping the links. Can be used in the case of internationalization with multiples domains.

Permalink

prefix: add the corresponding locale locale before the permalink. e.g: /example with {code: 'en'} locale will become /en/example.

defaultPrefix: if the default locale should have a prefix or not.

lastSlash: when asking for a permalink through this plugins, should it return the last slash or not.

Seo

hreflang: Generate hreflang links into the head of your document.

lang: Add the lang attribute with th corresponding locale to your body.

Helpers

This plugin come with somes helpers define in helpers.i18n accessible in your route.js file. These helpers can be describe in two categories:

Generation

They generate the new routes according to the plugins options. They have to be used in your route.js for the pages you want to internationalize.

  • generateRequests([request]) : [request]: generate requests for each locales. It will add a locale attributes.
  • generatePermalink(permalink, locale): permalink: generate permalink according to plugins options and a given locale.

Access

  • permalink(request) : permalink: act as the default permalink helpers
  • allPermalinks({route, slug}) : [permalink] get permalinks for each locales

Example

// route.js

module.exports = {
  all: async ({ helpers }) => helpers.i18n.generateRequests([{slug: 'example'}]), // [{slug: 'example', locale: 'en'}, ...]
  permalink: ({ request, helpers }) => helpers.i18n.generatePermalink(request.slug, request.locale), // '/en/example'
  data: async ({ helpers, request }) => { links: helpers.i18n.allPermalinks(request), }, // [{ locale: 'en', permalink: '/en/example' }, ...]
  }