Skip to content

atmajs/i18n

Repository files navigation

Localization Module (NodeJS and Browser)


Build Status NPM version Bower version

  • MaskJS Localization Util
  • Localization Function

Node.js

Resolve language from the current request(middleware)

Browser

Resolve language from navigator.language or location.query ('/?language=en')

If the language is not supported, the default one is taken.

Formatter

Atma-Formatter is used to format/interpolate strings.

Pluralization

Refer to the atma-formatter.

Usage

Mask Util

~[L: ID [,...expressions]] ~[L: (expression) [,...expressions]]

  • Simple: ~[L:fooId]

  • Formatting:

    Example:

     	header > '~[L:welcomeId, name]'
     	// same as
     	header > '~[L:"welcomeId", name]'
     $L.extend('en', {
     	welcome: 'Hello {0}!'
     });
     mask.render(template, { name: 'Baz' });
  • get i18n ID from model: Example:

     	var menu = [ 'todo', 'task' ]
     	ul {
     		for (item of menu) {
     			li > '~[L:("m_" + item)]'
     		}
     	}
     $L.extend('en', {
     	m_todo: 'My Todos',
     	m_task: 'My Tasks'
     });
     mask.render(template);
Function

Browser @see examples

	$L('titleHello');

Node

	connect
		.use($L.middleware({
			support: [ 'en', 'de', 'ru' ],
			path: '/public/localization/%%.json'
		});
	// Aftewards each `req` has `$L` function.
	// Or use direct
	$L.fromReq(req)('id');

Configuration

IncludeJS
Browser

Load this library with IncludeJS - after defining the list of supported languages and the path to translations, it will load also supported translations

include
	.embed('/atma/localization.js?path=/public/i18n/%%.json&langs=de,it,fr')
	.done(function(){
		// appropriate translationis is loaded and ready to use
		$L('welcome', 'Baz')
	});
	
NodeJS

Use the middleware function so that not all translations are loaded at once, but only with the first incomming request.


(c) MIT, Atma.js Project

About

Localization

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors