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

gengojs

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gengojs - npm Package Compare versions

Comparing version 0.2.25 to 0.2.26

8

CHANGELOG.md

@@ -167,2 +167,8 @@ #Change Log

};
```
```
**omega 0.2.26**
* Updated readme
* Fixed a bug in locale engine where cookie could set something that shouldn't be set.
* Fixed a bug in phrase parser where try catch wouldn't let parser return the original phrase if route results didn't exists

4

gengo.js

@@ -5,3 +5,3 @@ /*jslint node: true, forin: true, jslint white: true, newcap: true*/

* gengojs
* version : 0.2.25
* version : 0.2.26
* author : Takeshi Iwana

@@ -89,3 +89,3 @@ * https://github.com/iwatakeshi

//version
VERSION = '0.2.25',
VERSION = '0.2.26',
//configuration with defaults set

@@ -92,0 +92,0 @@ CONFIG = {

@@ -11,3 +11,2 @@ /*jslint node: true, forin: true, jslint white: true, newcap: true*/

*/
(function() {

@@ -31,30 +30,50 @@ 'use strict';

var result, routeResult, universeResult;
try {
//check if we have to override
if (isOverride(locale)) {
//the load a new instance of loader with the json loaded
//to the overrided locale
result = new loader(locale.locale).json();
} else {
result = loader(locale).json();
}
if (config().router()) {
if (router().route().length() === 0) {
//check if we have to override
if (isOverride(locale)) {
//the load a new instance of loader with the json loaded
//to the overrided locale
result = new loader(locale.locale).json();
} else {
result = loader(locale).json();
}
var _result;
if (config().router()) {
if (router().route().length() === 0) {
_result = result[router().route().dot()][phrase];
if (_result) {
routeResult = resultParser(result[router().route().dot()][phrase], locale, plural);
} else if (result[config().keywords().universe][phrase]) {
universeResult = resultParser(result[config().keywords().universe][phrase], locale, plural);
} else {
return phrase;
}
} else {
//check if the definition contains the route
_result = dotParser(router().route().dot(), result);
//if it does
if (_result) {
// do something
routeResult = resultParser(dotParser(router().route().dot(), result)[phrase], locale, plural);
universeResult = resultParser(result[config().keywords().universe][phrase], locale, plural);
//else lets try universe
} else {
_result = dotParser(router().route().dot(), result);
//if universe exists
if (_result) {
universeResult = resultParser(result[config().keywords().universe][phrase], locale, plural);
} else {
return phrase;
}
}
//if result still has trouble
if (!routeResult) {
//try universe
}
//if result still has trouble
if (!routeResult) {
//try universe
if (universeResult) {
routeResult = universeResult;
}
return routeResult || phrase;
} else {
return resultParser(result[phrase], locale, plural) || phrase;
}
} catch (error) {
debug("module: parse fn: parse, " + error.toString().replace("Error: ", " ")).error();
return routeResult || phrase;
} else {
return resultParser(result[phrase], locale, plural) || phrase;
}

@@ -61,0 +80,0 @@ };

@@ -5,3 +5,3 @@ /*jslint node: true, forin: true, jslint white: true, newcap: true*/

* gengojs
* version : 0.2.25
* version : 0.2.26
* author : Takeshi Iwana

@@ -21,3 +21,3 @@ * https://github.com/iwatakeshi

lib,
VERSION = 'omega 0.2.25',
VERSION = 'omega 0.2.26',
//gengo modules

@@ -207,5 +207,5 @@ config = require('./modules/config.js'),

apiname = [
config().global().gengo().toString(),
config().global().numeral().toString(),
config().global().moment().toString()
config().global().gengo(),
config().global().numeral(),
config().global().moment()
],

@@ -256,3 +256,3 @@ count = 0;

return {
locale: localemap.gengo[override].toString(),
locale: localemap.gengo[override],
override: true

@@ -262,3 +262,3 @@ };

//then just return the bestmatch
return locale().bestmatch().toString();
return locale().bestmatch();
}

@@ -269,3 +269,3 @@ //if override is an object

return {
locale: localemap.gengo[override.locale].toString(),
locale: localemap.gengo[override.locale],
override: true

@@ -275,3 +275,3 @@ };

//then just return the bestmatch
return locale().bestmatch().toString();
return locale().bestmatch();
}

@@ -281,3 +281,3 @@ }

//then just return the bestmatch
return locale().bestmatch().toString();
return locale().bestmatch();
}

@@ -546,3 +546,3 @@ }

//debug(bestmatch).warn();
if (typeof req === 'object') {
if (_.isObject(req)) {
var langheader = req.headers['accept-language'],

@@ -558,3 +558,2 @@ languages = [],

requested = acceptedlang(langheader);
for (var i = 0, len = requested.length; i < len; i++) {

@@ -581,3 +580,3 @@ var lang = requested[i],

if (req.cookies && req.cookies[config().cookie()]) {
req.language = req.cookies[config().cookie()] || localemap.gengo[req.cookies[config().cookie()]];
req.language = localemap.gengo[req.cookies[config().cookie()]];
}

@@ -587,3 +586,2 @@

}
/**

@@ -590,0 +588,0 @@ * Credits to @Mashpie https://github.com/mashpie

{
"name": "gengojs",
"version": "0.2.25",
"version": "0.2.26",
"description": "An uber basic and simple i18n library for Express 4",

@@ -5,0 +5,0 @@ "main": "gengo.js",

@@ -6,10 +6,8 @@ Gengo.js

###gengo.js is getting better than ever!
An alpha version is under development. The file is called `omega.gengo.js` so it will not affect your current gengo.
An omega version is under development. The file is called `omega.gengo.js` so it will not affect your current gengo.
See Change Log.
####Change Log at a Glance
Note on version:
How gengo version works is simply:
How gengo versioning works is simply:
* Major (When gengo becomes stable after rigid testings and user feedback)

@@ -64,106 +62,4 @@ * Minor (Additions and stability improvements)

###What is Gengo.js?
gengo is a library that allows you to translate your pages automatically (hot swapping) without having to do tedious stuff (such as creating more routes for each language)...well that is my goal. gengo only requires you to provide the translation files and then your done :).
Also, before moving on, Moment.js and Numeral.js are part of gengo. What does that mean? Well it simply means you get the best of the best in a small package. Technically it means that moment and numeral will change along with gengo (see [Translating](https://github.com/iwatakeshi/gengojs/wiki/Translating) for more details).
###Install
gengo is available on npm. To begin:
```bash
sudo npm install gengojs
#or
sudo npm install gengojs --save
```
###Configure
then in your app.js
```js
//require
var gengo = require('gengojs');
//configure gengo (optional)
gengo.config({
debug: false
localePath: 'Your locale folder'
default: 'en_US'
supported: ['ja','en_US']
});
//init before your routes. if using express generator it would be right after the last app.use
gengo.init(app);
```
for more configurations options see [Gengo](https://github.com/iwatakeshi/gengojs/wiki/Gengo).
###Dictionaries
From there you have two options, you can have gengo to:
* load the words/sentences from the translation file directly
* load the words/sentences from the translation file by route (not fully tested)
an example will look like this in your locale folder:
JSON:
```js
//ja.js
//really simple, gengojs will just get what you have
module.exports = {
"Welcome to express": "エクスプレスへようこそ",
};
//with viewAware: true and universe: true
module.exports = {
index:{
"Welcome to express": "エクスプレスへようこそ",
}
//gengo now supports 'universe'. Meaning that the definition will load at every route if routeAware is enabled.
gengo:{
"Welcome to express": "エクスプレスへようこそ"
}
}
```
XML:
```xml
<!--again, really simple-->
<?xml version="1.0" encoding="UTF-8" ?>
<begin>
<data>
<key>今日から働きます。</key>
<value>From today, I will work</value>
</data>
</begin>
<!--with viewAware: true and universe: true-->
<?xml version="1.0" encoding="UTF-8" ?>
<begin>
<index>
<data>
<key>今日から働きます。</key>
<value>From today, I will work</value>
</data>
</index>
<gengo>
<data>
<key>こんにちは</key>
<value>Hello</value>
</data>
</gengo>
</begin>
```
Now in your template file (Note: I've only used Jade, others should work)
```jade
extends layout
block content
h1= title
//pretty much the same as i18n '__' (can be changed through config. see Gengo)
//this will output エクスプレスへようこそ or Welcome to express
p Welcome to #{__("Welcome to express")}
```
For more templating and translation file examples see [Translating](https://github.com/iwatakeshi/gengojs/wiki/Translating)
##Acknowledgements

@@ -187,2 +83,3 @@ gengo was made possible by:

*An alien invasion happened between 0.2.17 and alpha 0.2.20. oh well, we'll proceed from alpha 0.2.20*

@@ -262,2 +159,7 @@ ####Alpha

};
```
```
**omega 0.2.26**
* Updated readme
* Fixed a bug in locale engine where cookie could set something that shouldn't be set.
* Fixed a bug in phrase parser where try catch wouldn't let parser return the original phrase if route results didn't exists
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