Skip to content

Commit

Permalink
Some fixes for error reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
chleck committed Dec 4, 2012
1 parent 18faa22 commit 6968f49
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
32 changes: 18 additions & 14 deletions bin/i18n
Expand Up @@ -68,7 +68,7 @@ function init() {
cfg.rule = scheme[base][2] || '(n == 1 ? 0 : 1)';
targets();
} else {
console.log('No language rules for "' + base + '".');
console.log('No language rules for "%s".', base);
program.prompt('Number of plural forms for "' + base + '": ', Number, function(n) {
cfg.n = n;
program.prompt('Plural rule for "' + base + '": ', function(rule) {
Expand Down Expand Up @@ -100,7 +100,7 @@ function init() {
cfg.targets[target].rule = scheme[target][2] || '(n == 1 ? 0 : 1)';
nextTarget();
} else {
console.log('No language rules for "' + target + '".');
console.log('No language rules for "%s".', target);
program.prompt('Number of plural forms for "' + target + '": ', Number, function(n) {
cfg.targets[target].n = n;
program.prompt('Plural rule for "' + target + '": ', function(rule) {
Expand All @@ -120,15 +120,15 @@ function init() {
try {
if(createDir) fs.mkdirSync(dir);
} catch(e) {
console.log('Can not create directory "%s":\n%s', dir, e);
console.log('ERROR: Can not create directory "%s".\n\t%s', dir, e);
process.exit(1);
}
//
try {
var cfgFile = path.join(dir, 'tr.json');
fs.writeFileSync(cfgFile, JSON.stringify(cfg, null, ' '), 'utf8');
} catch(e) {
console.log('Can not save project config "%s":\n%s', cfgFile, e);
console.log('ERROR: Can not save project config "%s".\n\t%s', cfgFile, e);
process.exit(1);
}
process.exit();
Expand Down Expand Up @@ -163,7 +163,7 @@ function collect() {
var dictFile = path.join(home, 'i18n', target + '.json');
var old = JSON.parse(fs.readFileSync(dictFile, 'utf8'));
} catch(e) {
console.log('WARNING: Can not load the old translation file "%s":\n%s', dictFile, e);
console.log('WARNING: Can not load the old translation file "%s".\n\t%s', dictFile, e);
var old = {};
}
// Add records
Expand Down Expand Up @@ -198,7 +198,7 @@ function collect() {
try {
fs.writeFileSync(trFile, res.join('\n'), 'utf8');
} catch(e) {
console.log('Can not save translation file "%s":\n%s', trFile, e);
console.log('ERROR: Can not save translation file "%s".\n\t%s', trFile, e);
process.exit(1);
}
}
Expand All @@ -209,7 +209,7 @@ function collect() {
try {
var files = fs.readdirSync(dir);
} catch(e) {
console.log('WARNING: Can not read directory "%s", skipped:\n%s', dir, e);
console.log('WARNING: Can not read directory "%s", skipped.\n\t%s', dir, e);
return;
}

Expand All @@ -218,7 +218,7 @@ function collect() {
try {
var s = fs.statSync(file);
} catch(e) {
console.log('WARNING: Can not get file properties "%s", skipped:\n%s', file, e);
console.log('WARNING: Can not get file properties "%s", skipped.\n\t%s', file, e);
continue;
}
// Dive into subdir
Expand All @@ -245,7 +245,7 @@ function collect() {
try {
var f = fs.readFileSync(file, 'utf8');
} catch(e) {
console.log('WARNING: Can not read file "%s", skipped:\n%s', file, e);
console.log('WARNING: Can not read file "%s", skipped.\n\t%s', file, e);
return;
}

Expand Down Expand Up @@ -357,6 +357,10 @@ function collect() {
var key;
var base = [];
for(var i in args) {
if(typeof args[i] != 'string') {
console.log('ERROR: One of the arguments of __() function at %s is not a string.', where);
process.exit(1);
}
var tmp = splitPhrase(args[i]);
// Create key based on the first arg
if(!key) {
Expand Down Expand Up @@ -431,7 +435,7 @@ function dict() {
var i18nFile = path.join(home, 'i18n', 'i18n.json');
fs.writeFileSync(i18nFile, JSON.stringify(i18n, null, ' '), 'utf8');
} catch(e) {
console.log('ERROR: Can not save dictionary config "%s":\n%s', i18nFile, e);
console.log('ERROR: Can not save dictionary config "%s".\n\t%s', i18nFile, e);
process.exit(1);
}

Expand All @@ -451,7 +455,7 @@ function dict() {
var trFile = path.join(home, 'i18n', target + '.tr');
var s = fs.readFileSync(trFile, 'utf8');
} catch(e) {
console.log('ERROR: Can not load translation file "%s":\n%s', trFile, e);
console.log('ERROR: Can not load translation file "%s".\n\t%s', trFile, e);
process.exit(1);
}
// Split .tr to lines
Expand Down Expand Up @@ -508,7 +512,7 @@ function dict() {
tr = [];
break;
default:
err('Bad line');
err('Unknown line prefix');
process.exit(1);
}
});
Expand All @@ -517,7 +521,7 @@ function dict() {
var jsonFile = path.join(home, 'i18n', target + '.json')
fs.writeFileSync(jsonFile, JSON.stringify(res, null, ' '), 'utf8');
} catch(e) {
console.log('ERROR: Can not save dictionary file "%s":\n%s', jsonFile, e);
console.log('ERROR: Can not save dictionary file "%s".\n\t%s', jsonFile, e);
}

function err(msg) {
Expand All @@ -541,7 +545,7 @@ function loadConfig() {
try {
cfg = JSON.parse(fs.readFileSync(cfgFile, 'utf8'));
} catch(e) {
console.log('Can not load config file "%s":\n%s', cfgFile, e);
console.log('Can not load config file "%s".\n\t%s', cfgFile, e);
process.exit(1);
}
}
Expand Down
1 change: 0 additions & 1 deletion test/i18n/ru.json
@@ -1,5 +1,4 @@
{
"1": "1",
"": "(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)",
"Hello!": "Привет!",
"Hello!#testid": "Здаров!",
Expand Down
2 changes: 0 additions & 2 deletions test/test.js
Expand Up @@ -9,8 +9,6 @@ locale.to('ru');

w(__());

w(__('1'));

var some_space = 123;

w(__("Hello!# This is comment"));
Expand Down

0 comments on commit 6968f49

Please sign in to comment.