scribe-translator
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Scribe Build Status

Scribe is a seriously lightweight translator for JavaScript with no dependencies that can be integrated into any project.


Usage

Scribe will not fetch translations, you should get the translations and pass them in the constructor. By default placeholders are define by prepending :.

import Scribe from 'scribe';
 
const translations = {
  buttons: {
    save: 'Save',
    udate: 'Update',
    delete: 'Delete'
  },
  validation: {
    range: 'Your range must be within :start and :end',
    contains: 'The string must contain these phrases: :contain, :contain, :contain',
    users: {
      email: 'Your email does not match.'
    }
  }
}
 
const scribe = new Scribe(translations, ':');
 
scribe.get('button.save'); // Save
scribe.get('validation.range', {start: 'Monday', end: 'Friday'}); // Your range must be within Monday and Friday
scribe.get('validation.contains', {contain: ['ayy lmao', 'such wow', 'doge']}); // The string must contain these phrases: ayy lmao, such wow, doge
scribe.get('validation.users.email'); // Your email does not match.

If you need to check if a translations exist you can simply use the has method.

let buttonLabel;
 
if (scribe.has('buttons.sync')) {
  buttonLabel = scribe.get('buttons.sync');
} else {
  buttonLabel = scribe.get('buttons.save');
}

Contributions

All contributions are welcomed. Please only edit src/scribe.ts and add tests if necessary.

Readme

Keywords

Package Sidebar

Install

npm i scribe-translator

Weekly Downloads

6

Version

1.1.0

License

MIT

Last publish

Collaborators

  • kyle_needham