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

docpad-plugin-polyglot

v2.1.2

Published

DocPad plugin for multilingual websites

Downloads

8

Readme

Polyglot Plugin for DocPad

Add multilanguage support for your site.

Heavily inspired and mostly based on multilang and the abandoned multilanguage plugins.

Install this DocPad plugin by entering docpad install polyglot into your terminal.

|Config|Default|Description| |---|---|---| |mainLanguage|(required)|The main language of the website. There is no specific format, but it is recommended to use some language code pattern, like IANA, ISO or IETF.| |languages|(required)|The languages the website will be translated into.| |omitMainFolder|true|Whether the main language files should be in the root of the website or have its own folder.|

Configuration

Add the necessary configuration into docpad.js:

plugins: {
  polyglot: {
    mainLanguage: "pt-br",
    languages: ["pt-br", "en"]
  }
}

Directory Structure

As omitMainFolder is true by default, only languages different from mainLanguage need to be inside its own folder:

project-folder
└─src/
  └─documents/
    ├─index.html # home in brazilian portuguese
    ├─sobre.html # brazilian portuguese
    └─en/ # all in english
      ├─index.html
      └─about.html

The generated URLs would be:

/index.html
/sobre.html
/en/index.html
/en/about.html

However, if omitMainFolder is false, each file must be inside its language folder, even for the main language:

project-folder
└─src/
  └─documents/
    ├─en/ # all in english
    │ ├─index.html
    │ └─about.html
    └─pt-br/ # all in brazilian portuguese
      ├─index.html
      └─sobre.html

The generated URLs would be:

/pt-br/index.html
/pt-br/sobre.html
/en/index.html
/en/about.html

How translations for a page are determined

At first the metadata of the page is searched for a dictionary named translations. In this dictionary if there are entries with the language keys then it is assumed that these pages are the translation of the current page. For instance for the page /postagem-poliglota.html, if there is a header

---
title: "Sobre"
layout: "default"
translations:
  en: about.html
---

then /en/about.html is assumed to be the translation to en of this page.

Note that the dictionary value (about.html) doesn't have any additional extension (eg. .html.md). It's only necessary to put the final extension in it.

For languages that are not specified with the translations dictionary, it is assumed that the name (including the path without the language directory) of the translated page is the same. In the above example, the file /en/sobre.html would be assumed as the en translation. If no such page is found in the database then it is assumed that there is no translation of the current page to that language.

Injected template data

The plugin injects some properties and functions into the template data so that they can be used in the template.

The functions are:

  • date({ date, format, lang }): Print the date of the article in a localized form. Takes several optional parameter: date and lang to use different values than the ones of the document. format to use a different date format as specified by Moment.js (defaults to LL).
  • hasLang(lang): Whether there is a translation of the current page to that language.
  • toLang(lang): Receives a language code as parameter and returns the URL of the translation of the current page. If there is no translation, it returns undefined.
  • otherLangs(): Dictionary with the other languages and their URLs that are available for this document. The object structure is { "<language>": "<translation URL>" }
  • langFromUrl(url): Allow to obtain current language from URL if @document.lang isn't available. Using @document.lang is prefered for performance.

The properties are:

  • mainLanguage: The main language, set on config
  • languages: List of the languages, set on config

Template data in use

Using the example defined above, if we wrote the following code into /en/about.html.eco:

- Lang: <%= @document.lang %>
- Lang from URL: <%= @langFromUrl(@document.url) %>
- Translation: <%= @toLang('pt-br') %>
- Has Portuguese: <%= @hasLang('pt-br') %>
- Has English: <%= @hasLang('en') %>
- Other languages: <%= JSON.stringify(@otherLangs()) %>

We would see the following output:

- Lang: en
- Lang from URL: en
- Translation: /sobre.html
- Has Portuguese: true
- Has English: true
- Other languages: { "pt-br": "/sobre.html" }

Injected document data

Properties are also injected into each document. They are:

  • lang: The language of the document.
  • translationURLs: Dictionary with all translations to the current page (including itself). Probably unnecessary with the functions in the template data.

Generated collections

For every language, a collection whose name is composed from lang_<language> is automatically created containing all files that have this language. For instance for the language pt-br there is a collection named lang_pt-br.

Discover the release history by heading on over to the HISTORY.md file.

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

These amazing people are maintaining this project:

No sponsors yet! Will you be the first?

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

Unless stated otherwise all works are:

and licensed under: