From c6f8b4c6dee462e6230e74d8646449685184910a Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 23 Jun 2014 23:12:26 +0200 Subject: [PATCH 1/3] Update README.md --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index e69de29..cad4521 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,27 @@ +## madlib-locale +Need support for multiple languages/locales in your project? This module adds several helpers to Handlebars to extend it to help you accomplish exactly this. It can format dates, numbers, money and "translate" texts. Next to that it will help you load the locale file when changing the language setting. + +## Installation: +The generator is available in the global NPM: + +```shell +npm install -g madlib-locale +``` + +## Usage + +To use it you will need to require the module, the module itself will export an singleton object. +Before rendering any templates you will first need to call the initialize function to pass the Handlebars +reference to extend with the helpers and set the default locale. Calling initialize will return an promise +when this is resolved the locale file loaded and you can savely render your templates. + +```shell +localeManager = require( "madlib-locale" ) +localeManager.setLocale( Handlebars, "en_GB" ).then( + () -> + ## Ready to render templates using the helper functions +, () -> + console.error( "something went wrong...." ) +).done() + +``` From d698607ca6d6acbdbf1f86fd42433353f28df950 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 23 Jun 2014 23:27:02 +0200 Subject: [PATCH 2/3] Update README.md --- README.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cad4521..5635079 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,46 @@ ## madlib-locale -Need support for multiple languages/locales in your project? This module adds several helpers to Handlebars to extend it to help you accomplish exactly this. It can format dates, numbers, money and "translate" texts. Next to that it will help you load the locale file when changing the language setting. +Need support for multiple languages/locales in your project? This module adds several helpers to Handlebars to extend it to help you accomplish exactly this. It can format dates, numbers, money and "translate" texts. Next to that it will help you load the locale file (async) when changing the language setting. + +The module used the following modules to achieve all of this: +- accounting: http://josscrowcroft.github.io/accounting.js/ +- moment: http://momentjs.com/ +- node-polyglot: https://github.com/ricardobeat/node-polyglot ## Installation: -The generator is available in the global NPM: +The module is available in the global NPM: ```shell -npm install -g madlib-locale +npm install madlib-locale --save ``` -## Usage +## Setup To use it you will need to require the module, the module itself will export an singleton object. Before rendering any templates you will first need to call the initialize function to pass the Handlebars reference to extend with the helpers and set the default locale. Calling initialize will return an promise when this is resolved the locale file loaded and you can savely render your templates. +*optional +Optionally you can pass a thirth parameter to the function which is the localeLocation. +This defaults to "/i18n" if you want to put your locale files in a different folder pass this parameter + +```shell +localeManager = require( "madlib-locale" ) +localeManager.initialize( Handlebars, "en_GB" ).then( + () -> + ## Ready to render templates using the helper functions +, () -> + console.error( "something went wrong...." ) +).done() + +``` + +## Change the language + +You can change the current language at any time by calling the setLocale function on the localeManager. +The function will return an promise, once this is resolved and you re-render you templates they will be +in the new language + ```shell localeManager = require( "madlib-locale" ) localeManager.setLocale( Handlebars, "en_GB" ).then( @@ -25,3 +51,37 @@ localeManager.setLocale( Handlebars, "en_GB" ).then( ).done() ``` + +## Get the current lanauage name + +To retrieve the current language name: + +```shell +localeManager = require( "madlib-locale" ) +localeName = localeManager.getLocaleName() +``` + +## How to setup the locale file + +See the exampleLocale file in the repo as an example + +## How to use all of this in your Handlebar templates +Translate - pass the key of the phrase in the localeFile +```shell +{{_translate "i18n-date"}} +``` + +Date - pass the type of formatting as defined in localeFile and the date, this can be any format as long as MomentJS can parse it. +```shell +{{_date "date" date }} +``` + +Number - pass the number to format +```shell +{{_number number }} +``` + +Money - Pass the type as defined in localeFile and the money/amount value +```shell +{{_money "euro" money}} +``` From f3aeb34f8e8e8971f739d4e476acc492e471fba7 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 23 Jun 2014 23:27:45 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5635079..8aacaa7 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ localeManager.setLocale( Handlebars, "en_GB" ).then( ``` -## Get the current lanauage name +## Get the current language name To retrieve the current language name: