0.5.9 • Published 6 years ago

atma-i18n v0.5.9

Weekly downloads
3
License
-
Repository
github
Last release
6 years ago

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:_
    	```scss
    		header > '~[L:welcomeId, name]'
    		// same as
    		header > '~[L:"welcomeId", name]'
    	```
    	```javascript
    	$L.extend('en', {
    		welcome: 'Hello {0}!'
    	});
    	mask.render(template, { name: 'Baz' });
    	```
  • get i18n ID from model: Example:
    	```scss
    		var menu = [ 'todo', 'task' ]
    		ul {
    			for (item of menu) {
    				li > '~[L:("m_" + item)]'
    			}
    		}
    	```
    	```javascript
    	$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

0.5.9

6 years ago

0.5.6

6 years ago

0.5.4

6 years ago

0.5.2

6 years ago

0.0.71

10 years ago

0.0.65

10 years ago

0.0.64

10 years ago

0.0.63

10 years ago

0.0.62

10 years ago

0.0.61

10 years ago

0.0.60

10 years ago

0.0.59

10 years ago

0.0.58

10 years ago

0.0.57

10 years ago

0.0.56

10 years ago