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

roots-i18n

v0.2.1

Published

A naïve i18n extension for the Roots static site generator ecosystem

Downloads

16

Readme

roots-i18n

A naïve i18n extension for the Roots static site generator ecosystem.

This extension makes many assumptions. It is not (yet) a catch-all solution to i18n in Roots. However, within strict limitations, it can be considered production ready.

Installation

$ npm i --save-dev roots-i18n

Usage

Configuration

roots-i18n requires that your translations are saved as a local file in yaml format. Each language should be in a separate file. Your folder structure might look something like this:

root
 ├─ views
 ├─ assets
 ├─ i18n
 │   ├─ en.yaml
 │   └─ es.yaml
 ├─ app.coffee
 └─ ...

Each language file should be named using the 2-letter language code, as above. The contents of es.yaml might look like this:

dir: es/
lang: es

homepage:
  title: Inicio
  message: empezar aquí y elegir una categoría

login:
  title: iniciar sesión / inscribirse

faq:
  title: Preguntas Frecuentes

dashboard:
  title: Tu cuadro de mandos

  tabs:
    requests: Solicitudes
    quotes: Presupuestos
    jobs: Trabajos
    completed: Terminados

messaging:
  title: Mensajes

Those first 2 lines are not required for roots-i18n to work, but they can be useful in your view templates, explained below. dir is the name of the output subdirectory where the Spanish (for example) version of your website will be located.

The lang property is simply the 2-letter language code, the same as the filename.

Add roots-i18n to your extensions array as follows:

i18n = require 'roots-i18n'

module.exports =
  extensions: [
    # ...

    i18n(
      translations: 'i18n/*'
      viewExtension: 'jade'
      templatesGlob: ['request/**/*.html']
    )

    # ...
  ]

roots-i18n takes a configuration object with the following properties:

  • translations: This is a globbing pattern that matches all your translation yaml files, explained above.
  • viewExtension: This tells roots-i18n how to identify your view templates.
  • templatesGlob: This property exists to play nicely with roots-records. If you're not using that extension, you can omit this property. If you are, this should be a globbing pattern (or an array of patterns) that identifies all your roots-records "single view templates".

roots-i18n assumes that the default language of your site is English, and places translated versions of the site in subdirectories named after the 2-letter language code, i.e. a Spanish homepage would be at example.com/es/, with the English homepage at example.com/. It only handles view templates – assets are untouched. roots-i18n assumes that all assets are non-language-specific, and are accessed at the root directory of your site.

Usage in your templates

roots-i18n exposes a mustache-esque syntax inside your templates. Here are some examples in jade, using the above es.yaml example file:

div.faq
  :marked
    ## {{ faq.title }}
- var tabs = ['requests', 'quotes', 'jobs', 'completed']

nav.dashboard-nav
  ul
    each tab in tabs
      li.check-tabs
        label
          input(
            type="radio",
            name="dashboard-nav",
            value= tab)
          span {{ dashboard.tabs.#{tab} }}
doctype html
html(lang='{{ lang }}')
a(href='/{{ dir }}') {{ homepage.title }}