Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match.replace will fail if match is not a string #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# i18n-nodejs
# i18n-nodejs-v2

i18n module for node, out of frustration with over complicated modules for translation & localization, I created this module with simplicity in mind.

## Install

```shell
npm install i18n-nodejs --save
npm install i18n-nodejs-v2 --save
```

## Usage
Expand All @@ -15,21 +15,21 @@ npm install i18n-nodejs --save
```js
var config = {
"lang": "ar",
"langFile": "./../../locale.json"//relative path to index.js file of i18n-nodejs module
"langFile": "./../../locale.json"//relative path to index.js file of i18n-nodejs-v2 module
}
//init internationalization / localization class
var i18n = require('i18n-nodejs')(config.lang, config.langFile);
var i18n = require('i18n-nodejs-v2')(config.lang, config.langFile);
console.log(i18n.__('Welcome')); // output => 'اهلا'
```
### New

```js
var config = {
"lang": "ar",
"langFile": "./../../locale.json"//relative path to index.js file of i18n-nodejs module
"langFile": "./../../locale.json"//relative path to index.js file of i18n-nodejs-v2 module
}
//init internationalization / localization class
var i18n_module = require('i18n-nodejs');
var i18n_module = require('i18n-nodejs-v2');
var i18n = new i18n_module(config.lang, config.langFile);
console.log(i18n.__('Welcome')); // output => 'اهلا'
```
Expand Down Expand Up @@ -77,10 +77,10 @@ If the text has `variable` that need to be translated you should add the the tex
//index.js file
var config = {
"lang": "ar",
"langFile": "./../../locale.json"//relative path to index.js file of i18n-nodejs module
"langFile": "./../../locale.json"//relative path to index.js file of i18n-nodejs-v2 module
}
//init internationalization / localization class
var i18n_module = require('i18n-nodejs');
var i18n_module = require('i18n-nodejs-v2');
var i18n = new i18n_module(config.lang, config.langFile);
console.log(i18n.__("Welcome {{name}}", {name: "اسلام"}));
// output => 'مرحبا اسلام'
Expand All @@ -97,10 +97,10 @@ Changed how the module was constructed now uses class format, so you must user `
```js
var config = {
"lang": "ar",
"langFile": "./../../locale.json"//relative path to index.js file of i18n-nodejs module
"langFile": "./../../locale.json"//relative path to index.js file of i18n-nodejs-v2 module
}
//init internationalization / localization class
var i18n_module = require('i18n-nodejs');
var i18n_module = require('i18n-nodejs-v2');
var i18n = new i18n_module(config.lang, config.langFile);
console.log(i18n.__('Welcome')); // output => 'اهلا'
```
Expand Down Expand Up @@ -158,5 +158,3 @@ There is a note also as you can see we did not submit the `points` variable in t

## Links
- [pluralization rules guide](http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html)
- [Bug Report](https://github.com/eslam-mahmoud/i18n-nodejs/issues)
- [Author: Eslam Mahmoud](https://eslam.me)
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,17 @@ class I18n {
if (typeof this._locale[string] != "undefined" && typeof this._locale[string][this._lang] != "undefined") {
translation = this._locale[string][this._lang];
}

if (typeof(translation) === "object") translation = translation.join('\n')
//If the string have place to render values withen
if ((/{{.+?}}/g).test(translation)) {

//get all the parts needed to be replaced
var matches = translation.match(/{{.+?}}/g);
//loop on each match
for (var index in matches) {
//get the match {{example}}
var match = matches[index];
if(typeof(match) !== "string") continue
//get the word in the match example
var match_word = (match.replace('}}', '')).replace('{{', '');

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "i18n-nodejs",
"version": "2.0.0",
"name": "i18n-nodejs-v2",
"version": "2.0.3",
"description": "Internationalization localization package",
"main": "index.js",
"scripts": {
Expand All @@ -14,13 +14,13 @@
"i18n-nodejs",
"plural"
],
"author": "Eslam Mahmoud <[email protected]> (http://eslam.me)",
"author": "Alberto Monterroso",
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/eslam-mahmoud/i18n-nodejs.git"
"url": "git://github.com/Albermonte/i18n-nodejs.git"
},
"bugs": {
"url": "https://github.com/eslam-mahmoud/i18n-nodejs/issues"
"url": "https://github.com/Albermonte/i18n-nodejs/issues"
}
}