Get available languages for one page
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Get available languages as links on one page


Install using npm.

 $ npm install hexo-helper-page-languages --save


In your front-matter.

The default language, in /en/docs/

title: Hello World
lang: en
contentId: hello-word

A translated version file, if /fr/docs/

title: Bonjour le monde
lang: fr
contentId: hello-word

If contentId is not provided, the full path except language will be used as value. The contentId variable is really usefull only if your file names are translated.

This can come handy if you care about SEO.

This other example can work because of the same file names.

The default language, in /en/docs/

title: Introduction
lang: en

A translated version file, if /fr/docs/

title: Bonjour le monde
lang: fr

in your ejs templates

List all pages for the same contentId.

    <dt><%= __('docs.otherlang') %></dt>
    <% var versions = getPageLanguages();
    for (var i=0; i<versions.length; i++) { %>
    <dd><a href="<%= versions[i].url %>"><%= versions[i].label %></a></dd>
    <% } %>

getPageLanguages return an array of objects, with:

  • url: full path url, example /fr/docs/bonjour.html
  • label: two letter code for the language, like fr