All Projects → grvcoelho → babelfish

grvcoelho / babelfish

Licence: MIT license
🐡 Straightforward library for translations and dictionaries

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to babelfish

Domino-English-Translation
🌏 Let's translate Domino, a Japanese MIDI editor!
Stars: ✭ 29 (-38.3%)
Mutual labels:  i18n
vue-example
Vue.js example application (server-side rendering, router, vuex store, form validation, i18n & l10n)
Stars: ✭ 62 (+31.91%)
Mutual labels:  i18n
JSON-i18n-Editor
Translate your i18n JSONs for your website or app with this tool
Stars: ✭ 29 (-38.3%)
Mutual labels:  i18n
pH7-Internationalization
🎌 pH7CMS Internationalization (I18N) package 🙊 Get new languages for your pH7CMS website!
Stars: ✭ 17 (-63.83%)
Mutual labels:  i18n
awesome-translations
😎 Awesome lists about Internationalization & localization stuff. l10n, g11n, m17n, i18n. Translations! 🌎🌍
Stars: ✭ 54 (+14.89%)
Mutual labels:  i18n
crowdin-api-client-ruby
The Crowdin Ruby Client is used to interact with the Crowdin API v2 from Ruby
Stars: ✭ 50 (+6.38%)
Mutual labels:  i18n
odoo-th
Ready to use Odoo with OCA Thai localization modules
Stars: ✭ 29 (-38.3%)
Mutual labels:  i18n
next-multilingual
An opinionated end-to-end solution for Next.js applications that requires multiple languages.
Stars: ✭ 135 (+187.23%)
Mutual labels:  i18n
LorittaLocales
🌎 Loritta's localization files, bringing Loritta's cuteness to everyone around the world!
Stars: ✭ 21 (-55.32%)
Mutual labels:  i18n
i18n-testing
International data for testing and QA
Stars: ✭ 61 (+29.79%)
Mutual labels:  i18n
cortexm-AES
high performance AES implementations optimized for cortex-m microcontrollers
Stars: ✭ 18 (-61.7%)
Mutual labels:  lib
grav-plugin-langswitcher
Grav LangSwitcher Plugin
Stars: ✭ 22 (-53.19%)
Mutual labels:  i18n
react-polyglot-hooks
Hooks for using Polyglot.js with React.
Stars: ✭ 26 (-44.68%)
Mutual labels:  i18n
markdown-i18n
i18n extension for Python Markdown
Stars: ✭ 13 (-72.34%)
Mutual labels:  i18n
laravel-translate
Generate translation files for Laravel using Google Translate
Stars: ✭ 22 (-53.19%)
Mutual labels:  i18n
cheatengine-threadstack-finder
List all thread's base address based on process id
Stars: ✭ 39 (-17.02%)
Mutual labels:  lib
metalsmith-paths
Metalsmith plugin that adds file path values to metadata
Stars: ✭ 19 (-59.57%)
Mutual labels:  lib
i18n
Yii i18n
Stars: ✭ 20 (-57.45%)
Mutual labels:  i18n
translate-go
https://babyblue94520.github.io/translate-go/dist/
Stars: ✭ 14 (-70.21%)
Mutual labels:  i18n
i18n-unused
The static analyze tool for finding, marking and removing unused and missing i18n translations in your JavaScript project
Stars: ✭ 76 (+61.7%)
Mutual labels:  i18n

babelfish

Build Status Coverage Status

Straightforward library for translations and i18n

Install

You can get it on npm.

npm install @grvcoelho/babelfish --save

If you're not into package management, just download a ZIP file.

Setup

First, you need to import it or require it:

import Babelfish from 'babelfish';

Then, you need to instantiate it and passing a dictionary object optionally:

let babelfish = new Babelfish({
	pt: {
		'APPLE': 'maçã'
	},
	en: {
		'APPLE': 'apple'
	}
});

Usage

Adding dictionaries:

babelfish.addDictionary('fr', {
	'APPLE': 'pomme'
});

Using dictionaries and translating:

babelfish.useDictionary('pt');
babelfish.translate('APPLE'); // "maçã"

You can also use functions as the translations:

babelfish.addDictionary('fr', {
	'APPLE': function() {
		return 'pomme' + '!';
	}
});

babelfish.useDictionary('fr');

babelfish.translate('APPLE'); // "pomme!"

You can handle pluralisation by passing an array as the translations, and passing a second argument to the .translate() method.

babelfish.addDictionary('pt', {
	'APPLE': [
		'Sem maçãs',
		'1 maçã',
		'%s maçãs'
	]
});

babelfish.useDictionary('pt');

babelfish.translate('APPLE'); // if no count is passed, 1 is the default. "1 maçã"
babelfish.translate('APPLE', 0); // "Sem maçãs"
babelfish.translate('APPLE', 1); // "1 maçã"
babelfish.translate('APPLE', 2); // "2 maçãs"
babelfish.translate('APPLE', 17); // "17 maçãs"

License

MIT © 2016

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].