New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

i18njs

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18njs - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

bin/copyGH.js

0

bin/templateI18njs.js

@@ -0,0 +0,0 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.templateI18N = f()}})(function(){var define,module,exports;

2

bower.json
{
"name": "i18njs",
"main": "i18njs.js",
"version": "2.1.0",
"version": "2.1.1",
"homepage": "https://github.com/yoannmoinet/i18njs",

@@ -6,0 +6,0 @@ "authors": [

@@ -1,3 +0,3 @@

<a name="2.1.0"></a>
# 2.1.0 (2015-08-09)
<a name="2.1.1"></a>
## 2.1.1 (2015-09-25)

@@ -7,2 +7,8 @@

<a name="2.1.1"></a>
## 2.1.1 (2015-09-25)
<a name="2.1.0"></a>

@@ -107,6 +113,6 @@ # 2.1.0 (2015-08-09)

* add Travis CI ([988fc16](https://github.com/yoannmoinet/i18njs/commit/988fc16))
* add changelog ([45a3ccd](https://github.com/yoannmoinet/i18njs/commit/45a3ccd))
* add defaults template values ([3601034](https://github.com/yoannmoinet/i18njs/commit/3601034))
* add linting ([b9de51a](https://github.com/yoannmoinet/i18njs/commit/b9de51a))
* add Travis CI ([988fc16](https://github.com/yoannmoinet/i18njs/commit/988fc16))
* **npm:** add scripts ([4b6b378](https://github.com/yoannmoinet/i18njs/commit/4b6b378))

@@ -113,0 +119,0 @@

@@ -0,0 +0,0 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.i18njs = f()}})(function(){var define,module,exports;

{
"name": "i18njs",
"version": "2.1.0",
"description": "A simple i18n for Javascript with a templating feature.",
"version": "2.1.1",
"description": "Simplistic I18N tool for universal/isomorphic Javascript.",
"main": "dist/i18njs.js",
"scripts": {
"preversion": "npm run-script build",
"postversion": "npm run-script bowerSync && npm run-script changelog",
"preversion": "npm run build",
"postversion": "npm run bowerSync && npm run changelog",
"build": "npm test",
"pretest": "npm run-script addTemp && npm run-script concat && npm run-script concatTemplate && npm run-script umd && npm run-script umdTemplate && npm run-script uglify",
"pretest": "npm run addTemp && npm run concat && npm run concatTemplate && npm run umd && npm run umdTemplate && npm run uglify",
"test": "mocha",
"posttest": "npm run-script format && npm run-script lint && npm run-script cleanTemp",
"posttest": "npm run format && npm run lint && npm run cleanTemp",
"format": "jscs ./src/i18n.js ./test/i18njs.spec.js",

@@ -31,2 +31,5 @@ "lint": "eslint ./src/i18n.js ./test/i18njs.spec.js",

"i18n",
"internationalization",
"universal",
"isomorphic",
"translation",

@@ -33,0 +36,0 @@ "template"

@@ -1,4 +0,5 @@

# i18njs
![logo](./dist/logo.png)
-----
> A simple i18n for Javascript with a templating feature.
> Simplistic I18N tool for universal/isomorphic Javascript.

@@ -9,7 +10,8 @@ [![npm version](https://img.shields.io/npm/v/i18njs.svg?style=flat)](http://badge.fury.io/js/i18njs)

- - -
----
## Usage with RequireJS
To use with **[RequireJS](http://requirejs.org)** I'd advise to also use the plugin
To use with **[RequireJS](http://requirejs.org)** I'd advise to also use the plugin
[requirejs-i18njs](https://github.com/yoannmoinet/requirejs-i18njs) to be able to precompile the templates

@@ -20,2 +22,23 @@ that are in your translation files for your production code.

## Usage with Handlebars
You can register your helper simply by using the `.get()` function of i18njs
```javascript
Handlebars.registerHelper('i18n',
function () {
return i18njs.get.apply(i18njs, arguments);
}
);
```
then in your templates :
```javascript
// Arguments after the 'key' are optionals
{{i18n 'key' data options lang}}
```
----
## Installation

@@ -36,15 +59,32 @@

## Test
## Usage
```node
npm test
Import it the way you want into your project :
```javascript
// CommonJS
var i18njs = require('i18njs');
```
----
## Usage
```javascript
// AMD
define(['i18njs'], function (i18njs) {
// use i18njs
});
```
After importing it `var i18n = require('i18njs');`
```html
// Global
<script type="text/javascript" src="./dist/i18njs.min.js"></script>
<script type="text/javascript">
// use i18njs
</script>
```
### Add locales
Your localized strings are simple json objects.
Namespaces can be as deep as you need.
```javascript

@@ -67,4 +107,4 @@

// i18n.add(language, [namespace,] locales);
i18n.add('en', 'first_test', en_locales);
i18n.add('fr', 'first_test', fr_locales);
i18n.add('en', 'first_level_namespace', en_locales);
i18n.add('fr', 'first_level_namespace', fr_locales);

@@ -106,6 +146,6 @@ ```

// i18n.has([key,] lang)
i18n.has('first_test.hello_world.hello', 'en');
i18n.has('first_level_namespace.hello_world.hello', 'en');
// true
i18n.has('first_test.hello_world.hello');
i18n.has('first_level_namespace.hello_world.hello');
// true

@@ -115,2 +155,11 @@

// true
i18n.has('de');
// false
i18n.has('hello_world.bye', 'en');
// false
i18n.has('test');
// false
```

@@ -132,6 +181,6 @@

// i18n.get(key[, data, options][, lang]);
i18n.get('first_test.hello_world.hello');
i18n.get('first_level_namespace.hello_world.hello');
// Hello
i18n.get('first_test.hello_world.hello', 'fr');
i18n.get('first_level_namespace.hello_world.hello', 'fr');
// Bonjour

@@ -148,7 +197,8 @@

```javascript
// localized strings
var en_locales = {
'st': '{{=interpolate}} {{for(var i = 0, max = 1; i < max; i += 1) {}}to{{}}} {{-escape}}'
'st': '{{=interpolate}}{{for(var i = 0, max = 5; i < max; i += 1) {}} to{{}}} {{-escape}}'
};
// context used in the templated string
var data = {

@@ -159,6 +209,8 @@ 'interpolate': 'Hello',

// register the localized string
i18n.add('en', en_locales);
// give it a context with the data object
var st = i18n.get('st', data);
// "Hello to &#x27;&lt;the&gt;&#x27; &#x60;&amp;&#x60; &quot;World&quot;"
// "Hello to to to to to &#x27;&lt;the&gt;&#x27; &#x60;&amp;&#x60; &quot;World&quot;"

@@ -181,9 +233,12 @@ ```

Will result in `<%=interpolate%>`, `<%evaluate%>` or `<%-escape%>`
Will result in these delimiters `<%=interpolate%>`, `<%evaluate%>` or `<%-escape%>`
### Add default values for templates
If you need to have a special key always replaced by the same value (brand for example),
you can set it as default.
If you need to have a special key always replaced by the same value (a brand for example),
you can set it as a **default**.
This `key` will be then replaced across your application's localized strings and you
won't need to pass it as a context object to your `.get()`.
```javascript

@@ -215,3 +270,3 @@ var fr = {

If not needed, you don't have to use localized defaults :
You don't have to use localized defaults if you don't need to :

@@ -218,0 +273,0 @@ ```javascript

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc