Skip to content
This repository has been archived by the owner on Feb 10, 2020. It is now read-only.
/ hadron-i18n Public archive

i18n for Hadron Applications

Notifications You must be signed in to change notification settings

mongodb-js/hadron-i18n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hadron-i18n

Extremely simple i18n support for hadron applications.

Installation

npm install --save hadron-i18n

Usage in Electron

In the renderer process entry point, for example src/renderer/index.js:

const path = require('path');
const electron = require('electron');
const I18n = require('hadron-i18n');

const LOCALES = path.join(__dirname, 'locales');

new I18n(electron.remote.app.getLocale()).load(LOCALES, (error, i18n) => {
  global.t = i18n.t
});

An example locale file, must be .yml and the filename must be lowercase. Example en-us.yml:

toolbar:
  home: "Home"
  list: "List"

An example React component that uses the translations:

const React = require('react');

class ToolbarComponent extends React.Component {
  render() {
    return (
      <div className="toolbar">
        <ol>
          <li>{global.t.toolbar.home}</li>
          <li>{global.t.toolbar.list}</li>
        </ol>
      </div>
    )
  }
}

License

Apache 2.0