Skip to content

maxnachlinger/hapi-l10n-gettext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hapi-l10n-gettext

A localization plug-in for HapiJS https://www.npmjs.com/package/hapi-l10n-gettext

Build Status Dependency Status

Installation:

npm i hapi-l10n-gettext

Plug-in options and setup:

// register as you would any other hapi plug-in
server.pack.register([
    // additional plug-ins here
    {
        plugin: require('hapi-l10n-gettext'),
        options: {
            // the name of the cookie this plug-in will set to store locale
            cookieName: '_locale',
            // optional: where your PO/MO files live, if no filesa are found, a debugging 
            // "test" locale will be used.
            l10nDirectory: path.resolve(__dirname, 'locales'),
            // optional (default 'en') - language used when neither the cookie nor the 
            // accept-language header are present
            defaultLocale: 'en',
            // optional: routes to exclude from localization
            excludedRoutes: [assetRoute],
            // optional: routes to include in localization
            includedRoutes: appRoutes
        }
    }
], function (err) {
    if (err) throw err;
    server.start(function () {
        server.log('info', 'Server running at: ' + server.info.uri);
    });
});

Localization methods provided to JS code

request.l10n = {
    gettext, // get a bit of text
    pgettex, // get text within a context
    ngettext, // get singular or plural text
    npgettext // get singular or plural text within a context
    // An array of locales found in the parsed PO/MO files
    locales: [{locale: 'en', name: 'English', selected: true}],
    selectedLocale: {locale: 'en', name: 'English', selected: true}, // the currently selected locale
    // whether or not PO/MO files were found
    devMode: false
}

Localization methods provided to view templates

(Added to response.source.context)

// An array of locales found in the parsed PO/MO files
locales: [{locale: 'en', name: 'English', selected: true}]
selectedLocale: {locale: 'en', name: 'English', selected: true}, // the currently selected locale
gettext, // get a bit of text
pgettex, // get text within a context
ngettext, // get singular or plural text
npgettext // get singular or plural text within a context

There's also an example app to get more of an idea how to use this plug-in.

Contributors

Here's a list, thanks for your help!

About

A localization plug-in for HapiJS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •